Press This: Do not show Categories & Tags UI for users who cannot assign terms to posts anyways.

Merge of [39968] to the 3.7 branch.
Built from https://develop.svn.wordpress.org/branches/3.7@39982


git-svn-id: http://core.svn.wordpress.org/branches/3.7@39919 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2017-01-26 14:16:21 +00:00
parent e62f79cfd7
commit 9669f73c62
1 changed files with 85 additions and 62 deletions

View File

@ -34,8 +34,25 @@ function press_it() {
if ( !current_user_can('edit_post', $post_ID) )
wp_die(__('You are not allowed to edit this post.'));
$post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : '';
$post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
// Only accept categories if the user actually can assign
$category_tax = get_taxonomy( 'category' );
if ( current_user_can( $category_tax->cap->assign_terms ) ) {
$post['post_category'] = ( ! empty( $_POST['post_category'] ) ) ? $_POST['post_category'] : array();
}
// Only accept taxonomies if the user can actually assign
if ( ! empty( $_POST['tax_input'] ) ) {
$tax_input = $_POST['tax_input'];
foreach ( $tax_input as $tax => $_ti ) {
$tax_object = get_taxonomy( $tax );
if ( ! $tax_object || ! current_user_can( $tax_object->cap->assign_terms ) ) {
unset( $tax_input[ $tax ] );
}
}
$post['tax_input'] = $tax_input;
}
$post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
$content = isset($_POST['content']) ? $_POST['content'] : '';
@ -490,7 +507,11 @@ $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace(
</div>
</div>
<?php $tax = get_taxonomy( 'category' ); ?>
<?php
$tax = get_taxonomy( 'category' );
if ( current_user_can( $tax->cap->assign_terms ) ) :
?>
<div id="categorydiv" class="postbox">
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
<h3 class="hndle"><?php _e('Categories') ?></h3>
@ -514,9 +535,6 @@ $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace(
</ul>
</div>
<?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
<p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
<?php endif; ?>
<?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
<div id="category-adder" class="wp-hidden-children">
<h4>
@ -540,7 +558,11 @@ $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace(
</div>
</div>
</div>
<?php endif;
$tax = get_taxonomy( 'post_tag' );
if ( current_user_can( $tax->cap->assign_terms ) ) :
?>
<div id="tagsdiv-post_tag" class="postbox">
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
<h3><span><?php _e('Tags'); ?></span></h3>
@ -559,6 +581,7 @@ $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace(
<p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<div class="posting">