Skip to content
Closed
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
205 changes: 205 additions & 0 deletions features/plugin-list-recently-active.feature
Original file line number Diff line number Diff line change
@@ -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.
"""
27 changes: 27 additions & 0 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should document how the behavior changes for multisite too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@danielbachhuber sorry, didn't get what needs to be done here.

*
* ## AVAILABLE FIELDS
*
* These fields will be displayed by default for each plugin:
Expand Down Expand Up @@ -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 ) {
Expand Down
9 changes: 9 additions & 0 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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." );
}
Expand Down