Make WordPress Core

Ticket #38636: 38636.1.patch

File 38636.1.patch, 4.0 KB (added by pbiron, 6 years ago)

the inline docs for WP_Admin_Bar::add_node() need some work

  • wp-includes/class-wp-admin-bar.php

    diff --git a/wp-includes/class-wp-admin-bar.php b/wp-includes/class-wp-admin-bar.php
    index 49986ac..3386408 100644
    a b class WP_Admin_Bar { 
    100100         *
    101101         * @since 3.1.0
    102102         * @since 4.5.0 Added the ability to pass 'lang' and 'dir' meta data.
     103         * @since 4.8.x Added the ability to arbitrary HTML attributes as meta data
    103104         * @access public
    104105         *
    105106         * @param array $args {
    class WP_Admin_Bar { 
    110111         *     @type string $parent Optional. ID of the parent node.
    111112         *     @type string $href   Optional. Link for the item.
    112113         *     @type bool   $group  Optional. Whether or not the node is a group. Default false.
    113          *     @type array  $meta   Meta data including the following keys: 'html', 'class', 'rel', 'lang', 'dir',
    114          *                          'onclick', 'target', 'title', 'tabindex'. Default empty.
     114         *     @type array  $meta   {
     115         *          Optional. HTML attributes (except for 'html', see below)
     116         *
     117         *          @type string $html Arbitrary HTML markup output after the node
     118         *          @type string xxx Arbitrary HTML attribute
     119         *     }
    115120         * }
    116121         */
    117122        public function add_node( $args ) {
    class WP_Admin_Bar { 
    494499                if ( $menuclass )
    495500                        $menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"';
    496501
     502                if ( !isset( $node->meta['class'] ) ) {
     503                        $node->meta['class'] = 'ab-item';
     504                } else {
     505                        $node->meta['class'] .= ' ab-item';
     506                }
     507                       
     508                if ( $has_link ) {
     509                        $node->meta['class'] .= ' ab-empty-item';
     510                }
    497511                ?>
    498512
    499513                <li id="<?php echo esc_attr( 'wp-admin-bar-' . $node->id ); ?>"<?php echo $menuclass; ?>><?php
    500514                        if ( $has_link ):
    501                                 ?><a class="ab-item"<?php echo $aria_attributes; ?> href="<?php echo esc_url( $node->href ) ?>"<?php
    502                                         if ( ! empty( $node->meta['onclick'] ) ) :
    503                                                 ?> onclick="<?php echo esc_js( $node->meta['onclick'] ); ?>"<?php
    504                                         endif;
    505                                 if ( ! empty( $node->meta['target'] ) ) :
    506                                         ?> target="<?php echo esc_attr( $node->meta['target'] ); ?>"<?php
    507                                 endif;
    508                                 if ( ! empty( $node->meta['title'] ) ) :
    509                                         ?> title="<?php echo esc_attr( $node->meta['title'] ); ?>"<?php
    510                                 endif;
    511                                 if ( ! empty( $node->meta['rel'] ) ) :
    512                                         ?> rel="<?php echo esc_attr( $node->meta['rel'] ); ?>"<?php
    513                                 endif;
    514                                 if ( ! empty( $node->meta['lang'] ) ) :
    515                                         ?> lang="<?php echo esc_attr( $node->meta['lang'] ); ?>"<?php
    516                                 endif;
    517                                 if ( ! empty( $node->meta['dir'] ) ) :
    518                                         ?> dir="<?php echo esc_attr( $node->meta['dir'] ); ?>"<?php
    519                                 endif;
    520                                 ?>><?php
     515                        ?><a<?php echo $aria_attributes; ?> href="<?php echo esc_url( $node->href ) ?>"<?php
     516                                foreach ( $node->meta as $attr => $value ) {
     517                                        if ( in_array($attr, array( 'aria-haspopup', 'href', 'html', ) ) || empty( $value ) ) {
     518                                                continue ;
     519                                        }
     520
     521                                        // @todo it would probably be a good idea to sanitize the attribute name
     522                                        //    AFAIK core doesn't current contain a func to do that, should one be added?
     523                                        echo sprintf (" $attr=\"%s\"",
     524                                                stripos ( $attr, 'on' ) === 0 ? esc_js( $value ) : esc_attr( $value ) );
     525                        }
     526                        ?>><?php
    521527                        else:
    522                                 ?><div class="ab-item ab-empty-item"<?php echo $aria_attributes;
    523                                 if ( ! empty( $node->meta['title'] ) ) :
    524                                         ?> title="<?php echo esc_attr( $node->meta['title'] ); ?>"<?php
    525                                 endif;
    526                                 if ( ! empty( $node->meta['lang'] ) ) :
    527                                         ?> lang="<?php echo esc_attr( $node->meta['lang'] ); ?>"<?php
    528                                 endif;
    529                                 if ( ! empty( $node->meta['dir'] ) ) :
    530                                         ?> dir="<?php echo esc_attr( $node->meta['dir'] ); ?>"<?php
    531                                 endif;
    532                                 ?>><?php
     528                                        ?><div<?php echo $aria_attributes;
     529                                foreach ( $node->meta as $attr => $value ) {
     530                                        if ( in_array($attr, array( 'aria-haspopup', 'html', ) ) || empty( $value ) ) {
     531                                                continue ;
     532                                        }
     533
     534                                        // @todo it would probably be a good idea to sanitize the attribute name
     535                                        //    AFAIK core doesn't current contain a func to do that, should one be added?
     536                                        echo sprintf (" $attr=\"%s\"",
     537                                                stripos ( $attr, 'on' ) === 0 ? esc_js( $value ) : esc_attr( $value ) );
     538                        }?>><?php
    533539                        endif;
    534540
    535541                        echo $node->title;