From 768caff1878e1820b3e7c0600ed4808ceaaf5821 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Mon, 20 Apr 2026 21:54:19 +0530 Subject: [PATCH 1/4] Fix: Regex pattern matching to identify verbose rules need --- src/wp-includes/class-wp-rewrite.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/class-wp-rewrite.php b/src/wp-includes/class-wp-rewrite.php index 8b75fa5c36d16..e6d851c2cb345 100644 --- a/src/wp-includes/class-wp-rewrite.php +++ b/src/wp-includes/class-wp-rewrite.php @@ -1938,11 +1938,13 @@ public function init() { $this->use_trailing_slashes = str_ends_with( $this->permalink_structure, '/' ); // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. - if ( preg_match( '/^[^%]*%(?:postname|category|tag|author)%/', $this->permalink_structure ) ) { - $this->use_verbose_page_rules = true; - } else { - $this->use_verbose_page_rules = false; + $clean_structure = str_replace( '/' . $this->index, '', $this->permalink_structure ); + + if ( is_multisite() && ! is_subdomain_install() && is_main_site() ) { + $clean_structure = preg_replace( '/^\/\w+/', '', $clean_structure, 1 ); } + + $this->use_verbose_page_rules = (bool) preg_match( '#^/?%(?:postname|category|tag|author)%#', $clean_structure ); } /** From 7279cd3d18ce85c26d7363be07fa8b2149705995 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Tue, 21 Apr 2026 21:12:05 +0530 Subject: [PATCH 2/4] Tests: Verfiy for verbose page rules enabled without stub --- tests/phpunit/tests/rewrite.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/phpunit/tests/rewrite.php b/tests/phpunit/tests/rewrite.php index 2bb7254abfcef..d05c77e785854 100644 --- a/tests/phpunit/tests/rewrite.php +++ b/tests/phpunit/tests/rewrite.php @@ -504,4 +504,20 @@ public function test_flush_rules_does_not_delete_option() { $this->assertIsArray( $rewrite_rules ); $this->assertNotEmpty( $rewrite_rules ); } + + public function test_verbose_page_rules_enabled_without_stub() { + global $wp_rewrite; + + $structures_expecting_true = array( + '/%postname%/', + '/%category%/%postname%/', + '/%tag%/%postname%/', + '/%author%/%postname%/', + ); + + foreach ( $structures_expecting_true as $structure ) { + $this->set_permalink_structure( $structure ); + $this->assertTrue( $wp_rewrite->use_verbose_page_rules, "Expected true for: $structure" ); + } + } } From 675e9f538aa1168319938aa7369233c3d8c4b50a Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Tue, 21 Apr 2026 21:12:56 +0530 Subject: [PATCH 3/4] Tests: Verify for verbose page rules disabled with stub --- tests/phpunit/tests/rewrite.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/phpunit/tests/rewrite.php b/tests/phpunit/tests/rewrite.php index d05c77e785854..ef05e3f437b0f 100644 --- a/tests/phpunit/tests/rewrite.php +++ b/tests/phpunit/tests/rewrite.php @@ -520,4 +520,23 @@ public function test_verbose_page_rules_enabled_without_stub() { $this->assertTrue( $wp_rewrite->use_verbose_page_rules, "Expected true for: $structure" ); } } + + public function test_verbose_page_rules_disabled_with_stub() { + global $wp_rewrite; + + $structures_expecting_false = array( + '/news/%postname%/', + '/blog/%postname%/', + '/news-and-events/%postname%/', + '/articles/%category%/%postname%/', + '/%year%/%monthnum%/%postname%/', + '/%year%/%postname%/', + '/archives/%post_id%', + ); + + foreach ( $structures_expecting_false as $structure ) { + $this->set_permalink_structure( $structure ); + $this->assertFalse( $wp_rewrite->use_verbose_page_rules, "Expected false for: $structure" ); + } + } } From 9ae8f6b05965f3b8ac281ea3eb017b04345e5710 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Tue, 21 Apr 2026 21:13:59 +0530 Subject: [PATCH 4/4] Docs: Add test doc block --- tests/phpunit/tests/rewrite.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/phpunit/tests/rewrite.php b/tests/phpunit/tests/rewrite.php index ef05e3f437b0f..fad67b2b7b387 100644 --- a/tests/phpunit/tests/rewrite.php +++ b/tests/phpunit/tests/rewrite.php @@ -505,6 +505,10 @@ public function test_flush_rules_does_not_delete_option() { $this->assertNotEmpty( $rewrite_rules ); } + /** + * + * @ticket 9824 + */ public function test_verbose_page_rules_enabled_without_stub() { global $wp_rewrite; @@ -521,6 +525,10 @@ public function test_verbose_page_rules_enabled_without_stub() { } } + /** + * + * @ticket 9824 + */ public function test_verbose_page_rules_disabled_with_stub() { global $wp_rewrite;