WordPress.org

Make WordPress Core

Ticket #17661: fix-canonical-by-matched-query.diff

File fix-canonical-by-matched-query.diff, 2.2 KB (added by wonderboymusic, 20 months ago)
  • wp-includes/canonical.php

     
    1010 */ 
    1111 
    1212/** 
     13 * Determine if query var was the highest order matched rule in the query 
     14 *  
     15 * @since 3.5.0 
     16 *  
     17 * @global WP $wp 
     18 * @param string $var 
     19 * @return bool 
     20 */ 
     21function is_matched_query( $var ) { 
     22        global $wp; 
     23        $queries = wp_parse_args( $wp->matched_query ); 
     24         
     25        return empty( $wp->matched_query ) || array_key_exists( $var, $queries ); 
     26} 
     27 
     28/** 
    1329 * Redirects incoming links to the proper URL based on the site url. 
    1430 * 
    1531 * Search engines consider www.somedomain.com and somedomain.com to be two 
     
    3854 */ 
    3955function redirect_canonical( $requested_url = null, $do_redirect = true ) { 
    4056        global $wp_rewrite, $is_IIS, $wp_query, $wpdb; 
    41  
     57         
    4258        if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || ( $is_IIS && !iis7_supports_permalinks() ) ) 
    4359                return; 
    4460 
     
    148164                } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) { 
    149165                        if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) 
    150166                                $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); 
    151                 } elseif ( is_year() && !empty($_GET['year']) ) { 
     167                } elseif ( is_matched_query( 'year' ) && is_year() && ! empty( $_GET['year'] ) ) { 
    152168                        if ( $redirect_url = get_year_link(get_query_var('year')) ) 
    153169                                $redirect['query'] = remove_query_arg('year', $redirect['query']); 
    154                 } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { 
     170                } elseif ( is_matched_query( 'author' ) && is_author() && ! empty( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { 
    155171                        $author = get_userdata(get_query_var('author')); 
    156172                        if ( ( false !== $author ) && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) ) { 
    157173                                if ( $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) )