diff --git a/features/plugin-list-recently-active.feature b/features/plugin-list-recently-active.feature new file mode 100644 index 000000000..504632cb5 --- /dev/null +++ b/features/plugin-list-recently-active.feature @@ -0,0 +1,205 @@ +Feature: List Recently Active WordPress plugins + + @require-php-7.0 @require-wp-5.0 + Scenario: Verify plugin installation, activation, deactivation and confirm listing recently active plugins list is correct + Given a WP install + When I run `wp plugin install bbpress buddypress gutenberg --activate` + Then STDOUT should contain: + """ + Activating 'bbpress'... + """ + And STDOUT should contain: + """ + Activating 'buddypress'... + """ + And STDOUT should contain: + """ + Activating 'gutenberg'... + """ + + When I run `wp plugin activate akismet` + Then STDOUT should contain: + """ + Plugin 'akismet' activated. + """ + + When I run `wp plugin deactivate bbpress buddypress` + Then STDOUT should contain: + """ + Plugin 'bbpress' deactivated. + Plugin 'buddypress' deactivated. + Success: Deactivated 2 of 2 plugins. + """ + + When I run `wp plugin list --recently-active --field=name --format=json` + Then STDOUT should not be empty + And STDOUT should contain: + """ + ["bbpress","buddypress"] + """ + + @require-wp-5.0 + Scenario: Re confirm recently active list before and after deactivation + Given a WP install + When I run `wp plugin install bbpress buddypress --activate` + Then STDOUT should contain: + """ + Activating 'bbpress'... + """ + And STDOUT should contain: + """ + Activating 'buddypress'... + """ + + When I run `wp plugin list --recently-active --field=name --format=json` + Then STDOUT should not be empty + And STDOUT should contain: + """ + [] + """ + + When I run `wp plugin deactivate bbpress buddypress` + Then STDOUT should contain: + """ + Plugin 'bbpress' deactivated. + Plugin 'buddypress' deactivated. + Success: Deactivated 2 of 2 plugins. + """ + + When I run `wp plugin list --recently-active --field=name --format=json` + Then STDOUT should not be empty + And STDOUT should contain: + """ + ["bbpress","buddypress"] + """ + + @require-wp-5.0 + Scenario: Use recently active plugin to activate plugins + Given a WP install + When I run `wp plugin install bbpress buddypress --activate` + Then STDOUT should contain: + """ + Activating 'bbpress'... + """ + And STDOUT should contain: + """ + Activating 'buddypress'... + """ + + When I run `wp plugin deactivate bbpress buddypress` + Then STDOUT should contain: + """ + Plugin 'bbpress' deactivated. + Plugin 'buddypress' deactivated. + Success: Deactivated 2 of 2 plugins. + """ + + When I run `wp plugin activate $(wp plugin list --recently-active --field=name)` + Then STDOUT should not be empty + And STDOUT should contain: + """ + Plugin 'bbpress' activated. + Plugin 'buddypress' activated. + """ + + @require-php-7.0 @require-wp-5.0 + Scenario: For a MU site, verify plugin installation, activation, deactivation and confirm listing recently active plugins list is correct + Given a WP multisite install + When I run `wp plugin install bbpress buddypress gutenberg --activate-network` + Then STDOUT should contain: + """ + Network-activating 'bbpress'... + """ + And STDOUT should contain: + """ + Network-activating 'buddypress'... + """ + And STDOUT should contain: + """ + Network-activating 'gutenberg'... + """ + + When I run `wp plugin activate akismet --network` + Then STDOUT should contain: + """ + Plugin 'akismet' network activated. + """ + + When I run `wp plugin deactivate bbpress buddypress --network` + Then STDOUT should contain: + """ + Plugin 'bbpress' network deactivated. + Plugin 'buddypress' network deactivated. + Success: Network deactivated 2 of 2 plugins. + """ + + When I run `wp plugin list --recently-active --field=name --format=json` + Then STDOUT should not be empty + And STDOUT should contain: + """ + ["bbpress","buddypress"] + """ + + @require-wp-5.0 + Scenario: For a MU site, re-confirm recently active list before and after deactivation + Given a WP install + When I run `wp plugin install bbpress buddypress --activate-network` + Then STDOUT should contain: + """ + Network-activating 'bbpress'... + """ + And STDOUT should contain: + """ + Network-activating 'buddypress'... + """ + + When I run `wp plugin list --recently-active --field=name --format=json` + Then STDOUT should not be empty + And STDOUT should contain: + """ + [] + """ + + When I run `wp plugin deactivate bbpress buddypress --network` + Then STDOUT should contain: + """ + Plugin 'bbpress' network deactivated. + Plugin 'buddypress' network deactivated. + Success: Network deactivated 2 of 2 plugins. + """ + + When I run `wp plugin list --recently-active --field=name --format=json` + Then STDOUT should not be empty + And STDOUT should contain: + """ + ["bbpress","buddypress"] + """ + + @require-wp-5.0 + Scenario: For a MU site, use recently active plugin to activate plugins + Given a WP install + When I run `wp plugin install bbpress buddypress --activate-network` + Then STDOUT should contain: + """ + Network-activating 'bbpress'... + """ + And STDOUT should contain: + """ + Network-activating 'buddypress'... + """ + + When I run `wp plugin deactivate bbpress buddypress` + Then STDOUT should contain: + """ + Plugin 'bbpress' network deactivated. + Plugin 'buddypress' network deactivated. + Success: Network deactivated 2 of 2 plugins. + """ + + When I run `wp plugin activate $(wp plugin list --recently-active --field=name) --network` + Then STDOUT should not be empty + And STDOUT should contain: + """ + Plugin 'bbpress' network deactivated. + Plugin 'buddypress' network deactivated. + """ diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 336f1dda3..c73ff7f18 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -322,6 +322,19 @@ protected function get_all_items() { * $ wp plugin activate hello --network * Plugin 'hello' network activated. * Success: Network activated 1 of 1 plugins. + * + * # Activate plugin that were recently active. + * $ wp plugin activate $(wp plugin list --recently-active --field=name) + * Plugin 'bbpress' activated. + * Plugin 'buddypress' activated. + * Success: Activated 2 of 3 plugins. + * + * + * # Activate plugin that were recently active on a mu site. + * $ wp plugin activate $(wp plugin list --recently-active --field=name) --network + * Plugin 'bbpress' network activated. + * Plugin 'buddypress' network activated. + * Success: Activated 2 of 3 plugins. */ public function activate( $args, $assoc_args = array() ) { $network_wide = Utils\get_flag_value( $assoc_args, 'network', false ); @@ -710,6 +723,12 @@ protected function get_item_list() { $auto_updates = []; } + $recently_active = is_network_admin() ? get_site_option( 'recently_activated' ) : get_option( 'recently_activated' ); + + if ( false === $recently_active ) { + $recently_active = []; + } + foreach ( $this->get_all_plugins() as $file => $details ) { $all_update_info = $this->get_update_info(); $update_info = ( isset( $all_update_info->response[ $file ] ) && null !== $all_update_info->response[ $file ] ) ? (array) $all_update_info->response[ $file ] : null; @@ -736,6 +755,7 @@ protected function get_item_list() { 'author' => $details['Author'], 'wporg_status' => $wporg_info['status'], 'wporg_last_updated' => $wporg_info['last_updated'], + 'recently_active' => in_array( $file, array_keys( $recently_active ), true ), ]; if ( null === $update_info ) { @@ -1240,6 +1260,9 @@ public function delete( $args, $assoc_args = array() ) { * [--skip-update-check] * : If set, the plugin update check will be skipped. * + * [--recently-active] + * : If set, only recently active plugins will be shown and the status filter will be ignored. + * * ## AVAILABLE FIELDS * * These fields will be displayed by default for each plugin: @@ -1294,6 +1317,10 @@ public function delete( $args, $assoc_args = array() ) { * | local | | | * +--------------------+--------------+--------------------+ * + * # List recently active plugins on the site. + * $ wp plugin list --recently-active --field=name --format=json + * ["akismet","bbpress","buddypress"] + * * @subcommand list */ public function list_( $_, $assoc_args ) { diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 2e704544b..17385b09a 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -501,6 +501,15 @@ protected function _list( $_, $assoc_args ) { $all_items = $this->get_all_items(); + if ( false !== (bool) Utils\get_flag_value( $assoc_args, 'recently-active', false ) ) { + $all_items = array_filter( + $all_items, + function ( $value ) { + return isset( $value['recently_active'] ) && true === $value['recently_active']; + } + ); + } + if ( ! is_array( $all_items ) ) { WP_CLI::error( "No {$this->item_type}s found." ); }