Skip to content

Commit 0981288

Browse files
authored
Merge pull request #424 from ernilambar/232-recently-active-plugins
2 parents 23fe646 + 6e09dcb commit 0981288

File tree

3 files changed

+181
-0
lines changed

3 files changed

+181
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
Feature: List recently active WordPress plugins
2+
3+
Scenario: Verify plugin installation, activation, deactivation and confirm listing recently active plugins list is correct
4+
Given a WP install
5+
6+
When I run `wp plugin install site-secrets debug-bar p2-by-email --activate`
7+
Then STDOUT should contain:
8+
"""
9+
Plugin 'site-secrets' activated.
10+
"""
11+
And STDOUT should contain:
12+
"""
13+
Plugin 'debug-bar' activated.
14+
"""
15+
And STDOUT should contain:
16+
"""
17+
Plugin 'p2-by-email' activated.
18+
"""
19+
20+
When I run `wp plugin list --recently-active --field=name --format=json`
21+
Then STDOUT should be:
22+
"""
23+
[]
24+
"""
25+
26+
When I run `wp plugin activate akismet`
27+
Then STDOUT should contain:
28+
"""
29+
Plugin 'akismet' activated.
30+
"""
31+
32+
When I run `wp plugin deactivate site-secrets debug-bar`
33+
Then STDOUT should contain:
34+
"""
35+
Plugin 'site-secrets' deactivated.
36+
Plugin 'debug-bar' deactivated.
37+
Success: Deactivated 2 of 2 plugins.
38+
"""
39+
40+
When I run `wp plugin list --recently-active --field=name`
41+
Then STDOUT should be a table containing rows:
42+
| debug-bar |
43+
| site-secrets |
44+
45+
Scenario: Use recently active plugin to activate plugins
46+
Given a WP install
47+
48+
When I run `wp plugin install site-secrets debug-bar --activate`
49+
Then STDOUT should contain:
50+
"""
51+
Plugin 'site-secrets' activated.
52+
"""
53+
And STDOUT should contain:
54+
"""
55+
Plugin 'debug-bar' activated.
56+
"""
57+
58+
When I run `wp plugin deactivate site-secrets debug-bar`
59+
Then STDOUT should be:
60+
"""
61+
Plugin 'site-secrets' deactivated.
62+
Plugin 'debug-bar' deactivated.
63+
Success: Deactivated 2 of 2 plugins.
64+
"""
65+
66+
When I run `wp plugin activate $(wp plugin list --recently-active --field=name)`
67+
Then STDOUT should contain:
68+
"""
69+
Plugin 'debug-bar' activated.
70+
"""
71+
And STDOUT should contain:
72+
"""
73+
Plugin 'site-secrets' activated.
74+
"""
75+
76+
Scenario: For a MU site, verify plugin installation, activation, deactivation and confirm listing recently active plugins list is correct
77+
Given a WP multisite install
78+
79+
When I run `wp plugin install site-secrets debug-bar p2-by-email --activate-network`
80+
Then STDOUT should contain:
81+
"""
82+
Plugin 'site-secrets' network activated.
83+
"""
84+
And STDOUT should contain:
85+
"""
86+
Plugin 'debug-bar' network activated.
87+
"""
88+
And STDOUT should contain:
89+
"""
90+
Plugin 'p2-by-email' network activated.
91+
"""
92+
93+
When I run `wp plugin activate akismet --network`
94+
Then STDOUT should contain:
95+
"""
96+
Plugin 'akismet' network activated.
97+
"""
98+
99+
When I run `wp plugin list --recently-active --field=name --format=json`
100+
Then STDOUT should be:
101+
"""
102+
[]
103+
"""
104+
When I run `wp plugin deactivate site-secrets debug-bar --network`
105+
Then STDOUT should be:
106+
"""
107+
Plugin 'site-secrets' network deactivated.
108+
Plugin 'debug-bar' network deactivated.
109+
Success: Network deactivated 2 of 2 plugins.
110+
"""
111+
112+
When I run `wp plugin list --recently-active --field=name`
113+
Then STDOUT should be a table containing rows:
114+
| debug-bar |
115+
| site-secrets |
116+
117+
Scenario: For a MU site, use recently active plugin to activate plugins
118+
Given a WP multisite install
119+
120+
When I run `wp plugin install site-secrets debug-bar --activate-network`
121+
Then STDOUT should contain:
122+
"""
123+
Plugin 'site-secrets' network activated.
124+
"""
125+
And STDOUT should contain:
126+
"""
127+
Plugin 'debug-bar' network activated.
128+
"""
129+
130+
When I run `wp plugin deactivate site-secrets debug-bar --network`
131+
Then STDOUT should be:
132+
"""
133+
Plugin 'site-secrets' network deactivated.
134+
Plugin 'debug-bar' network deactivated.
135+
Success: Network deactivated 2 of 2 plugins.
136+
"""
137+
138+
When I run `wp plugin activate $(wp plugin list --recently-active --field=name) --network`
139+
Then STDOUT should contain:
140+
"""
141+
Plugin 'site-secrets' network activated.
142+
"""
143+
And STDOUT should contain:
144+
"""
145+
Plugin 'debug-bar' network activated.
146+
"""

src/Plugin_Command.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ protected function get_all_items() {
329329
* $ wp plugin activate hello --network
330330
* Plugin 'hello' network activated.
331331
* Success: Network activated 1 of 1 plugins.
332+
*
333+
* # Activate plugins that were recently active.
334+
* $ wp plugin activate $(wp plugin list --recently-active --field=name)
335+
* Plugin 'bbpress' activated.
336+
* Plugin 'buddypress' activated.
337+
* Success: Activated 2 of 2 plugins.
338+
*
339+
* # Activate plugins that were recently active on a multisite.
340+
* $ wp plugin activate $(wp plugin list --recently-active --field=name) --network
341+
* Plugin 'bbpress' network activated.
342+
* Plugin 'buddypress' network activated.
343+
* Success: Activated 2 of 2 plugins.
332344
*/
333345
public function activate( $args, $assoc_args = array() ) {
334346
$network_wide = Utils\get_flag_value( $assoc_args, 'network', false );
@@ -718,6 +730,12 @@ protected function get_item_list() {
718730
$auto_updates = [];
719731
}
720732

733+
$recently_active = is_network_admin() ? get_site_option( 'recently_activated' ) : get_option( 'recently_activated' );
734+
735+
if ( false === $recently_active ) {
736+
$recently_active = [];
737+
}
738+
721739
foreach ( $this->get_all_plugins() as $file => $details ) {
722740
$all_update_info = $this->get_update_info();
723741
$update_info = ( isset( $all_update_info->response[ $file ] ) && null !== $all_update_info->response[ $file ] ) ? (array) $all_update_info->response[ $file ] : null;
@@ -745,6 +763,7 @@ protected function get_item_list() {
745763
'tested_up_to' => '',
746764
'wporg_status' => $wporg_info['status'],
747765
'wporg_last_updated' => $wporg_info['last_updated'],
766+
'recently_active' => in_array( $file, array_keys( $recently_active ), true ),
748767
];
749768

750769
if ( $this->check_headers['tested_up_to'] ) {
@@ -1306,6 +1325,9 @@ public function delete( $args, $assoc_args = array() ) {
13061325
* [--skip-update-check]
13071326
* : If set, the plugin update check will be skipped.
13081327
*
1328+
* [--recently-active]
1329+
* : If set, only recently active plugins will be shown and the status filter will be ignored.
1330+
*
13091331
* ## AVAILABLE FIELDS
13101332
*
13111333
* These fields will be displayed by default for each plugin:
@@ -1361,6 +1383,10 @@ public function delete( $args, $assoc_args = array() ) {
13611383
* | local | | |
13621384
* +--------------------+--------------+--------------------+
13631385
*
1386+
* # List recently active plugins on the site.
1387+
* $ wp plugin list --recently-active --field=name --format=json
1388+
* ["akismet","bbpress","buddypress"]
1389+
*
13641390
* @subcommand list
13651391
*/
13661392
public function list_( $_, $assoc_args ) {

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,15 @@ protected function _list( $_, $assoc_args ) {
539539

540540
$all_items = $this->get_all_items();
541541

542+
if ( false !== (bool) Utils\get_flag_value( $assoc_args, 'recently-active', false ) ) {
543+
$all_items = array_filter(
544+
$all_items,
545+
function ( $value ) {
546+
return isset( $value['recently_active'] ) && true === $value['recently_active'];
547+
}
548+
);
549+
}
550+
542551
if ( ! is_array( $all_items ) ) {
543552
WP_CLI::error( "No {$this->item_type}s found." );
544553
}

0 commit comments

Comments
 (0)