Make sure rewrite rules are not written until wp_loaded has fired

If a plugin attempts to change the rewrite rules to early, other plugins may have their rules inadvertently discarded. Additionally, some function such as `url_to_post_id` cause a rewrite rule lookup that could cause this accidental flushing. This forces the flushing to only occur once `wp_loaded` has been fired.

Fixes #37892.
Props Chouby.


Built from https://develop.svn.wordpress.org/trunk@38751


git-svn-id: http://core.svn.wordpress.org/trunk@38694 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2016-10-07 19:44:28 +00:00
parent 0dcd49e6fc
commit a8802232ec
2 changed files with 5 additions and 1 deletions

View File

@ -1475,6 +1475,10 @@ class WP_Rewrite {
if ( empty($this->rules) ) {
$this->matches = 'matches';
$this->rewrite_rules();
if ( ! did_action( 'wp_loaded' ) ) {
add_action( 'wp_loaded', array( $this, 'flush_rules' ) );
return $this->rules;
}
update_option('rewrite_rules', $this->rules);
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38750';
$wp_version = '4.7-alpha-38751';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.