From 9d67bfe82d49d891abb113de8ddd3b713b6c2571 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 8 Jan 2015 21:59:57 +0000 Subject: [PATCH] If WP_Rewrite::flush_rules() is called on 'init' or earlier, wait until 'wp_loaded' before actually flushing the rules, to make sure all the rules registered on 'init' are included. props joostdevalk. see #30501. git-svn-id: https://develop.svn.wordpress.org/trunk@31104 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/rewrite.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wp-includes/rewrite.php b/src/wp-includes/rewrite.php index 98791f6dde..0d38db7075 100644 --- a/src/wp-includes/rewrite.php +++ b/src/wp-includes/rewrite.php @@ -2036,6 +2036,12 @@ class WP_Rewrite { * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard). */ public function flush_rules($hard = true) { + // Prevent this action from running before everyone has registered their rewrites + if ( ! did_action( 'wp_loaded' ) ) { + add_action( 'wp_loaded', array( $this, 'flush_rules' ) ); + return; + } + delete_option('rewrite_rules'); $this->wp_rewrite_rules(); /**