From 14fc9be1e987bd3b35a9533bf4c0be0db6aadd95 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:28:03 +0000 Subject: [PATCH 01/10] Initial plan From 5a4ad4e0cc7d30c5c0fa8bd7e6079f151f1c49b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:34:38 +0000 Subject: [PATCH 02/10] Add auto_update_indicated field and --auto-update-indicated flag Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Plugin_Command.php | 44 ++++++++++++++++++++++++++++--- src/WP_CLI/CommandWithUpgrade.php | 6 +++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index c257debbc..110c89f1d 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -67,6 +67,7 @@ class Plugin_Command extends CommandWithUpgrade { 'version', 'update_version', 'auto_update', + 'auto_update_indicated', ); public function __construct() { @@ -707,6 +708,9 @@ protected function install_from_repo( $slug, $assoc_args ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * + * [--auto-update-indicated] + * : Only update plugins where the server response indicates an automatic update. Updates to the version indicated by the server, not necessarily the latest version. + * * ## EXAMPLES * * $ wp plugin update bbpress --version=dev @@ -756,7 +760,39 @@ protected function install_from_repo( $slug, $assoc_args ) { * @alias upgrade */ public function update( $args, $assoc_args ) { - $all = Utils\get_flag_value( $assoc_args, 'all', false ); + $all = Utils\get_flag_value( $assoc_args, 'all', false ); + $auto_update_indicated = Utils\get_flag_value( $assoc_args, 'auto-update-indicated', false ); + + // If --auto-update-indicated is set, we need to filter plugins by this flag. + if ( $auto_update_indicated ) { + // Get all plugins with their update info. + $items = $this->get_item_list(); + + // Filter to only include plugins where auto_update_indicated is true. + $auto_update_plugins = array_filter( + $items, + function ( $item ) { + return ! empty( $item['auto_update_indicated'] ); + } + ); + + // Get the plugin names to update. + $args = array_values( wp_list_pluck( $auto_update_plugins, 'name' ) ); + + if ( empty( $args ) ) { + WP_CLI::success( 'No plugins with server-indicated automatic updates available.' ); + return; + } + + // Don't allow --version to be set with --auto-update-indicated, as the version comes from the server. + if ( isset( $assoc_args['version'] ) ) { + WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); + } + + // Process the updates. + parent::update_many( $args, $assoc_args ); + return; + } $args = $this->check_optional_args_and_all( $args, $all ); if ( ! $args ) { @@ -806,8 +842,9 @@ protected function get_item_list() { $duplicate_names[ $name ] = array(); } - $requires = isset( $update_info ) && isset( $update_info['requires'] ) ? $update_info['requires'] : null; - $requires_php = isset( $update_info ) && isset( $update_info['requires_php'] ) ? $update_info['requires_php'] : null; + $requires = isset( $update_info ) && isset( $update_info['requires'] ) ? $update_info['requires'] : null; + $requires_php = isset( $update_info ) && isset( $update_info['requires_php'] ) ? $update_info['requires_php'] : null; + $auto_update_indicated = isset( $update_info ) && isset( $update_info['autoupdate'] ) ? (bool) $update_info['autoupdate'] : false; // If an update has requires_php set, check to see if the local version of PHP meets that requirement // The plugins update API already filters out plugins that don't meet WordPress requirements, but does not @@ -849,6 +886,7 @@ protected function get_item_list() { 'description' => wordwrap( $details['Description'] ), 'file' => $file, 'auto_update' => in_array( $file, $auto_updates, true ), + 'auto_update_indicated' => $auto_update_indicated, 'author' => $details['Author'], 'tested_up_to' => '', 'requires' => $requires, diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 52f9f5bf5..edc433166 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -642,6 +642,12 @@ function ( $value ) { } elseif ( false === $value ) { $value = 'off'; } + } elseif ( 'auto_update_indicated' === $field ) { + if ( true === $value ) { + $value = 'yes'; + } elseif ( false === $value ) { + $value = 'no'; + } } } From 4e3d71bf2668ad33a5215430c3b5426c282d04d4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:35:34 +0000 Subject: [PATCH 03/10] Add Behat tests for auto-update-indicated feature Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/plugin-update.feature | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/features/plugin-update.feature b/features/plugin-update.feature index a028b8df3..e5830c079 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -267,3 +267,52 @@ Feature: Update WordPress plugins """ Success: Updated 1 of 1 plugins (1 skipped). """ + + @require-wp-5.2 + Scenario: Show auto_update_indicated field in plugin list + Given a WP install + + When I run `wp plugin install wordpress-importer --version=0.5 --force` + Then STDOUT should not be empty + + When I run `wp plugin list --fields=name,version,update,auto_update_indicated` + Then STDOUT should be a table containing rows: + | name | version | update | auto_update_indicated | + | wordpress-importer | 0.5 | available | no | + + @require-wp-5.2 + Scenario: Using --auto-update-indicated flag when no plugins have auto-update indicated + Given a WP install + + When I run `wp plugin install wordpress-importer --version=0.5 --force` + Then STDOUT should not be empty + + When I run `wp plugin update --auto-update-indicated` + Then STDOUT should be: + """ + Success: No plugins with server-indicated automatic updates available. + """ + + @require-wp-5.2 + Scenario: Error when using --version with --auto-update-indicated + Given a WP install + + When I try `wp plugin update --auto-update-indicated --version=1.0.0` + Then STDERR should be: + """ + Error: Cannot use --version with --auto-update-indicated. The version is determined by the server. + """ + And the return code should be 1 + + @require-wp-5.2 + Scenario: Preview updates with --auto-update-indicated and --dry-run + Given a WP install + + When I run `wp plugin install wordpress-importer --version=0.5 --force` + Then STDOUT should not be empty + + When I run `wp plugin update --auto-update-indicated --dry-run` + Then STDOUT should be: + """ + Success: No plugins with server-indicated automatic updates available. + """ From d1e15003ab669eb7c32936f503634b67961d0ac5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:36:51 +0000 Subject: [PATCH 04/10] Address code review feedback: move validation earlier and add test comments Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/plugin-update.feature | 6 ++++++ src/Plugin_Command.php | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/features/plugin-update.feature b/features/plugin-update.feature index e5830c079..3643a4dd7 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -268,6 +268,12 @@ Feature: Update WordPress plugins Success: Updated 1 of 1 plugins (1 skipped). """ + # Tests for --auto-update-indicated feature + # Note: These tests verify the flag handling and error cases. + # The actual update behavior when autoupdate is true from the server + # cannot be easily tested as it requires mocking WordPress.org API responses. + # The update functionality itself is handled by the existing update_many method. + @require-wp-5.2 Scenario: Show auto_update_indicated field in plugin list Given a WP install diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 110c89f1d..97c2f9a26 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -763,6 +763,11 @@ public function update( $args, $assoc_args ) { $all = Utils\get_flag_value( $assoc_args, 'all', false ); $auto_update_indicated = Utils\get_flag_value( $assoc_args, 'auto-update-indicated', false ); + // Don't allow --version to be set with --auto-update-indicated, as the version comes from the server. + if ( $auto_update_indicated && isset( $assoc_args['version'] ) ) { + WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); + } + // If --auto-update-indicated is set, we need to filter plugins by this flag. if ( $auto_update_indicated ) { // Get all plugins with their update info. @@ -784,11 +789,6 @@ function ( $item ) { return; } - // Don't allow --version to be set with --auto-update-indicated, as the version comes from the server. - if ( isset( $assoc_args['version'] ) ) { - WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); - } - // Process the updates. parent::update_many( $args, $assoc_args ); return; From 5ad764d6e6c55726b4f06a41a033d25a19744a2a Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 4 Feb 2026 14:24:37 -0500 Subject: [PATCH 05/10] Update src/Plugin_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Plugin_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 97c2f9a26..dd1e39bae 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -709,7 +709,7 @@ protected function install_from_repo( $slug, $assoc_args ) { * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * * [--auto-update-indicated] - * : Only update plugins where the server response indicates an automatic update. Updates to the version indicated by the server, not necessarily the latest version. + * : Only update plugins where the server response indicates an automatic update. Updates to the version indicated by the server, not necessarily the latest version. Cannot be used with `--version`, `--minor`, or `--patch`. * * ## EXAMPLES * From 27ab4e604abefcb9ade76b4423529a2f9de7a5b4 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 4 Feb 2026 14:24:46 -0500 Subject: [PATCH 06/10] Update src/Plugin_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Plugin_Command.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index dd1e39bae..ef83a6942 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -768,6 +768,10 @@ public function update( $args, $assoc_args ) { WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); } + // Don't allow --minor or --patch to be set with --auto-update-indicated, as the version comes from the server. + if ( $auto_update_indicated && ( isset( $assoc_args['minor'] ) || isset( $assoc_args['patch'] ) ) ) { + WP_CLI::error( 'Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.' ); + } // If --auto-update-indicated is set, we need to filter plugins by this flag. if ( $auto_update_indicated ) { // Get all plugins with their update info. From 7db7e24c8cd9a62b7b88eedc5756471430902625 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 19:27:38 +0000 Subject: [PATCH 07/10] Add validation for plugin names and tests for --minor/--patch incompatibility Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/plugin-update.feature | 33 +++++++++++++++++++++++++++++++++ src/Plugin_Command.php | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/features/plugin-update.feature b/features/plugin-update.feature index 3643a4dd7..43db92bc7 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -310,6 +310,39 @@ Feature: Update WordPress plugins """ And the return code should be 1 + @require-wp-5.2 + Scenario: Error when using --minor with --auto-update-indicated + Given a WP install + + When I try `wp plugin update --auto-update-indicated --minor` + Then STDERR should be: + """ + Error: Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server. + """ + And the return code should be 1 + + @require-wp-5.2 + Scenario: Error when using --patch with --auto-update-indicated + Given a WP install + + When I try `wp plugin update --auto-update-indicated --patch` + Then STDERR should be: + """ + Error: Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server. + """ + And the return code should be 1 + + @require-wp-5.2 + Scenario: Error when specifying plugin names with --auto-update-indicated + Given a WP install + + When I try `wp plugin update akismet --auto-update-indicated` + Then STDERR should be: + """ + Error: Cannot specify plugin names with --auto-update-indicated. This flag updates all plugins with server-indicated automatic updates. + """ + And the return code should be 1 + @require-wp-5.2 Scenario: Preview updates with --auto-update-indicated and --dry-run Given a WP install diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index ef83a6942..b9c4a5a3a 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -772,6 +772,12 @@ public function update( $args, $assoc_args ) { if ( $auto_update_indicated && ( isset( $assoc_args['minor'] ) || isset( $assoc_args['patch'] ) ) ) { WP_CLI::error( 'Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.' ); } + + // Don't allow plugin names to be specified with --auto-update-indicated. + if ( $auto_update_indicated && ! empty( $args ) ) { + WP_CLI::error( 'Cannot specify plugin names with --auto-update-indicated. This flag updates all plugins with server-indicated automatic updates.' ); + } + // If --auto-update-indicated is set, we need to filter plugins by this flag. if ( $auto_update_indicated ) { // Get all plugins with their update info. From 0e8a856f81173907d27ad58f9e8cb5c74fce7cb2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Feb 2026 21:32:06 +0000 Subject: [PATCH 08/10] Add auto-update-indicated support for themes Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/theme-update.feature | 81 ++++++++++++++++++++++++++++++ src/Theme_Command.php | 48 +++++++++++++++++- src/WP_CLI/ParseThemeNameInput.php | 6 ++- 3 files changed, 132 insertions(+), 3 deletions(-) diff --git a/features/theme-update.feature b/features/theme-update.feature index 4179b6a6a..08b5b2a1d 100644 --- a/features/theme-update.feature +++ b/features/theme-update.feature @@ -154,3 +154,84 @@ Feature: Update WordPress themes """ 1.1.1 """ + + # Tests for --auto-update-indicated feature + # Note: These tests verify the flag handling and error cases. + # The actual update behavior when autoupdate is true from the server + # cannot be easily tested as it requires mocking WordPress.org API responses. + # The update functionality itself is handled by the existing update_many method. + + Scenario: Show auto_update_indicated field in theme list + Given a WP install + + When I run `wp theme install twentytwelve --version=3.0 --force` + Then STDOUT should not be empty + + When I run `wp theme list --fields=name,version,update,auto_update_indicated` + Then STDOUT should be a table containing rows: + | name | version | update | auto_update_indicated | + | twentytwelve | 3.0 | available | no | + + Scenario: Using --auto-update-indicated flag when no themes have auto-update indicated + Given a WP install + + When I run `wp theme install twentytwelve --version=3.0 --force` + Then STDOUT should not be empty + + When I run `wp theme update --auto-update-indicated` + Then STDOUT should be: + """ + Success: No themes with server-indicated automatic updates available. + """ + + Scenario: Error when using --version with --auto-update-indicated + Given a WP install + + When I try `wp theme update --auto-update-indicated --version=1.0.0` + Then STDERR should be: + """ + Error: Cannot use --version with --auto-update-indicated. The version is determined by the server. + """ + And the return code should be 1 + + Scenario: Error when using --minor with --auto-update-indicated + Given a WP install + + When I try `wp theme update --auto-update-indicated --minor` + Then STDERR should be: + """ + Error: Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server. + """ + And the return code should be 1 + + Scenario: Error when using --patch with --auto-update-indicated + Given a WP install + + When I try `wp theme update --auto-update-indicated --patch` + Then STDERR should be: + """ + Error: Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server. + """ + And the return code should be 1 + + Scenario: Error when specifying theme names with --auto-update-indicated + Given a WP install + + When I try `wp theme update twentytwelve --auto-update-indicated` + Then STDERR should be: + """ + Error: Cannot specify theme names with --auto-update-indicated. This flag updates all themes with server-indicated automatic updates. + """ + And the return code should be 1 + + Scenario: Preview updates with --auto-update-indicated and --dry-run + Given a WP install + + When I run `wp theme install twentytwelve --version=3.0 --force` + Then STDOUT should not be empty + + When I run `wp theme update --auto-update-indicated --dry-run` + Then STDOUT should be: + """ + Success: No themes with server-indicated automatic updates available. + """ diff --git a/src/Theme_Command.php b/src/Theme_Command.php index e18b17e89..dda2f8c86 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -63,6 +63,7 @@ class Theme_Command extends CommandWithUpgrade { 'version', 'update_version', 'auto_update', + 'auto_update_indicated', 'type', ]; @@ -691,6 +692,9 @@ public function get( $args, $assoc_args ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * + * [--auto-update-indicated] + * : Only update themes where the server response indicates an automatic update. Updates to the version indicated by the server, not necessarily the latest version. Cannot be used with `--version`, `--minor`, or `--patch`. + * * ## EXAMPLES * * # Update multiple themes @@ -739,7 +743,49 @@ public function get( $args, $assoc_args ) { * @alias upgrade */ public function update( $args, $assoc_args ) { - $all = Utils\get_flag_value( $assoc_args, 'all', false ); + $all = Utils\get_flag_value( $assoc_args, 'all', false ); + $auto_update_indicated = Utils\get_flag_value( $assoc_args, 'auto-update-indicated', false ); + + // Don't allow --version to be set with --auto-update-indicated, as the version comes from the server. + if ( $auto_update_indicated && isset( $assoc_args['version'] ) ) { + WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); + } + + // Don't allow --minor or --patch to be set with --auto-update-indicated, as the version comes from the server. + if ( $auto_update_indicated && ( isset( $assoc_args['minor'] ) || isset( $assoc_args['patch'] ) ) ) { + WP_CLI::error( 'Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.' ); + } + + // Don't allow theme names to be specified with --auto-update-indicated. + if ( $auto_update_indicated && ! empty( $args ) ) { + WP_CLI::error( 'Cannot specify theme names with --auto-update-indicated. This flag updates all themes with server-indicated automatic updates.' ); + } + + // If --auto-update-indicated is set, we need to filter themes by this flag. + if ( $auto_update_indicated ) { + // Get all themes with their update info. + $items = $this->get_item_list(); + + // Filter to only include themes where auto_update_indicated is true. + $auto_update_themes = array_filter( + $items, + function ( $item ) { + return ! empty( $item['auto_update_indicated'] ); + } + ); + + // Get the theme names to update. + $args = array_values( wp_list_pluck( $auto_update_themes, 'name' ) ); + + if ( empty( $args ) ) { + WP_CLI::success( 'No themes with server-indicated automatic updates available.' ); + return; + } + + // Process the updates. + parent::update_many( $args, $assoc_args ); + return; + } $args = $this->check_optional_args_and_all( $args, $all ); if ( ! $args ) { diff --git a/src/WP_CLI/ParseThemeNameInput.php b/src/WP_CLI/ParseThemeNameInput.php index 5a4def568..0786c4cb1 100644 --- a/src/WP_CLI/ParseThemeNameInput.php +++ b/src/WP_CLI/ParseThemeNameInput.php @@ -90,8 +90,9 @@ private function get_all_themes() { } foreach ( wp_get_themes( [ 'errors' => null ] ) as $key => $theme ) { - $stylesheet = $theme->get_stylesheet(); - $update_info = ( isset( $all_update_info->response[ $stylesheet ] ) && null !== $all_update_info->response[ $theme->get_stylesheet() ] ) ? (array) $all_update_info->response[ $theme->get_stylesheet() ] : null; + $stylesheet = $theme->get_stylesheet(); + $update_info = ( isset( $all_update_info->response[ $stylesheet ] ) && null !== $all_update_info->response[ $theme->get_stylesheet() ] ) ? (array) $all_update_info->response[ $theme->get_stylesheet() ] : null; + $auto_update_indicated = isset( $update_info ) && isset( $update_info['autoupdate'] ) ? (bool) $update_info['autoupdate'] : false; // Unlike plugin update responses, the wordpress.org API does not seem to check and filter themes that don't meet // WordPress version requirements into a separate no_updates array @@ -149,6 +150,7 @@ private function get_all_themes() { 'description' => wordwrap( $theme->get( 'Description' ) ), 'author' => $theme->get( 'Author' ), 'auto_update' => in_array( $stylesheet, $auto_updates, true ), + 'auto_update_indicated' => $auto_update_indicated, 'requires' => $requires, 'requires_php' => $requires_php, 'update_unavailable_reason' => isset( $update_unavailable_reason ) ? $update_unavailable_reason : '', From 563e34aba98551e563040f8decf9cdc1df1a6c09 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 17 Feb 2026 14:22:11 +0100 Subject: [PATCH 09/10] Don't include field by default --- src/Plugin_Command.php | 2 +- src/Theme_Command.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 0d7ba73ee..45d90c75a 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -67,7 +67,6 @@ class Plugin_Command extends CommandWithUpgrade { 'version', 'update_version', 'auto_update', - 'auto_update_indicated', ); public function __construct() { @@ -1837,6 +1836,7 @@ public function delete( $args, $assoc_args ) { * * requires_php * * wporg_status * * wporg_last_updated + * * auto_update_indicated * * ## EXAMPLES * diff --git a/src/Theme_Command.php b/src/Theme_Command.php index dda2f8c86..d246cc233 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -63,7 +63,6 @@ class Theme_Command extends CommandWithUpgrade { 'version', 'update_version', 'auto_update', - 'auto_update_indicated', 'type', ]; @@ -991,6 +990,7 @@ public function delete( $args, $assoc_args ) { * * update_id * * title * * description + * * auto_update_indicated * * ## EXAMPLES * From 31bbe0b4914c685f67439016ba0a561faabffdd6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 14:21:58 +0000 Subject: [PATCH 10/10] Refactor auto-update-indicated logic into shared method in CommandWithUpgrade Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Plugin_Command.php | 43 ++---------------------- src/Theme_Command.php | 43 ++---------------------- src/WP_CLI/CommandWithUpgrade.php | 56 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 80 deletions(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index abc89a93e..7930bfdde 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -778,47 +778,10 @@ protected function install_from_repo( $slug, $assoc_args ) { * @alias upgrade */ public function update( $args, $assoc_args ) { - $all = Utils\get_flag_value( $assoc_args, 'all', false ); - $auto_update_indicated = Utils\get_flag_value( $assoc_args, 'auto-update-indicated', false ); + $all = Utils\get_flag_value( $assoc_args, 'all', false ); - // Don't allow --version to be set with --auto-update-indicated, as the version comes from the server. - if ( $auto_update_indicated && isset( $assoc_args['version'] ) ) { - WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); - } - - // Don't allow --minor or --patch to be set with --auto-update-indicated, as the version comes from the server. - if ( $auto_update_indicated && ( isset( $assoc_args['minor'] ) || isset( $assoc_args['patch'] ) ) ) { - WP_CLI::error( 'Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.' ); - } - - // Don't allow plugin names to be specified with --auto-update-indicated. - if ( $auto_update_indicated && ! empty( $args ) ) { - WP_CLI::error( 'Cannot specify plugin names with --auto-update-indicated. This flag updates all plugins with server-indicated automatic updates.' ); - } - - // If --auto-update-indicated is set, we need to filter plugins by this flag. - if ( $auto_update_indicated ) { - // Get all plugins with their update info. - $items = $this->get_item_list(); - - // Filter to only include plugins where auto_update_indicated is true. - $auto_update_plugins = array_filter( - $items, - function ( $item ) { - return ! empty( $item['auto_update_indicated'] ); - } - ); - - // Get the plugin names to update. - $args = array_values( wp_list_pluck( $auto_update_plugins, 'name' ) ); - - if ( empty( $args ) ) { - WP_CLI::success( 'No plugins with server-indicated automatic updates available.' ); - return; - } - - // Process the updates. - parent::update_many( $args, $assoc_args ); + // Handle --auto-update-indicated flag if present. + if ( $this->handle_auto_update_indicated( $args, $assoc_args ) ) { return; } diff --git a/src/Theme_Command.php b/src/Theme_Command.php index d246cc233..f276ec410 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -742,47 +742,10 @@ public function get( $args, $assoc_args ) { * @alias upgrade */ public function update( $args, $assoc_args ) { - $all = Utils\get_flag_value( $assoc_args, 'all', false ); - $auto_update_indicated = Utils\get_flag_value( $assoc_args, 'auto-update-indicated', false ); - - // Don't allow --version to be set with --auto-update-indicated, as the version comes from the server. - if ( $auto_update_indicated && isset( $assoc_args['version'] ) ) { - WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); - } - - // Don't allow --minor or --patch to be set with --auto-update-indicated, as the version comes from the server. - if ( $auto_update_indicated && ( isset( $assoc_args['minor'] ) || isset( $assoc_args['patch'] ) ) ) { - WP_CLI::error( 'Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.' ); - } - - // Don't allow theme names to be specified with --auto-update-indicated. - if ( $auto_update_indicated && ! empty( $args ) ) { - WP_CLI::error( 'Cannot specify theme names with --auto-update-indicated. This flag updates all themes with server-indicated automatic updates.' ); - } - - // If --auto-update-indicated is set, we need to filter themes by this flag. - if ( $auto_update_indicated ) { - // Get all themes with their update info. - $items = $this->get_item_list(); - - // Filter to only include themes where auto_update_indicated is true. - $auto_update_themes = array_filter( - $items, - function ( $item ) { - return ! empty( $item['auto_update_indicated'] ); - } - ); - - // Get the theme names to update. - $args = array_values( wp_list_pluck( $auto_update_themes, 'name' ) ); - - if ( empty( $args ) ) { - WP_CLI::success( 'No themes with server-indicated automatic updates available.' ); - return; - } + $all = Utils\get_flag_value( $assoc_args, 'all', false ); - // Process the updates. - parent::update_many( $args, $assoc_args ); + // Handle --auto-update-indicated flag if present. + if ( $this->handle_auto_update_indicated( $args, $assoc_args ) ) { return; } diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index cf1db3fe8..d1623c979 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -562,6 +562,62 @@ protected function get_upgrader( $assoc_args ) { return Utils\get_upgrader( $upgrader_class, $insecure, new ExtensionUpgraderSkin() ); } + /** + * Handles the --auto-update-indicated flag logic for both plugins and themes. + * + * This method validates flag combinations, filters items by auto_update_indicated, + * and processes updates if any items are found. + * + * @param array $args Positional arguments (item names). + * @param array $assoc_args Associative arguments (flags). + * @return bool Returns true if auto-update-indicated was handled, false otherwise. + */ + protected function handle_auto_update_indicated( $args, $assoc_args ) { + $auto_update_indicated = Utils\get_flag_value( $assoc_args, 'auto-update-indicated', false ); + + if ( ! $auto_update_indicated ) { + return false; + } + + // Don't allow --version to be set with --auto-update-indicated, as the version comes from the server. + if ( isset( $assoc_args['version'] ) ) { + WP_CLI::error( 'Cannot use --version with --auto-update-indicated. The version is determined by the server.' ); + } + + // Don't allow --minor or --patch to be set with --auto-update-indicated, as the version comes from the server. + if ( isset( $assoc_args['minor'] ) || isset( $assoc_args['patch'] ) ) { + WP_CLI::error( 'Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.' ); + } + + // Don't allow item names to be specified with --auto-update-indicated. + if ( ! empty( $args ) ) { + WP_CLI::error( "Cannot specify {$this->item_type} names with --auto-update-indicated. This flag updates all {$this->item_type}s with server-indicated automatic updates." ); + } + + // Get all items with their update info. + $items = $this->get_item_list(); + + // Filter to only include items where auto_update_indicated is true. + $auto_update_items = array_filter( + $items, + function ( $item ) { + return ! empty( $item['auto_update_indicated'] ); + } + ); + + // Get the item names to update. + $args = array_values( wp_list_pluck( $auto_update_items, 'name' ) ); + + if ( empty( $args ) ) { + WP_CLI::success( "No {$this->item_type}s with server-indicated automatic updates available." ); + return true; + } + + // Process the updates. + $this->update_many( $args, $assoc_args ); + return true; + } + protected function update_many( $args, $assoc_args ) { call_user_func( $this->upgrade_refresh );