Make WordPress Core


Ignore:
Timestamp:
09/24/2015 02:03:05 PM (11 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/class-wp.php

    r34476 r34492  
    588588         */
    589589        public function handle_404() {
    590                 global $wp_query;
     590                global $wp_query, $wp;
    591591
    592592                // If we've already issued a 404, bail.
     
    597597                if ( is_admin() || is_robots() || $wp_query->posts ) {
    598598
    599                         // Only set X-Pingback for single posts.
     599                        $success = true;
    600600                        if ( is_singular() ) {
    601601                                $p = clone $wp_query->post;
     602                                // Only set X-Pingback for single posts that allow pings.
    602603                                if ( $p && pings_open( $p ) ) {
    603604                                        @header( 'X-Pingback: ' . get_bloginfo( 'pingback_url' ) );
    604605                                }
    605                         }
    606 
    607                         status_header( 200 );
    608                         return;
     606
     607                                // check for paged content that exceeds the max number of pages
     608                                $next = '<!--nextpage-->';
     609                                if ( $p && false !== strpos( $p->post_content, $next ) && ! empty( $wp->query_vars['page'] ) ) {
     610                                        $page = trim( $wp->query_vars['page'], '/' );
     611                                        $success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 );
     612                                }
     613                        }
     614
     615                        if ( $success ) {
     616                                status_header( 200 );
     617                                return;
     618                        }
    609619                }
    610620
Note: See TracChangeset for help on using the changeset viewer.