Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/wp-includes/class-wp-rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
43 changes: 43 additions & 0 deletions tests/phpunit/tests/rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
}
}
Loading