Repository navigation
Keep the alloptions cache in sync in wp option set-autoload - #688
rahultank-spaceo wants to merge 1 commit into
Conversation
The command refreshed the caches like a value change in update_option(), so the option stayed in, or out of, the cached alloptions after its autoload value changed. Refresh the cache like wp_set_option_autoload_values() instead. Fixes wp-cli#687.
|
Hello! 👋 Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project. Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation. Here are some useful Composer commands to get you started:
To run a single Behat test, you can use the following command: # Run all tests in a single file
composer behat features/some-feature.feature
# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123You can find a list of all available Behat steps in our handbook. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Fixes #687.
wp option set-autoloadrefreshed the caches the wayupdate_option()does for a value change. So after the autoload value changed, the option stayed in, or out of, the cachedalloptions. With a persistent object cache, an option set tooffkept loading on every request, and a laterdelete_option()left its old value behind.The command now refreshes the cache the same way core's
wp_set_option_autoload_values()does:onoryes: it deletes the option's own cache andalloptions, soalloptionsis rebuilt on the next load;offorno: it removes the option from the cachedalloptions.I kept the command's own query instead of calling
wp_set_option_autoload(). That way there is no version check or fallback for WordPress before 6.4 (see the comment on the issue), andyes/noare still stored as given, as the existing scenarios expect. Core would storeon/off.Testing
The new scenario reproduces the bug without a persistent object cache. It runs the command in the same process with
WP_CLI::runcommand( ..., array( 'launch' => false ) ), so the in-memory cache keepsalloptionsbetween the two calls. With SQLite and WordPress 7.1.4,features/option-set-autoload.featurepasses on this branch (4 scenarios). With the oldsrc/Option_Command.php, the new scenario fails: the firstvar_dump()printsbool(true). PHPCS and the linter pass on the change.I also ran the old and new
set_autoload()code on WordPress 7.2-beta4, in one request, with the option cached first:on→offalloptionsoff→onalloptionsyes→noalloptionsno→yesalloptionsdelete_option()afteroffget_option()returns the old valueAI assistance: Yes. An AI assistant helped write the change and this description. I reviewed the code and the test results.
Summary by CodeRabbit