Detect current menu items for root-relative URLs. props filosofo, fixes #15954.
git-svn-id: https://develop.svn.wordpress.org/trunk@18746 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3094ed7733
commit
c0682ee59b
|
@ -360,11 +360,12 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
|
||||||
|
|
||||||
// if the menu item corresponds to the currently-requested URL
|
// if the menu item corresponds to the currently-requested URL
|
||||||
} elseif ( 'custom' == $menu_item->object ) {
|
} elseif ( 'custom' == $menu_item->object ) {
|
||||||
$current_url = untrailingslashit( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
|
$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
|
||||||
|
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_root_relative_current;
|
||||||
$item_url = untrailingslashit( strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url );
|
$item_url = untrailingslashit( strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url );
|
||||||
$_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) );
|
$_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) );
|
||||||
|
|
||||||
if ( in_array( $item_url, array( $current_url, $_indexless_current ) ) ) {
|
if ( in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) {
|
||||||
$classes[] = 'current-menu-item';
|
$classes[] = 'current-menu-item';
|
||||||
$menu_items[$key]->current = true;
|
$menu_items[$key]->current = true;
|
||||||
$_anc_id = (int) $menu_item->db_id;
|
$_anc_id = (int) $menu_item->db_id;
|
||||||
|
|
Loading…
Reference in New Issue