From 1caa9860cd964b90b5742d714f56993795277179 Mon Sep 17 00:00:00 2001 From: Dhrupo Date: Fri, 6 Nov 2026 18:00:28 +0600 Subject: [PATCH 1/2] Update autoload in `wp option update` when the value is unchanged --- features/option.feature | 59 +++++++++++++++++++++++++++++++++++++++++ src/Option_Command.php | 2 ++ 2 files changed, 61 insertions(+) diff --git a/features/option.feature b/features/option.feature index 212f82d4d..298df596b 100644 --- a/features/option.feature +++ b/features/option.feature @@ -180,6 +180,65 @@ 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 + """ + + @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 + """ + @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..037733a03 100644 --- a/src/Option_Command.php +++ b/src/Option_Command.php @@ -454,6 +454,8 @@ 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 ) { + $this->set_autoload( [ $key, $autoload ] ); // @phpstan-ignore argument.type } elseif ( update_option( $key, $value, $autoload ) ) { WP_CLI::success( "Updated '{$key}' option." ); From a744b952b1a6b4bfd42fd18ab3e1510ae720a18d Mon Sep 17 00:00:00 2001 From: Dhrupo Date: Fri, 6 Nov 2026 20:14:39 +0600 Subject: [PATCH 2/2] Store the autoload value update_option() would use on each WordPress version --- features/option.feature | 48 +++++++++++++++++++++++++++++++++++++++++ src/Option_Command.php | 7 ++++++ 2 files changed, 55 insertions(+) diff --git a/features/option.feature b/features/option.feature index 298df596b..d2f52a9bf 100644 --- a/features/option.feature +++ b/features/option.feature @@ -210,6 +210,30 @@ Feature: Manage WordPress options 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 @@ -239,6 +263,30 @@ Feature: Manage WordPress options 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 037733a03..1d4af6d30 100644 --- a/src/Option_Command.php +++ b/src/Option_Command.php @@ -455,6 +455,13 @@ 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 ) ) {