-
Notifications
You must be signed in to change notification settings - Fork 877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure that the rewrite rules don't get flushed on every option update #17363
base: trunk
Are you sure you want to change the base?
Conversation
CR: 🚧 We already have a dedicated watcher for the This watcher is doing very similar checks as the ones that you added in the Regarding the changelog entry: why is it non-user-facing when it fixes a bug? In any case, adding the label to the PR is enough, and we should not also add it between brackets ( |
I just want to report that I've seen this race condition in action. To track it down, I set up a mu-plugin to log PHP backtraces whenever rewrite rules were deleted or updated. Every 1-2 months on a particular customer account, their site 404s everywhere due to rewrite rules being permanently corrupted until a new rewrite_flush was executed. Every time this has occurred, I could see in the backtrace that Until this PR can be merged, I've developed a solution using a small mu-plugin: <?php
/*
For each of its internal options, Yoast hooks into the "update_option_{$option_name}"
action to clear the rewrite rules when their options are updated. The problem is that
their WPSEO_Utils::clear_rewrites() logic is using "delete_option('rewrite_rules')"
which can cause race conditions to occur.
Yoast has a PR to address this bug, but as of 2020-11-04 the PR is not yet merged:
https://github.com/Yoast/wordpress-seo/pull/17363
In the meantime, this plugin will surgically replace Yoast's hooks with new ones
that use the safer "flush_rewrite_rules".
*/
add_action(
'wpseo_loaded',
function() {
if ( ! property_exists( 'WPSEO_Options', 'options' ) ) {
return;
}
foreach( array_filter( array_keys( (array) WPSEO_Options::$options ) ) as $option_name ) {
add_action(
'update_option_' . $option_name,
function() {
remove_filter( current_filter(), [ 'WPSEO_Utils', 'clear_rewrites' ], 10 );
add_filter( current_filter(), 'flush_rewrite_rules', 10 );
},
0,
0
);
}
}
); |
@Djennez Is this still relevant or can it be closed? :) |
@IreneStr it is still relevant as far as I'm aware (I still see the support requests regarding 404s when our plugin updates). However, I don't recall it being fully finished. And when I was working on this, there were talks of reworking the options framework which would likely make these changes obsolete. If that rework is not planned in the foreseeable future, I think it will be a good move to continue this PRs integration to see if it has the expected outcome. If it does, this could potentially fix a very big annoyance for sites that run into 404s on every one of our plugin updates. |
Context
wpseo<option_group>
update. This PR aims to only flush the rewrite rules when thestripcategorybase
option gets updated and only via the WP coreflush_rewrites
function (which has its own safety in place).Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
stripcategorybase
option.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
DELETE FROM 'wp_options' WHERE 'option_name' = 'rewrite_rules'
would be performed.flush_rewrite_rules
should be performed on shutdown.Test instructions for QA when the code is in the RC
QA can test this PR by following these steps:
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
Documentation
Quality assurance
Fixes #