From 9e07667864ca860d8683e30ccfdca796229c5657 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 1 May 2017 23:31:16 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@40565 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-walker-page.php | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-walker-page.php b/src/wp-includes/class-walker-page.php index 30831bbc8a..8bec66f417 100644 --- a/src/wp-includes/class-walker-page.php +++ b/src/wp-includes/class-walker-page.php @@ -160,10 +160,38 @@ class Walker_Page extends Walker { $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before']; $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after']; + $atts = array(); + $atts['href'] = get_permalink( $page->ID ); + + /** + * Filters the HTML attributes applied to a page menu item's anchor element. + * + * @since 4.8.0 + * + * @param array $atts { + * The HTML attributes applied to the menu item's `` element, empty strings are ignored. + * + * @type string $href The href attribute. + * } + * @param WP_Post $page Page data object. + * @param int $depth Depth of page, used for padding. + * @param array $args An array of arguments. + * @param int $current_page ID of the current page. + */ + $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page ); + + $attributes = ''; + foreach ( $atts as $attr => $value ) { + if ( ! empty( $value ) ) { + $value = esc_attr( $value ); + $attributes .= ' ' . $attr . '="' . $value . '"'; + } + } + $output .= $indent . sprintf( - '
  • %s%s%s', + '
  • %s%s%s', $css_classes, - get_permalink( $page->ID ), + $attributes, $args['link_before'], /** This filter is documented in wp-includes/post-template.php */ apply_filters( 'the_title', $page->post_title, $page->ID ),