Make WordPress Core

Changeset 39981


Ignore:
Timestamp:
01/26/2017 02:12:15 PM (7 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.8 branch.

File:
1 edited

Legend:

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

    r30441 r39981  
    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'] : '';
     
    510527            </div>
    511528
    512             <?php $tax = get_taxonomy( 'category' ); ?>
    513             <div id="categorydiv" class="postbox">
    514                 <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    515                 <h3 class="hndle"><?php _e('Categories') ?></h3>
    516                 <div class="inside">
    517                 <div id="taxonomy-category" class="categorydiv">
    518 
    519                     <ul id="category-tabs" class="category-tabs">
    520                         <li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li>
    521                         <li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li>
    522                     </ul>
    523 
    524                     <div id="category-pop" class="tabs-panel" style="display: none;">
    525                         <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
    526                             <?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?>
     529            <?php
     530
     531            $tax = get_taxonomy( 'category' );
     532            if ( current_user_can( $tax->cap->assign_terms ) ) :
     533                ?>
     534                <div id="categorydiv" class="postbox">
     535                    <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
     536                    <h3 class="hndle"><?php _e('Categories') ?></h3>
     537                    <div class="inside">
     538                    <div id="taxonomy-category" class="categorydiv">
     539
     540                        <ul id="category-tabs" class="category-tabs">
     541                            <li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li>
     542                            <li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li>
    527543                        </ul>
     544
     545                        <div id="category-pop" class="tabs-panel" style="display: none;">
     546                            <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
     547                                <?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?>
     548                            </ul>
     549                        </div>
     550
     551                        <div id="category-all" class="tabs-panel">
     552                            <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
     553                                <?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?>
     554                            </ul>
     555                        </div>
     556
     557                        <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
     558                            <div id="category-adder" class="wp-hidden-children">
     559                                <h4>
     560                                    <a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
     561                                        <?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
     562                                    </a>
     563                                </h4>
     564                                <p id="category-add" class="category-add wp-hidden-child">
     565                                    <label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
     566                                    <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"/>
     567                                    <label class="screen-reader-text" for="newcategory_parent">
     568                                        <?php echo $tax->labels->parent_item_colon; ?>
     569                                    </label>
     570                                    <?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;' ) ); ?>
     571                                    <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 ); ?>" />
     572                                    <?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
     573                                    <span id="category-ajax-response"></span>
     574                                </p>
     575                            </div>
     576                        <?php endif; ?>
    528577                    </div>
    529 
    530                     <div id="category-all" class="tabs-panel">
    531                         <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
    532                             <?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?>
    533                         </ul>
    534578                    </div>
    535 
    536                     <?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
    537                     <p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
    538                     <?php endif; ?>
    539                     <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
    540                         <div id="category-adder" class="wp-hidden-children">
    541                             <h4>
    542                                 <a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
    543                                     <?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
    544                                 </a>
    545                             </h4>
    546                             <p id="category-add" class="category-add wp-hidden-child">
    547                                 <label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
    548                                 <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"/>
    549                                 <label class="screen-reader-text" for="newcategory_parent">
    550                                     <?php echo $tax->labels->parent_item_colon; ?>
    551                                 </label>
    552                                 <?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;' ) ); ?>
    553                                 <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 ); ?>" />
    554                                 <?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
    555                                 <span id="category-ajax-response"></span>
    556                             </p>
     579                </div>
     580            <?php endif;
     581
     582            $tax = get_taxonomy( 'post_tag' );
     583            if ( current_user_can( $tax->cap->assign_terms ) ) :
     584                ?>
     585                <div id="tagsdiv-post_tag" class="postbox">
     586                    <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
     587                    <h3><span><?php _e('Tags'); ?></span></h3>
     588                    <div class="inside">
     589                        <div class="tagsdiv" id="post_tag">
     590                            <div class="jaxtag">
     591                                <label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
     592                                <input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
     593                                <div class="ajaxtag">
     594                                    <input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
     595                                    <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
     596                                </div>
     597                            </div>
     598                            <div class="tagchecklist"></div>
    557599                        </div>
    558                     <?php endif; ?>
     600                        <p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
     601                    </div>
    559602                </div>
    560                 </div>
    561             </div>
    562 
    563             <div id="tagsdiv-post_tag" class="postbox">
    564                 <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    565                 <h3><span><?php _e('Tags'); ?></span></h3>
    566                 <div class="inside">
    567                     <div class="tagsdiv" id="post_tag">
    568                         <div class="jaxtag">
    569                             <label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
    570                             <input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
    571                             <div class="ajaxtag">
    572                                 <input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
    573                                 <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
    574                             </div>
    575                         </div>
    576                         <div class="tagchecklist"></div>
    577                     </div>
    578                     <p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
    579                 </div>
    580             </div>
     603            <?php endif; ?>
    581604        </div>
    582605    </div>
Note: See TracChangeset for help on using the changeset viewer.