Ticket #17661: fix-canonical-by-matched-query.diff
| File fix-canonical-by-matched-query.diff, 2.2 KB (added by wonderboymusic, 9 months ago) |
|---|
-
wp-includes/canonical.php
10 10 */ 11 11 12 12 /** 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 */ 21 function 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 /** 13 29 * Redirects incoming links to the proper URL based on the site url. 14 30 * 15 31 * Search engines consider www.somedomain.com and somedomain.com to be two … … 38 54 */ 39 55 function redirect_canonical( $requested_url = null, $do_redirect = true ) { 40 56 global $wp_rewrite, $is_IIS, $wp_query, $wpdb; 41 57 42 58 if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || ( $is_IIS && !iis7_supports_permalinks() ) ) 43 59 return; 44 60 … … 148 164 } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) { 149 165 if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) 150 166 $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'] ) ) { 152 168 if ( $redirect_url = get_year_link(get_query_var('year')) ) 153 169 $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'] ) ) { 155 171 $author = get_userdata(get_query_var('author')); 156 172 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 ) ) ) { 157 173 if ( $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) )