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 ); } /** diff --git a/tests/phpunit/tests/rewrite.php b/tests/phpunit/tests/rewrite.php index 2bb7254abfcef..fad67b2b7b387 100644 --- a/tests/phpunit/tests/rewrite.php +++ b/tests/phpunit/tests/rewrite.php @@ -504,4 +504,47 @@ public function test_flush_rules_does_not_delete_option() { $this->assertIsArray( $rewrite_rules ); $this->assertNotEmpty( $rewrite_rules ); } + + /** + * + * @ticket 9824 + */ + 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" ); + } + } + + /** + * + * @ticket 9824 + */ + 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" ); + } + } }