From a8802232ecac8184cbe6e8dbe9c6a7bd0f5b7dee Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Fri, 7 Oct 2016 19:44:28 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-rewrite.php | 4 ++++ wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-rewrite.php b/wp-includes/class-wp-rewrite.php index 6efa5833a2..17c58b90a8 100644 --- a/wp-includes/class-wp-rewrite.php +++ b/wp-includes/class-wp-rewrite.php @@ -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); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 7bcc6f0218..fc0d525877 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.