#29107 closed defect (bug) (fixed)
WP_Rewrite::flush_rules() should not delete 'rewrite_rules' option
Reported by: | SergeyBiryukov | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | 2.0.1 |
Component: | Rewrite Rules | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
If permalinks are disabled, there's an extra query on each page load:
SELECT option_value FROM trunk_options WHERE option_name = 'rewrite_rules' LIMIT 1
It comes from WP::parse_request(), which calls WP_Rewrite::wp_rewrite_rules().
Normally, it should be covered by wp_load_alloptions(), but:
- The
rewrite_rules
option is not created on installation. - If you enable permalinks and disable them again, WP_Rewrite::flush_rules() deletes the option.
- WP_Rewrite::wp_rewrite_rules() attempts to recreate it, but fails due to the check in update_option().
I think we should replace rewrite_rules
option with an empty value instead of deleting it.
Introduced in [3373].
Attachments (4)
Change History (14)
#2
@
10 years ago
Can we confirm (perhaps with a unit test) that an empty option gets updated to a populated option when a structure is set and rules are flushed?
#6
@
9 years ago
- Keywords needs-refresh removed
- Milestone changed from Awaiting Review to 4.5
29107.2.diff is an updated patch that applies cleanly against trunk.
In what ways does this affect #11384?
#8
@
9 years ago
- Owner set to swissspidy
- Resolution set to fixed
- Status changed from new to closed
In 36254:
#10
@
5 years ago
update_home_siteurl()
and site-info.php
both continue to call delete_option( 'rewrite_rules' )
.
Is it possible to confirm whether those usages may cause this issue to reappear?
Also, delete_option( 'rewrite_rules' )
has been used for a very long time as the way for plugins to easily (and maybe poorly) queue up a rewrite rule flush on the subsequent page load. A quick search on GitHub shows over 47,000 usages across all repositories of people using it, mostly for this reason.
Is that enough in the wild for core to provide a helper function (like queue_rewrite_rule_updates()
or something) that everyone can change to using instead of incorrectly deleting the option and causing this extra query to reappear?
Or... instead of caring if the option is empty vs. missing, is there a different approach core can take to tuck this concern under the rug, and internally add rewrite_rules
to the notoptions
array before it's queried independently, or something less sinister?
Related: #11384, #27276.