Make WordPress Core


Ignore:
Timestamp:
01/26/2017 02:11:19 PM (9 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 4.0 branch.

File:
1 edited

Legend:

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

    r30439 r39978  
    3333        wp_die(__('You are not allowed to edit this post.'));
    3434
    35     $post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : '';
    36     $post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
     35    // Only accept categories if the user actually can assign
     36    $category_tax = get_taxonomy( 'category' );
     37    if ( current_user_can( $category_tax->cap->assign_terms ) ) {
     38        $post['post_category'] = ( ! empty( $_POST['post_category'] ) ) ? $_POST['post_category'] : array();
     39    }
     40
     41    // Only accept taxonomies if the user can actually assign
     42    if ( ! empty( $_POST['tax_input'] ) ) {
     43        $tax_input = $_POST['tax_input'];
     44        foreach ( $tax_input as $tax => $_ti ) {
     45            $tax_object = get_taxonomy( $tax );
     46            if ( ! $tax_object || ! current_user_can( $tax_object->cap->assign_terms ) ) {
     47                unset( $tax_input[ $tax ] );
     48            }
     49        }
     50
     51        $post['tax_input'] = $tax_input;
     52    }
     53
    3754    $post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
    3855    $content = isset($_POST['content']) ? $_POST['content'] : '';
     
    524541            </div>
    525542
    526             <?php $tax = get_taxonomy( 'category' ); ?>
    527             <div id="categorydiv" class="postbox">
    528                 <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    529                 <h3 class="hndle"><?php _e('Categories') ?></h3>
    530                 <div class="inside">
    531                 <div id="taxonomy-category" class="categorydiv">
    532 
    533                     <ul id="category-tabs" class="category-tabs">
    534                         <li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li>
    535                         <li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li>
    536                     </ul>
    537 
    538                     <div id="category-pop" class="tabs-panel" style="display: none;">
    539                         <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
    540                             <?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?>
     543            <?php
     544
     545            $tax = get_taxonomy( 'category' );
     546            if ( current_user_can( $tax->cap->assign_terms ) ) :
     547                ?>
     548                <div id="categorydiv" class="postbox">
     549                    <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
     550                    <h3 class="hndle"><?php _e('Categories') ?></h3>
     551                    <div class="inside">
     552                    <div id="taxonomy-category" class="categorydiv">
     553
     554                        <ul id="category-tabs" class="category-tabs">
     555                            <li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li>
     556                            <li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li>
    541557                        </ul>
     558
     559                        <div id="category-pop" class="tabs-panel" style="display: none;">
     560                            <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
     561                                <?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?>
     562                            </ul>
     563                        </div>
     564
     565                        <div id="category-all" class="tabs-panel">
     566                            <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
     567                                <?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?>
     568                            </ul>
     569                        </div>
     570
     571                        <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
     572                            <div id="category-adder" class="wp-hidden-children">
     573                                <h4>
     574                                    <a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
     575                                        <?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
     576                                    </a>
     577                                </h4>
     578                                <p id="category-add" class="category-add wp-hidden-child">
     579                                    <label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
     580                                    <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"/>
     581                                    <label class="screen-reader-text" for="newcategory_parent">
     582                                        <?php echo $tax->labels->parent_item_colon; ?>
     583                                    </label>
     584                                    <?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;' ) ); ?>
     585                                    <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 ); ?>" />
     586                                    <?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
     587                                    <span id="category-ajax-response"></span>
     588                                </p>
     589                            </div>
     590                        <?php endif; ?>
    542591                    </div>
    543 
    544                     <div id="category-all" class="tabs-panel">
    545                         <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
    546                             <?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?>
    547                         </ul>
    548592                    </div>
    549 
    550                     <?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
    551                     <p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
    552                     <?php endif; ?>
    553                     <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
    554                         <div id="category-adder" class="wp-hidden-children">
    555                             <h4>
    556                                 <a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
    557                                     <?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
    558                                 </a>
    559                             </h4>
    560                             <p id="category-add" class="category-add wp-hidden-child">
    561                                 <label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
    562                                 <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"/>
    563                                 <label class="screen-reader-text" for="newcategory_parent">
    564                                     <?php echo $tax->labels->parent_item_colon; ?>
    565                                 </label>
    566                                 <?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;' ) ); ?>
    567                                 <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 ); ?>" />
    568                                 <?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
    569                                 <span id="category-ajax-response"></span>
    570                             </p>
     593                </div>
     594            <?php endif;
     595
     596            $tax = get_taxonomy( 'post_tag' );
     597            if ( current_user_can( $tax->cap->assign_terms ) ) :
     598                ?>
     599                <div id="tagsdiv-post_tag" class="postbox">
     600                    <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
     601                    <h3><span><?php _e('Tags'); ?></span></h3>
     602                    <div class="inside">
     603                        <div class="tagsdiv" id="post_tag">
     604                            <div class="jaxtag">
     605                                <label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
     606                                <input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
     607                                <div class="ajaxtag">
     608                                    <input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
     609                                    <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
     610                                </div>
     611                            </div>
     612                            <div class="tagchecklist"></div>
    571613                        </div>
    572                     <?php endif; ?>
     614                        <p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
     615                    </div>
    573616                </div>
    574                 </div>
    575             </div>
    576 
    577             <div id="tagsdiv-post_tag" class="postbox">
    578                 <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    579                 <h3><span><?php _e('Tags'); ?></span></h3>
    580                 <div class="inside">
    581                     <div class="tagsdiv" id="post_tag">
    582                         <div class="jaxtag">
    583                             <label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
    584                             <input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
    585                             <div class="ajaxtag">
    586                                 <input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
    587                                 <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
    588                             </div>
    589                         </div>
    590                         <div class="tagchecklist"></div>
    591                     </div>
    592                     <p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
    593                 </div>
    594             </div>
     617            <?php endif; ?>
    595618        </div>
    596619    </div>
Note: See TracChangeset for help on using the changeset viewer.