WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 8 months ago

#37892 closed defect (bug) (fixed)

Make sure rewrite rules are written once 'wp_loaded' is fired

Reported by: Chouby Owned by: SergeyBiryukov
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.

Attachments (1)

37892.patch (508 bytes) - added by Chouby 9 months ago.

Download all attachments as: .zip

Change History (6)

@Chouby
9 months ago

#1 @Chouby
9 months ago

  • Keywords has-patch added

#2 @SergeyBiryukov
9 months ago

  • Milestone changed from Awaiting Review to 4.7
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#3 @jorbin
8 months ago

@SergeyBiryukov What do you think of the patch?

This ticket was mentioned in Slack in #core by stevenkword. View the logs.


8 months ago

#5 @jorbin
8 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 38751:

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.

Note: See TracTickets for help on using tickets.