Make WordPress Core

Ticket #38636: 38636.2.patch

File 38636.2.patch, 2.9 KB (added by sabernhardt, 4 years ago)

refresh, allowing almost any attributes, adding aria-current

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

     
    108108         *
    109109         * @since 3.1.0
    110110         * @since 4.5.0 Added the ability to pass 'lang' and 'dir' meta data.
     111         * @since x.x.x Added the ability to pass most HTML attributes as meta data.
     112         * @since x.x.x Added `aria-current` attribute.
    111113         *
     114         * @global string $pagenow
     115         *
    112116         * @param array $args {
    113117         *     Arguments for adding a node.
    114118         *
     
    117121         *     @type string $parent Optional. ID of the parent node.
    118122         *     @type string $href   Optional. Link for the item.
    119123         *     @type bool   $group  Optional. Whether or not the node is a group. Default false.
    120          *     @type array  $meta   Meta data including the following keys: 'html', 'class', 'rel', 'lang', 'dir',
    121          *                          'onclick', 'target', 'title', 'tabindex'. Default empty.
     124         *     @type array  $meta   Optional. Meta data for the node.
     125         *                          Add HTML attributes to the item, such as
     126         *                          'rel', 'lang', 'dir', 'onclick', 'target', 'title', 'tabindex'.
     127         *                          Reserved attributes include 'href', 'aria-haspopup', 'aria-current'.
     128         *                          Use 'html' to append arbitrary HTML content within the node.
     129         *                          Use 'class' to apply classes to the node element.
     130         *                          Default empty.
    122131         * }
    123132         */
    124133        public function add_node( $args ) {
     
    537546                echo "<li id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$menuclass>";
    538547
    539548                if ( $has_link ) {
    540                         $attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
     549                        if ( is_admin() ) {
     550                                global $pagenow;
     551                                if ( $node->href == network_admin_url( $pagenow ) ) {
     552                                        $aria_attributes .= ' aria-current="page"';
     553                                }
     554                        }
    541555                        echo "<a class='ab-item'$aria_attributes href='" . esc_url( $node->href ) . "'";
    542556                } else {
    543                         $attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' );
    544557                        echo '<div class="ab-item ab-empty-item"' . $aria_attributes;
    545558                }
    546559
    547                 foreach ( $attributes as $attribute ) {
    548                         if ( empty( $node->meta[ $attribute ] ) ) {
     560                $reserved = array( 'html', 'class', 'href', 'tabindex', 'aria-haspopup', 'aria-current' );
     561
     562                foreach ( $node->meta as $attr => $value ) {
     563                        if ( in_array( $attr, $reserved ) || empty( $value ) ) {
    549564                                continue;
    550565                        }
    551566
    552                         if ( 'onclick' === $attribute ) {
    553                                 echo " $attribute='" . esc_js( $node->meta[ $attribute ] ) . "'";
    554                         } else {
    555                                 echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'";
    556                         }
     567                        printf(
     568                                ' %s="%s"',
     569                                $attr,
     570                                0 === stripos( $attr, 'on' ) ? esc_js( $value ) : esc_attr( $value )
     571                        );
    557572                }
    558573
    559574                echo ">{$arrow}{$node->title}";