Skip to content

Conversation

anomiex
Copy link

@anomiex anomiex commented Jul 23, 2024

On a non-multisite, get_network_option(), add_network_option(), and update_network_option() don't bother updating the network notoptions cache, instead reling on get_option(), add_option(), and update_option() to use the non-network notoptions.

delete_options() and delete_network_options() were recently updated to populate the notoptions caches. But, contrary to existing practice, delete_network_options() was made to update the network notoptions cache even on non-multisites.

This moves the updating of the network notoptions cache in delete_network_options() to the multisite code path, matching the behavior of the other functions, and adds a test to verify this.

Trac ticket: https://core.trac.wordpress.org/ticket/61730


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…isites

On a non-multisite, `get_network_option()`, `add_network_option()`, and
`update_network_option()` don't bother updating the network `notoptions`
cache, instead reling on `get_option()`, `add_option()`, and
`update_option()` to use the non-network `notoptions`.

`delete_options()` and `delete_network_options()` were recently updated
to populate the `notoptions` caches. But, contrary to existing practice,
`delete_network_options()` was made to update the network `notoptions`
cache even on non-multisites.

This moves the updating of the network `notoptions` cache in
`delete_network_options()` to the multisite code path, matching the
behavior of the other functions, and adds a test to verify this.

Trac ticket: https://core.trac.wordpress.org/ticket/61730
Copy link

github-actions bot commented Jul 23, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props bjorsch, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@anomiex
Copy link
Author

anomiex commented Jul 23, 2024

An alternative fix would be to update the other functions to all populate the network notoptions cache, but this seemed more straightforward.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thank you!

I created #7079 to:

  • ensure the new test added here failed without the fix
  • add some additional tests
  • push the code change to ensure the tests started passing

It all worked as expected so I have taken the liberty of pushing 3ec1a4d to this branch with the additional tests. This will allow us to work from a single PR.

@pbearne are you able to take a look at the updated code?

@peterwilsoncc peterwilsoncc requested a review from costdev July 24, 2024 00:19
)
);

if ( $result ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, on second thoughts I am wondering if this should be

Suggested change
if ( $result ) {
if ( false !== $result ) {

If $wpdb::delete() returns 0, it means that the query ran successfully but there was no option to delete. The result is the same, it's a known notoption.

If $wpdb::delete() returns false, then the query failed so it's not known whether or not the option doesn't exist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a problem with the code here, there's the same problem already in trunk: the notoptions-setting code on lines 2296–2303 is guarded by an if ( $result ) on line 2269.

delete_option() then has the opposite problem, it sets notoptions even if $result === false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete_option() then has the opposite problem, it sets notoptions even if $result === false.

Good catch. I'll open the original ticket to note that it needs a little work to account for a database failure.

Are you happy to add some protections here or would you prefer me to do it on a separate PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer you fix these issues in a separate PR.

@peterwilsoncc
Copy link
Contributor

Merged r58811 / b38541d

Thanks for catching this, Brad, it's much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants