Make sure rewrite rules are written once 'wp_loaded' is fired
|Reported by:||Chouby||Owned by:||SergeyBiryukov|
With #30501, it was made sure that an early call to flush_rewrite_rules() would not break rewrite rules.
However, in the context of network activation / deactivation, some plugins don't flush the rewrite rules with flush_rewrite_rules() but with a direct call to delete_option( 'rewrite_rules' );. @jeremyfelt explained the reason for doing this in https://jeremyfelt.com/2015/07/17/flushing-rewrite-rules-in-wordpress-multisite-for-fun-and-profit/. For example, Yoast SEO and Polylang are flushing rules at activation / deactivation using this way.
Now, if another plugin uses the rewrite rules before the wp_loaded action is fired (for example by calling url_to_post_id(), the rewrite rules are saved too early and are broken.
Plugins could fix this at activation, but obviously not at deactivation.
Inspired by what has been done to fix #30501, I propose to flush the rewrite rules in the 'wp_loaded' action if there is an attempt to save them before this action has been fired.
Change History (6)
- Milestone changed from Awaiting Review to 4.7
- Owner set to SergeyBiryukov
- Status changed from new to reviewing