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) ) if ( !current_user_can('edit_post', $post_ID) )
wp_die(__('You are not allowed to edit this post.')); wp_die(__('You are not allowed to edit this post.'));
$post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : ''; // Only accept categories if the user actually can assign
$post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : ''; $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'] : ''; $post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
$content = isset($_POST['content']) ? $_POST['content'] : ''; $content = isset($_POST['content']) ? $_POST['content'] : '';
@ -490,75 +507,81 @@ $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace(
</div> </div>
</div> </div>
<?php $tax = get_taxonomy( 'category' ); ?> <?php
<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>
<div class="inside">
<div id="taxonomy-category" class="categorydiv">
<ul id="category-tabs" class="category-tabs"> $tax = get_taxonomy( 'category' );
<li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li> if ( current_user_can( $tax->cap->assign_terms ) ) :
<li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li> ?>
</ul> <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>
<div class="inside">
<div id="taxonomy-category" class="categorydiv">
<div id="category-pop" class="tabs-panel" style="display: none;"> <ul id="category-tabs" class="category-tabs">
<ul id="categorychecklist-pop" class="categorychecklist form-no-clear" > <li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li>
<?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?> <li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li>
</ul> </ul>
</div>
<div id="category-all" class="tabs-panel"> <div id="category-pop" class="tabs-panel" style="display: none;">
<ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear"> <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
<?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?> <?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?>
</ul> </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>
<a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
<?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
</a>
</h4>
<p id="category-add" class="category-add wp-hidden-child">
<label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
<input type="text" name="newcategory" id="newcategory" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" aria-required="true"/>
<label class="screen-reader-text" for="newcategory_parent">
<?php echo $tax->labels->parent_item_colon; ?>
</label>
<?php wp_dropdown_categories( array( 'taxonomy' => 'category', 'hide_empty' => 0, 'name' => 'newcategory_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;' ) ); ?>
<input type="button" id="category-add-submit" data-wp-lists="add:categorychecklist:category-add" class="button category-add-submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" />
<?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
<span id="category-ajax-response"></span>
</p>
</div> </div>
<?php endif; ?>
</div>
</div>
</div>
<div id="tagsdiv-post_tag" class="postbox"> <div id="category-all" class="tabs-panel">
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div> <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
<h3><span><?php _e('Tags'); ?></span></h3> <?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?>
<div class="inside"> </ul>
<div class="tagsdiv" id="post_tag"> </div>
<div class="jaxtag">
<label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label> <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
<input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" /> <div id="category-adder" class="wp-hidden-children">
<div class="ajaxtag"> <h4>
<input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" /> <a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
<input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" /> <?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
</a>
</h4>
<p id="category-add" class="category-add wp-hidden-child">
<label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
<input type="text" name="newcategory" id="newcategory" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" aria-required="true"/>
<label class="screen-reader-text" for="newcategory_parent">
<?php echo $tax->labels->parent_item_colon; ?>
</label>
<?php wp_dropdown_categories( array( 'taxonomy' => 'category', 'hide_empty' => 0, 'name' => 'newcategory_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;' ) ); ?>
<input type="button" id="category-add-submit" data-wp-lists="add:categorychecklist:category-add" class="button category-add-submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" />
<?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
<span id="category-ajax-response"></span>
</p>
</div> </div>
</div> <?php endif; ?>
<div class="tagchecklist"></div> </div>
</div> </div>
<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>
</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>
<div class="inside">
<div class="tagsdiv" id="post_tag">
<div class="jaxtag">
<label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
<input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
<div class="ajaxtag">
<input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
<input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
</div>
</div>
<div class="tagchecklist"></div>
</div>
<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> </div>
<div class="posting"> <div class="posting">