Make WordPress Core


Ignore:
Timestamp:
09/24/2015 02:03:05 PM (9 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r34446 r34492  
    147147                $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
    148148            }
     149        }
     150
     151        if ( get_query_var( 'page' ) && $wp_query->post &&
     152            false !== strpos( $wp_query->post->post_content, '<!--nextpage-->' ) ) {
     153            $redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
     154            $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
     155            $redirect_url = get_permalink( $wp_query->post->ID );
    149156        }
    150157
     
    561568        if ( get_query_var( 'feed' ) )
    562569            return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
    563         elseif ( get_query_var( 'page' ) )
     570        elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' ) )
    564571            return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
    565572        else
Note: See TracChangeset for help on using the changeset viewer.