WordPress.org

Make WordPress Core

Ticket #19712: meta-boxes.2.diff

File meta-boxes.2.diff, 3.3 KB (added by niallkennedy, 6 years ago)

disabled() version. replace string assignment and echo with function call for capability test

  • wp-admin/includes/meta-boxes.php

     
    268268 * @since 2.6.0
    269269 *
    270270 * @param object $post
     271 * @param array $box associative array
    271272 */
    272273function post_tags_meta_box($post, $box) {
    273         $defaults = array('taxonomy' => 'post_tag');
    274         if ( !isset($box['args']) || !is_array($box['args']) )
     274        $defaults = array( 'taxonomy' => 'post_tag' );
     275        if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) )
    275276                $args = array();
    276277        else
    277278                $args = $box['args'];
    278279        extract( wp_parse_args($args, $defaults), EXTR_SKIP );
    279280        $tax_name = esc_attr($taxonomy);
    280281        $taxonomy = get_taxonomy($taxonomy);
    281         $disabled = !current_user_can($taxonomy->cap->assign_terms) ? 'disabled="disabled"' : '';
     282        $user_can_assign_terms = current_user_can( $taxonomy->cap->assign_terms );
    282283?>
    283284<div class="tagsdiv" id="<?php echo $tax_name; ?>">
    284285        <div class="jaxtag">
    285286        <div class="nojs-tags hide-if-js">
    286         <p><?php echo $taxonomy->labels->add_or_remove_items; ?></p>
    287         <textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php echo $disabled; ?>><?php echo get_terms_to_edit( $post->ID, $tax_name ); // textarea_escaped by esc_attr() ?></textarea></div>
    288         <?php if ( current_user_can($taxonomy->cap->assign_terms) ) : ?>
     287        <p><?php echo esc_html( $taxonomy->labels->add_or_remove_items ); ?></p>
     288        <textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php disabled( ! $user_can_assign_terms ); ?>><?php echo get_terms_to_edit( $post->ID, $tax_name ); // textarea_escaped by esc_attr() ?></textarea>
     289        </div>
     290        <?php if ( $user_can_assign_terms ) : ?>
    289291        <div class="ajaxtag hide-if-no-js">
    290                 <label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $box['title']; ?></label>
    291                 <div class="taghint"><?php echo $taxonomy->labels->add_new_item; ?></div>
     292                <label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo esc_html( $box['title'] ); ?></label>
     293                <div class="taghint"><?php echo esc_html( $taxonomy->labels->add_new_item ); ?></div>
    292294                <p><input type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
    293295                <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" tabindex="3" /></p>
    294296        </div>
    295         <p class="howto"><?php echo esc_attr( $taxonomy->labels->separate_items_with_commas ); ?></p>
     297        <p class="howto"><?php echo esc_html( $taxonomy->labels->separate_items_with_commas ); ?></p>
    296298        <?php endif; ?>
    297299        </div>
    298300        <div class="tagchecklist"></div>
    299301</div>
    300 <?php if ( current_user_can($taxonomy->cap->assign_terms) ) : ?>
    301 <p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->choose_from_most_used; ?></a></p>
     302<?php if ( $user_can_assign_terms ) : ?>
     303<p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php echo esc_html( $taxonomy->labels->choose_from_most_used ); ?></a></p>
    302304<?php endif; ?>
    303305<?php
    304306}