Make WordPress Core

Ticket #40359: page_menu_link_attributes.diff

File page_menu_link_attributes.diff, 1.6 KB (added by pbiron, 8 years ago)

patch implementing suggestion

  • wp-includes/class-walker-page.php

    diff --git a/wp-includes/class-walker-page.php b/wp-includes/class-walker-page.php
    index 30831bb..9b9cc1b 100644
    a b class Walker_Page extends Walker { 
    160160                $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
    161161                $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
    162162
     163                $atts = array();
     164                $atts['href'] = get_permalink( $page->ID );
     165
     166                /**
     167                 * Filters the HTML attributes applied to a menu item's anchor element.
     168                 *
     169                 * @since 4.x.x
     170                 *
     171                 * @param array $atts {
     172                 *     The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
     173                 *
     174                 *     @type string $href   The href attribute.
     175                 * }
     176                 * @param WP_Post $page         Page data object.
     177                 * @param int     $depth        Depth of page, used for padding.
     178                 * @param array   $args         An array of arguments.
     179                 * @param int     $current_page ID of the current page.
     180                 */
     181                $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
     182
     183                $attributes = '';
     184                foreach ( $atts as $attr => $value ) {
     185                        if ( ! empty( $value ) ) {
     186                                $value = esc_attr( $value );
     187                                $attributes .= ' ' . $attr . '="' . $value . '"';
     188                        }
     189                }
     190
    163191                $output .= $indent . sprintf(
    164                         '<li class="%s"><a href="%s">%s%s%s</a>',
     192                        '<li class="%s"><a%s>%s%s%s</a>',
    165193                        $css_classes,
    166                         get_permalink( $page->ID ),
     194                        $attributes,
    167195                        $args['link_before'],
    168196                        /** This filter is documented in wp-includes/post-template.php */
    169197                        apply_filters( 'the_title', $page->post_title, $page->ID ),