Make WordPress Core

Changeset 40565


Ignore:
Timestamp:
05/01/2017 11:31:16 PM (9 years ago)
Author:
SergeyBiryukov
Message:

Menus: Introduce page_menu_link_attributes filter in Walker_Page::start_el() for the HTML attributes applied to a page menu item's anchor element.

This complements the nav_menu_link_attributes filter used in Walker_Nav_Menu::start_el().

Props pbiron.
Fixes #40359.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-walker-page.php

    r39949 r40565  
    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 page menu item's anchor element.
     168                 *
     169                 * @since 4.8.0
     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 */
Note: See TracChangeset for help on using the changeset viewer.