summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorTonya Mork <hellofromtonya@git.wordpress.org>2024-09-30 18:16:18 +0000
committerTonya Mork <hellofromtonya@git.wordpress.org>2024-09-30 18:16:18 +0000
commit1f40d422c23a2e3a35140c4b3856721b7eac70db (patch)
treef860dd6e4b288a2dfebce91497140f9abc42a72f
parent92fdeb486b8315505281329ad986f298538d3b38 (diff)
downloadwordpress-1f40d422c23a2e3a35140c4b3856721b7eac70db.tar.gz
wordpress-1f40d422c23a2e3a35140c4b3856721b7eac70db.zip
Canonical: Revert redirect when front page's paginated states not found.
r59091 introduced a backward compatibility (BC) break for a static homepage that includes a shortcode's or block's with paginated content that uses the `'paged'` query var, e.g. bbPress. In this use case, attempting to navigate the shortcode / block's pagination causes a canonical redirect, rather than navigating to the next page of content within that shortcode or block. Follow-up to [59091]. Props davidbinda, jjj. See #50163, #meta5184. git-svn-id: https://develop.svn.wordpress.org/trunk@59133 602fd350-edb4-49c9-b593-d223f7449a82
-rw-r--r--src/wp-includes/class-wp.php9
-rw-r--r--tests/phpunit/tests/canonical/paged.php45
2 files changed, 4 insertions, 50 deletions
diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php
index 11a0b9e6f8..ce88c102cf 100644
--- a/src/wp-includes/class-wp.php
+++ b/src/wp-includes/class-wp.php
@@ -747,15 +747,14 @@ class WP {
$content_found = true;
if ( is_singular() ) {
- $post = isset( $wp_query->post ) ? $wp_query->post : null;
- $next = '<!--nextpage-->';
- $page_qv = is_front_page() ? 'paged' : 'page';
+ $post = isset( $wp_query->post ) ? $wp_query->post : null;
+ $next = '<!--nextpage-->';
// Check for paged content that exceeds the max number of pages.
- if ( $post && ! empty( $this->query_vars[ $page_qv ] ) ) {
+ if ( $post && ! empty( $this->query_vars['page'] ) ) {
// Check if content is actually intended to be paged.
if ( str_contains( $post->post_content, $next ) ) {
- $page = trim( $this->query_vars[ $page_qv ], '/' );
+ $page = trim( $this->query_vars['page'], '/' );
$content_found = (int) $page <= ( substr_count( $post->post_content, $next ) + 1 );
} else {
$content_found = false;
diff --git a/tests/phpunit/tests/canonical/paged.php b/tests/phpunit/tests/canonical/paged.php
index 0929dde057..d2440ef18b 100644
--- a/tests/phpunit/tests/canonical/paged.php
+++ b/tests/phpunit/tests/canonical/paged.php
@@ -26,49 +26,4 @@ class Tests_Canonical_Paged extends WP_Canonical_UnitTestCase {
// Non-existing page should redirect to the permalink.
$this->assertCanonical( $link . '4/', $link );
}
-
- /**
- * Ensures canonical redirects are performed for sites with a static front page.
- *
- * @ticket 50163
- */
- public function test_redirect_missing_front_page_pagination_canonical() {
- update_option( 'show_on_front', 'page' );
-
- $page_id = self::factory()->post->create(
- array(
- 'post_title' => 'front-page-1',
- 'post_type' => 'page',
- 'post_content' => "Front Page 1\n<!--nextpage-->\nPage 2",
- )
- );
-
- update_option( 'page_on_front', $page_id );
-
- $link = parse_url( get_permalink( $page_id ), PHP_URL_PATH );
-
- // Valid page numbers should not redirect.
- $this->assertCanonical( $link, $link, 'The home page is not expected to redirect.' );
- $this->assertCanonical( $link . 'page/2/', $link . 'page/2/', 'Page 2 exists and is not expected to redirect.' );
-
- // Invalid page numbers should redirect to the front page.
- $this->assertCanonical( $link . 'page/3/', $link, 'Page 3 does not exist and is expected to redirect to the home page.' );
- }
-
- /**
- * Ensures that canonical redirects are not performed for sites with a blog listing home page.
- *
- * @ticket 50163
- */
- public function test_redirect_missing_front_page_pagination_does_not_affect_posts_canonical() {
- self::factory()->post->create_many( 3 );
- update_option( 'posts_per_page', 2 );
-
- // Valid page numbers should not redirect.
- $this->assertCanonical( '/', '/', 'Page one of the blog archive should not redirect.' );
- $this->assertCanonical( '/page/2/', '/page/2/', 'Page 2 of the blog archive exists and is not expected to redirect.' );
-
- // Neither should invalid page numbers.
- $this->assertCanonical( '/page/3/', '/page/3/', 'Page 3 of the blog archive is not populated but is not expected to redirect.' );
- }
}