mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-06 23:58:03 +00:00
Canonical/Rewrite: sanity check posts that are paged with <!--nextpage-->. Page numbers past the max number of pages are returning the last page of content and causing infinite duplicate content.
Awesome rewrite bug: the `page` query var was being set to `'/4'` in `$wp`. When cast to `int`, it returns `0` (Bless you, PHP). `WP_Query` calls `trim( $page, '/' )` when setting its own query var. The few places that were checking `page` before posts were queried now have sanity checks, so that these changes work without flushing rewrites. Adds/updates unit tests. Props wonderboymusic, dd32. See #11694. git-svn-id: https://develop.svn.wordpress.org/trunk@34492 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -148,6 +148,13 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( get_query_var( 'page' ) && $wp_query->post &&
|
||||
false !== strpos( $wp_query->post->post_content, '<!--nextpage-->' ) ) {
|
||||
$redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
|
||||
$redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
|
||||
$redirect_url = get_permalink( $wp_query->post->ID );
|
||||
}
|
||||
|
||||
} elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
|
||||
// rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
|
||||
if ( is_attachment() && ! $redirect_url ) {
|
||||
@@ -560,7 +567,7 @@ function redirect_guess_404_permalink() {
|
||||
return false;
|
||||
if ( get_query_var( 'feed' ) )
|
||||
return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
|
||||
elseif ( get_query_var( 'page' ) )
|
||||
elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' ) )
|
||||
return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
|
||||
else
|
||||
return get_permalink( $post_id );
|
||||
|
||||
Reference in New Issue
Block a user