diff --git a/features/checksum-plugin.feature b/features/checksum-plugin.feature index e70af037..7e754741 100644 --- a/features/checksum-plugin.feature +++ b/features/checksum-plugin.feature @@ -173,3 +173,45 @@ Feature: Validate checksums for WordPress plugins """ "plugin_name":"duplicate-post","file":"duplicate-post.php","message":"Checksum does not match" """ + + Scenario: Plugin verification is skipped when the --exclude argument is included + Given a WP install + + When I run `wp plugin delete --all` + Then STDOUT should contain: + """ + Success: + """ + + When I run `wp plugin install akismet` + Then STDOUT should contain: + """ + Success: + """ + + When I try `wp plugin verify-checksums --all --exclude=akismet` + Then STDOUT should contain: + """ + Verified 0 of 1 plugins (1 skipped). + """ + + Scenario: Plugin is verified when the --exclude argument isn't included + Given a WP install + + When I run `wp plugin delete --all` + Then STDOUT should contain: + """ + Success: + """ + + When I run `wp plugin install akismet` + Then STDOUT should contain: + """ + Success: + """ + + When I try `wp plugin verify-checksums --all` + Then STDOUT should contain: + """ + Verified 1 of 1 plugins. + """ diff --git a/src/Checksum_Plugin_Command.php b/src/Checksum_Plugin_Command.php index e60b097d..c65a80b6 100644 --- a/src/Checksum_Plugin_Command.php +++ b/src/Checksum_Plugin_Command.php @@ -66,6 +66,9 @@ class Checksum_Plugin_Command extends Checksum_Base_Command { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * + * [--exclude=] + * : Comma separated list of plugin names that should be excluded from verifying. + * * ## EXAMPLES * * # Verify the checksums of all installed plugins @@ -83,17 +86,25 @@ public function __invoke( $args, $assoc_args ) { $strict = (bool) Utils\get_flag_value( $assoc_args, 'strict', false ); $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); $plugins = $fetcher->get_many( $all ? $this->get_all_plugin_names() : $args ); + $exclude = Utils\get_flag_value( $assoc_args, 'exclude', '' ); $version_arg = isset( $assoc_args['version'] ) ? $assoc_args['version'] : ''; if ( empty( $plugins ) && ! $all ) { WP_CLI::error( 'You need to specify either one or more plugin slugs to check or use the --all flag to check all plugins.' ); } + $exclude_list = explode( ',', $exclude ); + $skips = 0; foreach ( $plugins as $plugin ) { $version = empty( $version_arg ) ? $this->get_plugin_version( $plugin->file ) : $version_arg; + if ( in_array( $plugin->name, $exclude_list, true ) ) { + $skips++; + continue; + } + if ( false === $version ) { WP_CLI::warning( "Could not retrieve the version for plugin {$plugin->name}, skipping." ); $skips++;