From 0f1eaa6ca34ecfc6e1c32231cb4301c3ae4f9bf8 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Wed, 25 Sep 2024 19:37:19 +0000 Subject: [PATCH] Canonical: Redirect when front page's paginated states not found. Perform a canonical redirect for an invalid pagination request of a static front page. When a site has a static front page assigned and that page has a `` within its content, previously accessing non-existing pages (e.g. `example.com/page/3/`) did not redirect or return a 404 or 301. This changeset resolves that issue by performing a canonical redirect. Unit tests are also included for this specific use case and to ensure the fix does not affect a blog listing home page. Follow-up to [47738], [47727], [34492]. Props dd32, audrasjb, chaion07, hellofromTonya, joemcgill, lukecarbis, Mte90, mukesh27, peterwilsoncc, rajinsharwar, SergeyBiryukov. Fixes #50163. See meta#5184. Built from https://develop.svn.wordpress.org/trunk@59091 git-svn-id: http://core.svn.wordpress.org/trunk@58487 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp.php | 9 +++++---- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index ce88c102cf..11a0b9e6f8 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -747,14 +747,15 @@ class WP { $content_found = true; if ( is_singular() ) { - $post = isset( $wp_query->post ) ? $wp_query->post : null; - $next = ''; + $post = isset( $wp_query->post ) ? $wp_query->post : null; + $next = ''; + $page_qv = is_front_page() ? 'paged' : 'page'; // Check for paged content that exceeds the max number of pages. - if ( $post && ! empty( $this->query_vars['page'] ) ) { + if ( $post && ! empty( $this->query_vars[ $page_qv ] ) ) { // Check if content is actually intended to be paged. if ( str_contains( $post->post_content, $next ) ) { - $page = trim( $this->query_vars['page'], '/' ); + $page = trim( $this->query_vars[ $page_qv ], '/' ); $content_found = (int) $page <= ( substr_count( $post->post_content, $next ) + 1 ); } else { $content_found = false; diff --git a/wp-includes/version.php b/wp-includes/version.php index 039f6d30bb..e88031962f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-59090'; +$wp_version = '6.7-alpha-59091'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.