Make WordPress Core

Changeset 39971


Ignore:
Timestamp:
01/26/2017 02:09:05 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 4.6 branch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6/src/wp-admin/includes/class-wp-press-this.php

    r38028 r39971  
    120120            'post_status'   => 'draft',
    121121            'post_format'   => ( ! empty( $_POST['post_format'] ) ) ? sanitize_text_field( $_POST['post_format'] ) : '',
    122             'tax_input'     => ( ! empty( $_POST['tax_input'] ) ) ? $_POST['tax_input'] : array(),
    123             'post_category' => ( ! empty( $_POST['post_category'] ) ) ? $_POST['post_category'] : array(),
    124122        );
    125123
     124        // Only accept categories if the user actually can assign
     125        $category_tax = get_taxonomy( 'category' );
     126        if ( current_user_can( $category_tax->cap->assign_terms ) ) {
     127            $post_data['post_category'] = ( ! empty( $_POST['post_category'] ) ) ? $_POST['post_category'] : array();
     128        }
     129
     130        // Only accept taxonomies if the user can actually assign
     131        if ( ! empty( $_POST['tax_input'] ) ) {
     132            $tax_input = $_POST['tax_input'];
     133            foreach ( $tax_input as $tax => $_ti ) {
     134                $tax_object = get_taxonomy( $tax );
     135                if ( ! $tax_object || ! current_user_can( $tax_object->cap->assign_terms ) ) {
     136                    unset( $tax_input[ $tax ] );
     137                }
     138            }
     139
     140            $post_data['tax_input'] = $tax_input;
     141        }
     142
     143        // Toggle status to pending if user cannot actually publish
    126144        if ( ! empty( $_POST['post_status'] ) && 'publish' === $_POST['post_status'] ) {
    127145            if ( current_user_can( 'publish_posts' ) ) {
     
    456474     *
    457475     * @param string $src Embed source URL.
    458      * @return string If not from a supported provider, an empty string. Otherwise, a reformattd embed URL.
     476     * @return string If not from a supported provider, an empty string. Otherwise, a reformatted embed URL.
    459477     */
    460478    private function _limit_embed( $src ) {
     
    857875        $taxonomy = get_taxonomy( 'category' );
    858876
     877        // Bail if user cannot assign terms
     878        if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) {
     879            return;
     880        }
     881
     882        // Only show "add" if user can edit terms
    859883        if ( current_user_can( $taxonomy->cap->edit_terms ) ) {
    860884            ?>
     
    12751299        wp_enqueue_script( 'editor' );
    12761300
     1301        $categories_tax   = get_taxonomy( 'category' );
     1302        $show_categories  = current_user_can( $categories_tax->cap->assign_terms ) || current_user_can( $categories_tax->cap->edit_terms );
     1303
     1304        $tag_tax          = get_taxonomy( 'post_tag' );
     1305        $show_tags        = current_user_can( $tag_tax->cap->assign_terms );
     1306
    12771307        $supports_formats = false;
    12781308        $post_format      = 0;
     
    14261456                <?php endif; ?>
    14271457
    1428                 <button type="button" class="button-link post-option">
    1429                     <span class="dashicons dashicons-category"></span>
    1430                     <span class="post-option-title"><?php _e( 'Categories' ); ?></span>
    1431                     <span class="dashicons post-option-forward"></span>
    1432                 </button>
    1433 
    1434                 <button type="button" class="button-link post-option">
    1435                     <span class="dashicons dashicons-tag"></span>
    1436                     <span class="post-option-title"><?php _e( 'Tags' ); ?></span>
    1437                     <span class="dashicons post-option-forward"></span>
    1438                 </button>
     1458                <?php if ( $show_categories ) : ?>
     1459                    <button type="button" class="button-link post-option">
     1460                        <span class="dashicons dashicons-category"></span>
     1461                        <span class="post-option-title"><?php _e( 'Categories' ); ?></span>
     1462                        <span class="dashicons post-option-forward"></span>
     1463                    </button>
     1464                <?php endif; ?>
     1465
     1466                <?php if ( $show_tags ) : ?>
     1467                    <button type="button" class="button-link post-option">
     1468                        <span class="dashicons dashicons-tag"></span>
     1469                        <span class="post-option-title"><?php _e( 'Tags' ); ?></span>
     1470                        <span class="dashicons post-option-forward"></span>
     1471                    </button>
     1472                <?php endif; ?>
    14391473            </div>
    14401474
     
    14501484            <?php endif; ?>
    14511485
    1452             <div class="setting-modal is-off-screen is-hidden">
    1453                 <button type="button" class="button-link modal-close">
    1454                     <span class="dashicons post-option-back"></span>
    1455                     <span class="setting-title" aria-hidden="true"><?php _e( 'Categories' ); ?></span>
    1456                     <span class="screen-reader-text"><?php _e( 'Back to post options' ) ?></span>
    1457                 </button>
    1458                 <?php $this->categories_html( $post ); ?>
    1459             </div>
    1460 
    1461             <div class="setting-modal tags is-off-screen is-hidden">
    1462                 <button type="button" class="button-link modal-close">
    1463                     <span class="dashicons post-option-back"></span>
    1464                     <span class="setting-title" aria-hidden="true"><?php _e( 'Tags' ); ?></span>
    1465                     <span class="screen-reader-text"><?php _e( 'Back to post options' ) ?></span>
    1466                 </button>
    1467                 <?php $this->tags_html( $post ); ?>
    1468             </div>
     1486            <?php if ( $show_categories ) : ?>
     1487                <div class="setting-modal is-off-screen is-hidden">
     1488                    <button type="button" class="button-link modal-close">
     1489                        <span class="dashicons post-option-back"></span>
     1490                        <span class="setting-title" aria-hidden="true"><?php _e( 'Categories' ); ?></span>
     1491                        <span class="screen-reader-text"><?php _e( 'Back to post options' ) ?></span>
     1492                    </button>
     1493                    <?php $this->categories_html( $post ); ?>
     1494                </div>
     1495            <?php endif; ?>
     1496
     1497            <?php if ( $show_tags ) : ?>
     1498                <div class="setting-modal tags is-off-screen is-hidden">
     1499                    <button type="button" class="button-link modal-close">
     1500                        <span class="dashicons post-option-back"></span>
     1501                        <span class="setting-title" aria-hidden="true"><?php _e( 'Tags' ); ?></span>
     1502                        <span class="screen-reader-text"><?php _e( 'Back to post options' ) ?></span>
     1503                    </button>
     1504                    <?php $this->tags_html( $post ); ?>
     1505                </div>
     1506            <?php endif; ?>
    14691507        </div><!-- .options-panel -->
    14701508    </div><!-- .wrapper -->
Note: See TracChangeset for help on using the changeset viewer.