Make WordPress Core


Ignore:
Timestamp:
01/26/2017 02:12:32 PM (10 years ago)
Author:
ocean90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7/src/wp-admin/press-this.php

    r30442 r39982  
    3535                wp_die(__('You are not allowed to edit this post.'));
    3636
    37         $post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : '';
    38         $post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
     37        // Only accept categories if the user actually can assign
     38        $category_tax = get_taxonomy( 'category' );
     39        if ( current_user_can( $category_tax->cap->assign_terms ) ) {
     40                $post['post_category'] = ( ! empty( $_POST['post_category'] ) ) ? $_POST['post_category'] : array();
     41        }
     42
     43        // Only accept taxonomies if the user can actually assign
     44        if ( ! empty( $_POST['tax_input'] ) ) {
     45                $tax_input = $_POST['tax_input'];
     46                foreach ( $tax_input as $tax => $_ti ) {
     47                        $tax_object = get_taxonomy( $tax );
     48                        if ( ! $tax_object || ! current_user_can( $tax_object->cap->assign_terms ) ) {
     49                                unset( $tax_input[ $tax ] );
     50                        }
     51                }
     52
     53                $post['tax_input'] = $tax_input;
     54        }
     55
    3956        $post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
    4057        $content = isset($_POST['content']) ? $_POST['content'] : '';
     
    491508                        </div>
    492509
    493                         <?php $tax = get_taxonomy( 'category' ); ?>
    494                         <div id="categorydiv" class="postbox">
    495                                 <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    496                                 <h3 class="hndle"><?php _e('Categories') ?></h3>
    497                                 <div class="inside">
    498                                 <div id="taxonomy-category" class="categorydiv">
    499 
    500                                         <ul id="category-tabs" class="category-tabs">
    501                                                 <li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li>
    502                                                 <li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li>
    503                                         </ul>
    504 
    505                                         <div id="category-pop" class="tabs-panel" style="display: none;">
    506                                                 <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
    507                                                         <?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?>
     510                        <?php
     511
     512                        $tax = get_taxonomy( 'category' );
     513                        if ( current_user_can( $tax->cap->assign_terms ) ) :
     514                                ?>
     515                                <div id="categorydiv" class="postbox">
     516                                        <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
     517                                        <h3 class="hndle"><?php _e('Categories') ?></h3>
     518                                        <div class="inside">
     519                                        <div id="taxonomy-category" class="categorydiv">
     520
     521                                                <ul id="category-tabs" class="category-tabs">
     522                                                        <li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li>
     523                                                        <li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li>
    508524                                                </ul>
     525
     526                                                <div id="category-pop" class="tabs-panel" style="display: none;">
     527                                                        <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
     528                                                                <?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?>
     529                                                        </ul>
     530                                                </div>
     531
     532                                                <div id="category-all" class="tabs-panel">
     533                                                        <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
     534                                                                <?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?>
     535                                                        </ul>
     536                                                </div>
     537
     538                                                <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
     539                                                        <div id="category-adder" class="wp-hidden-children">
     540                                                                <h4>
     541                                                                        <a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
     542                                                                                <?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
     543                                                                        </a>
     544                                                                </h4>
     545                                                                <p id="category-add" class="category-add wp-hidden-child">
     546                                                                        <label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
     547                                                                        <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"/>
     548                                                                        <label class="screen-reader-text" for="newcategory_parent">
     549                                                                                <?php echo $tax->labels->parent_item_colon; ?>
     550                                                                        </label>
     551                                                                        <?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;' ) ); ?>
     552                                                                        <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 ); ?>" />
     553                                                                        <?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
     554                                                                        <span id="category-ajax-response"></span>
     555                                                                </p>
     556                                                        </div>
     557                                                <?php endif; ?>
    509558                                        </div>
    510 
    511                                         <div id="category-all" class="tabs-panel">
    512                                                 <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
    513                                                         <?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?>
    514                                                 </ul>
    515559                                        </div>
    516 
    517                                         <?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
    518                                         <p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
    519                                         <?php endif; ?>
    520                                         <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
    521                                                 <div id="category-adder" class="wp-hidden-children">
    522                                                         <h4>
    523                                                                 <a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
    524                                                                         <?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
    525                                                                 </a>
    526                                                         </h4>
    527                                                         <p id="category-add" class="category-add wp-hidden-child">
    528                                                                 <label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
    529                                                                 <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"/>
    530                                                                 <label class="screen-reader-text" for="newcategory_parent">
    531                                                                         <?php echo $tax->labels->parent_item_colon; ?>
    532                                                                 </label>
    533                                                                 <?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;' ) ); ?>
    534                                                                 <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 ); ?>" />
    535                                                                 <?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
    536                                                                 <span id="category-ajax-response"></span>
    537                                                         </p>
     560                                </div>
     561                        <?php endif;
     562
     563                        $tax = get_taxonomy( 'post_tag' );
     564                        if ( current_user_can( $tax->cap->assign_terms ) ) :
     565                                ?>
     566                                <div id="tagsdiv-post_tag" class="postbox">
     567                                        <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
     568                                        <h3><span><?php _e('Tags'); ?></span></h3>
     569                                        <div class="inside">
     570                                                <div class="tagsdiv" id="post_tag">
     571                                                        <div class="jaxtag">
     572                                                                <label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
     573                                                                <input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
     574                                                                <div class="ajaxtag">
     575                                                                        <input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
     576                                                                        <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
     577                                                                </div>
     578                                                        </div>
     579                                                        <div class="tagchecklist"></div>
    538580                                                </div>
    539                                         <?php endif; ?>
     581                                                <p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
     582                                        </div>
    540583                                </div>
    541                                 </div>
    542                         </div>
    543 
    544                         <div id="tagsdiv-post_tag" class="postbox">
    545                                 <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    546                                 <h3><span><?php _e('Tags'); ?></span></h3>
    547                                 <div class="inside">
    548                                         <div class="tagsdiv" id="post_tag">
    549                                                 <div class="jaxtag">
    550                                                         <label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
    551                                                         <input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
    552                                                         <div class="ajaxtag">
    553                                                                 <input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
    554                                                                 <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
    555                                                         </div>
    556                                                 </div>
    557                                                 <div class="tagchecklist"></div>
    558                                         </div>
    559                                         <p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
    560                                 </div>
    561                         </div>
     584                        <?php endif; ?>
    562585                </div>
    563586        </div>
Note: See TracChangeset for help on using the changeset viewer.