Menus: When checking if a Custom Link matches the current URL to add the `current-menu-item` class, check for decoded URL as well.

Props soulseekah, campusboy1987.
Fixes #43401.
Built from https://develop.svn.wordpress.org/trunk@42732


git-svn-id: http://core.svn.wordpress.org/trunk@42562 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2018-02-24 13:44:31 +00:00
parent fc5617e7fe
commit 0e39cef343
2 changed files with 9 additions and 2 deletions

View File

@ -441,12 +441,19 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
if ( is_customize_preview() ) {
$_root_relative_current = strtok( untrailingslashit( $_SERVER['REQUEST_URI'] ), '?' );
}
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
$raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
$item_url = set_url_scheme( untrailingslashit( $raw_item_url ) );
$_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
if ( $raw_item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) {
$matches = array(
$current_url, urldecode( $current_url ),
$_indexless_current, urldecode( $_indexless_current ),
$_root_relative_current, urldecode( $_root_relative_current ),
);
if ( $raw_item_url && in_array( $item_url, $matches ) ) {
$classes[] = 'current-menu-item';
$menu_items[ $key ]->current = true;
$_anc_id = (int) $menu_item->db_id;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-42731';
$wp_version = '5.0-alpha-42732';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.