Opened 8 years ago
Closed 8 years ago
#37892 closed defect (bug) (fixed)
Make sure rewrite rules are written once 'wp_loaded' is fired
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Rewrite Rules | Keywords: | has-patch |
Focuses: | Cc: |
Description
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.
@SergeyBiryukov What do you think of the patch?