Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions features/option.feature
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,113 @@ Feature: Manage WordPress options
| option_name | option_value | autoload |
| hello | island | on |

@require-wp-4.2
@less-than-wp-6.6
Scenario: Update autoload value for custom option with an unchanged value
Given a WP install
And I run `wp option add hello world --autoload=yes`

When I run `wp option update hello world --autoload=no`
Then STDOUT should be:
"""
Success: Updated autoload value for 'hello' option.
"""

When I run `wp option get-autoload hello`
Then STDOUT should be:
"""
no
"""

When I run `wp option update hello world --autoload=yes`
Then STDOUT should be:
"""
Success: Updated autoload value for 'hello' option.
"""

When I run `wp option get-autoload hello`
Then STDOUT should be:
"""
yes
"""

When I run `wp option update hello world --autoload=off`
Then STDOUT should be:
"""
Success: Updated autoload value for 'hello' option.
"""

When I run `wp option get-autoload hello`
Then STDOUT should be:
"""
no
"""

When I run `wp option update hello world --autoload=on`
Then STDOUT should be:
"""
Success: Updated autoload value for 'hello' option.
"""

When I run `wp option get-autoload hello`
Then STDOUT should be:
"""
yes
"""

@require-wp-6.6
Scenario: Update autoload value for custom option with an unchanged value
Given a WP install
And I run `wp option add hello world --autoload=on`

When I run `wp option update hello world --autoload=off`
Then STDOUT should be:
"""
Success: Updated autoload value for 'hello' option.
"""

When I run `wp option get-autoload hello`
Then STDOUT should be:
"""
off
"""

When I run `wp option update hello world --autoload=on`
Then STDOUT should be:
"""
Success: Updated autoload value for 'hello' option.
"""

When I run `wp option get-autoload hello`
Then STDOUT should be:
"""
on
"""

When I run `wp option update hello world --autoload=no`
Then STDOUT should be:
"""
Success: Updated autoload value for 'hello' option.
"""

When I run `wp option get-autoload hello`
Then STDOUT should be:
"""
off
"""

When I run `wp option update hello world --autoload=yes`
Then STDOUT should be:
"""
Success: Updated autoload value for 'hello' option.
"""

When I run `wp option get-autoload hello`
Then STDOUT should be:
"""
on
"""

@require-wp-4.2
@less-than-wp-6.6
Scenario: Managed autoloaded options
Expand Down
9 changes: 9 additions & 0 deletions src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ public function update( $args, $assoc_args ) {

if ( $value === $old_value && null === $autoload ) {
WP_CLI::success( "Value passed for '{$key}' option is unchanged." );
} elseif ( $value === $old_value ) {
// Store the value update_option() would: WordPress before 6.6 only autoloads 'yes'.
$autoload_on = in_array( $autoload, [ 'on', 'yes' ], true );
if ( Utils\wp_version_compare( '6.6', '<' ) ) {
$autoload = $autoload_on ? 'yes' : 'no';
} else {
$autoload = $autoload_on ? 'on' : 'off';
}
$this->set_autoload( [ $key, $autoload ] );
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
// @phpstan-ignore argument.type
} elseif ( update_option( $key, $value, $autoload ) ) {
WP_CLI::success( "Updated '{$key}' option." );
Expand Down
Loading