[wp-trac] [WordPress Trac] #14849: Rewrite rules should be flushed when you switch themes
WordPress Trac
noreply at wordpress.org
Thu Sep 10 18:16:25 UTC 2015
#14849: Rewrite rules should be flushed when you switch themes
-------------------------+-----------------------
Reporter: jorbin | Owner: jorbin
Type: enhancement | Status: assigned
Priority: normal | Milestone: 4.4
Component: Permalinks | Version: 3.0
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
-------------------------+-----------------------
Changes (by jorbin):
* keywords: needs-patch needs-unit-tests => needs-patch
Comment:
I can't figure out a good way to unit test this since:
1) None of the default themes that we use for testing have custom rewrite
rules.
2) flush_rewrite_rules relies upon saving the in memory rules. As the
tests all run in a single memory session, there isn't a good way to fake
this that would produce reliable test results.
This is the test code I was playing around with before coming to this
conclusion.
{{{
class Tests_Flush_On_Theme_Change extends WP_UnitTestCase {
private $original_rewrite_rules;
private $current_theme;
function setUp() {
global $wp_rewrite;
parent::setUp();
// Need rewrite rules in place to use url_to_postid
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure(
'/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies();
$wp_rewrite->flush_rules();
$this->original_rewrite_rules = get_option( 'rewrite_rules' );
$this->current_theme = wp_get_theme();
}
function tearDown() {
global $wp_rewrite;
$wp_rewrite->init();
$theme = $this->current_theme;
switch_theme( $theme->Stylesheet );
parent::tearDown();
}
/**
* @ticket 14849
*/
function test_switch_theme_rewrite_flush() {
$themes = wp_get_themes();
flush_rewrite_rules();
add_rewrite_rule('^test/([0-9]+)/?',
'index.php?page_id=$matches[1]', 'top');
flush_rewrite_rules();
$updated_rewrite_rules = get_option( 'rewrite_rules' );
$this->assertNotEquals( $this->original_rewrite_rules ,
$updated_rewrite_rules );
foreach ( $themes as $theme ) {
switch_theme( $theme->Template, $theme->Stylesheet );
$updated_rewrite_rules = get_option( 'rewrite_rules' );
$this->assertEquals( $this->original_rewrite_rules ,
$updated_rewrite_rules );
}
}
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/14849#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list