Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#33816 closed defect (bug) (fixed)

Rewrite rules may be flushed incorrectly when home, siteurl, or page_on_front is updated in multisite

Reported by: jeremyfelt's profile jeremyfelt Owned by: jeremyfelt's profile jeremyfelt
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.0
Component: Rewrite Rules Keywords: has-patch
Focuses: multisite Cc:

Description

Rewrite rules have been flushed when the home url for a site is updated for a very long time. See [2494].

Now, if the siteurl, home, or page_on_front options are updated, update_home_siteurl() fires and flushes rewrite rules.

If this happens in site-info.php while updating a site's options in a switched state, the rewrite rules are deleted and then regenerated in the context of the current network's main site. Further up in site-info.php, we already use delete_option( 'rewrite_rules' ); directly as we know that is a better way to flush rules in a switched context.

I think the best option here is to add an ms_is_switched() check to update_home_siteurl() and just delete the rewrite_rules option when true rather than flush. I haven't fully tested this yet though.

Attachments (2)

33816.diff (537 bytes) - added by jeremyfelt 9 years ago.
33816.2.diff (496 bytes) - added by jeremyfelt 9 years ago.

Download all attachments as: .zip

Change History (7)

@jeremyfelt
9 years ago

#1 @jeremyfelt
9 years ago

33816.diff adds the ms_is_switched() check. We may also be able to remove the existing delete_option( 'rewrite_rules' ); in site-info.php.

#2 @jeremyfelt
9 years ago

We could also add a multisite/switched check to flush_rewrite_rules() itself as this is a pretty common error in general.

@jeremyfelt
9 years ago

#3 @jeremyfelt
9 years ago

  • Milestone changed from Future Release to 4.4

33816.2.diff targets the specific issue and leaves flush_rewrite_rules() as is for now.

A better description of what happens here:

  1. A staging site is setup, plugins are activated, and content is entered at https://stage.foo.bar/.
  2. A custom post type is added by a plugin so that the URL https://stage.foo.bar/my-content-type/ is valid.
  3. The staging site URL is updated in the network admin to https://foo.bar/.
  4. https://foo.bar/my-content-type/ is now a 404 because the rewrite rules were generated in the context of the network's main site.

Deleting the rewrite_rules option rather than flushing rewrite rules in this scenario will result in proper rewrite rules being generated on that site's next page view.

#4 @jeremyfelt
9 years ago

  • Owner set to jeremyfelt
  • Resolution set to fixed
  • Status changed from new to closed

In 34672:

MS: Delete rewrite_rules when updating a switched site's URL.

Previously, rewrite rules could be flushed and regenerated in the context of another site. Deleting the rules when in a switched state allows for them to be generated properly on the next page view.

Fixes #33816.

#5 @jeremyfelt
9 years ago

In 34673:

Fixes #33816.

MS: Adjust formatting of code in site-new.php to improve readability.

Fixes #34066.

Note: See TracTickets for help on using tickets.