Skip to content

Conversation

danielbachhuber
Copy link
Member

Adds wp option get-autoload and wp option set-autoload commands:

$ wp option add foo bar
Success: Added 'foo' option.
$ wp option get-autoload foo
yes
$ wp option set-autoload foo no
Success: Updated autoload value for 'foo' option.
$ wp option set-autoload foo no
Success: Autoload value passed for 'foo' option is unchanged.

These are useful for manipulating the autoload value. wp option update can't be used for this directly because update_option() won't change autoload if the value doesn't change.

Recreates the cache manipulation inside of update_option() too: https://github.com/WordPress/wordpress-develop/blob/04e8bb4bb5ed37dade1b1ddda634e45f7503820d/src/wp-includes/option.php#L525-L540

This feels brittle, but not sure there's a better way around it...

@danielbachhuber danielbachhuber requested a review from a team as a code owner November 1, 2022 22:50
@danielbachhuber danielbachhuber self-assigned this Nov 1, 2022
@danielbachhuber danielbachhuber added this to the 2.4.0 milestone Nov 1, 2022
Comment on lines +479 to +480
* - 'yes'
* - 'no'
Copy link
Member

Choose a reason for hiding this comment

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

This means the API is:

wp option set-autoload my_option no

That seems to be forced by the DB value and is neither developer-speak (set autoload true) nor natural language (disable autoload).

I'm don't love that API, but I have trouble coming up with something better.

What do think about:

wp option autoload get my_option
wp option autoload enable my_option
wp option autoload disable my_option

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm don't love that API, but I have trouble coming up with something better.

What do think about:

@schlessera Good points. I don't love your proposed approach either because it seems unnecessarily complex to nest the commands further.

I went with wp option set-autoload my_option no because wp option add accepts --autoload=yes/--autoload=no.

@danielbachhuber danielbachhuber merged commit 1bd9e2e into master Nov 15, 2022
@danielbachhuber danielbachhuber deleted the add/option-autoload-commands branch November 15, 2022 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants