diff --git a/features/option.feature b/features/option.feature index 212f82d4d..d2f52a9bf 100644 --- a/features/option.feature +++ b/features/option.feature @@ -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 diff --git a/src/Option_Command.php b/src/Option_Command.php index e4cd076f2..1d4af6d30 100644 --- a/src/Option_Command.php +++ b/src/Option_Command.php @@ -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 ] ); // @phpstan-ignore argument.type } elseif ( update_option( $key, $value, $autoload ) ) { WP_CLI::success( "Updated '{$key}' option." );