Skip to content
Draft
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
88 changes: 88 additions & 0 deletions features/plugin-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,91 @@ 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

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: 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

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.
"""
Comment on lines 271 to 357
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The test coverage for the --auto-update-indicated flag is missing scenarios for incompatibility with --minor and --patch flags. Consider adding test scenarios similar to the existing "Error when using --version with --auto-update-indicated" test (line 303) for these flags:

Scenario: Error when using --minor with --auto-update-indicated
Scenario: Error when using --patch with --auto-update-indicated

This would ensure the validation logic is properly tested.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added test scenarios for --minor and --patch incompatibility in commit 7db7e24. The tests now cover:

  • Error when using --minor with --auto-update-indicated
  • Error when using --patch with --auto-update-indicated
  • Error when specifying plugin names with --auto-update-indicated

54 changes: 51 additions & 3 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Plugin_Command extends CommandWithUpgrade {
'version',
'update_version',
'auto_update',
'auto_update_indicated',
);

public function __construct() {
Expand Down Expand Up @@ -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. Cannot be used with `--version`, `--minor`, or `--patch`.
*
* ## EXAMPLES
*
* $ wp plugin update bbpress --version=dev
Expand Down Expand Up @@ -756,7 +760,49 @@ 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 );

// 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 );
return;
}
Comment on lines +782 to +805
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

When --auto-update-indicated is used, any plugin names passed in the command arguments are silently ignored. This could be confusing to users who might expect the flag to act as a filter on the specified plugins. Consider adding validation to error if both plugin names and --auto-update-indicated are specified, similar to how the codebase validates that either plugin names or --all must be provided (see check_optional_args_and_all at src/WP_CLI/ParsePluginNameInput.php:19). For example:

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.' );
}

This would make the behavior explicit and prevent user confusion.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added validation to error when both plugin names and --auto-update-indicated are specified in commit 7db7e24. The error message clearly states: "Cannot specify plugin names with --auto-update-indicated. This flag updates all plugins with server-indicated automatic updates."

This prevents user confusion by making the behavior explicit - the flag is designed to update all plugins with the server-indicated flag, not to filter specific plugins.


$args = $this->check_optional_args_and_all( $args, $all );
if ( ! $args ) {
Expand Down Expand Up @@ -806,8 +852,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
Expand Down Expand Up @@ -849,6 +896,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,
Expand Down
6 changes: 6 additions & 0 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
}

Expand Down