Make WordPress Core

Ticket #32221: 32221.patch

File 32221.patch, 1.2 KB (added by McGuive7, 11 years ago)

Fixes to more accurately add current-menu-item class for custom menu items when URLs aren't an exact match (https/http, URL parameters)

  • wp-includes/nav-menu-template.php

     
    545545
    546546                // if the menu item corresponds to the currently-requested URL
    547547                } elseif ( 'custom' == $menu_item->object ) {
    548                         $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
     548
     549                        // Use strtok() to omit any URL parameters when comparing
     550                        $_root_relative_current = untrailingslashit( strtok( $_SERVER['REQUEST_URI'], '?' ) );
    549551                        $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
    550552                        $raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
    551                         $item_url = untrailingslashit( $raw_item_url );
     553                        $item_url = set_url_scheme( untrailingslashit( strtok( $raw_item_url, '?' ) ) );
    552554                        $_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
    553555
    554556                        if ( $raw_item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) {