From 49950626863a2bc09825875412a4501a7e17ed16 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 1 May 2017 23:32:42 +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. Built from https://develop.svn.wordpress.org/trunk@40565 git-svn-id: http://core.svn.wordpress.org/trunk@40434 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-walker-page.php | 32 +++++++++++++++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-walker-page.php b/wp-includes/class-walker-page.php index 30831bbc8a..8bec66f417 100644 --- a/wp-includes/class-walker-page.php +++ b/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 ), diff --git a/wp-includes/version.php b/wp-includes/version.php index c0167e08b4..7d33e42476 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-40564'; +$wp_version = '4.8-alpha-40565'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.