diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 30b6f6b8b4..a88b3a8e22 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -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, '' ) ) { + $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 ); diff --git a/wp-includes/class-wp-rewrite.php b/wp-includes/class-wp-rewrite.php index e828f8d1cf..5f7bbb2340 100644 --- a/wp-includes/class-wp-rewrite.php +++ b/wp-includes/class-wp-rewrite.php @@ -1071,8 +1071,10 @@ class WP_Rewrite { $sub1 .= '?$'; $sub2 .= '?$'; - //post pagination, e.g. /2/ - $match = $match . '(/[0-9]+)?/?$'; + // Post pagination, e.g. /2/ + // Previously: '(/[0-9]+)?/?$', which produced '/2' for page. + // When cast to int, returned 0. + $match = $match . '(?:/([0-9]+))?/?$'; $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1); } else { //not matching a permalink so this is a lot simpler //close the match and finalise the query diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 60eb6aff83..4e859ee9e1 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -587,7 +587,7 @@ class WP { * @global WP_Query $wp_query */ public function handle_404() { - global $wp_query; + global $wp_query, $wp; // If we've already issued a 404, bail. if ( is_404() ) @@ -596,16 +596,26 @@ class WP { // Never 404 for the admin, robots, or if we found posts. if ( is_admin() || is_robots() || $wp_query->posts ) { - // Only set X-Pingback for single posts. + $success = true; if ( is_singular() ) { $p = clone $wp_query->post; + // Only set X-Pingback for single posts that allow pings. if ( $p && pings_open( $p ) ) { @header( 'X-Pingback: ' . get_bloginfo( 'pingback_url' ) ); } + + // check for paged content that exceeds the max number of pages + $next = ''; + if ( $p && false !== strpos( $p->post_content, $next ) && ! empty( $wp->query_vars['page'] ) ) { + $page = trim( $wp->query_vars['page'], '/' ); + $success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 ); + } } - status_header( 200 ); - return; + if ( $success ) { + status_header( 200 ); + return; + } } // We will 404 for paged queries, as no posts were found. diff --git a/wp-includes/rewrite-functions.php b/wp-includes/rewrite-functions.php index 96739a8da3..840e5d6425 100644 --- a/wp-includes/rewrite-functions.php +++ b/wp-includes/rewrite-functions.php @@ -256,6 +256,8 @@ function wp_resolve_numeric_slug_conflicts( $query_vars = array() ) { } elseif ( 'monthnum' === $compare && isset( $query_vars['day'] ) ) { $maybe_page = $query_vars['day']; } + // Bug found in #11694 - 'page' was returning '/4' + $maybe_page = (int) trim( $maybe_page, '/' ); $post_page_count = substr_count( $post->post_content, '' ) + 1; diff --git a/wp-includes/version.php b/wp-includes/version.php index 6e57ca3dbf..a720382e9f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34491'; +$wp_version = '4.4-alpha-34492'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.