From bb8d792d3732eec77e833a93c1e61cbec36b3a95 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Fri, 7 Oct 2016 19:43:57 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@38751 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-rewrite.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wp-includes/class-wp-rewrite.php b/src/wp-includes/class-wp-rewrite.php index 6efa5833a2..17c58b90a8 100644 --- a/src/wp-includes/class-wp-rewrite.php +++ b/src/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); }