Skip to content

Commit a6a00a3

Browse files
committed
Implement 'Recently Active' functionality for network-wide plugins in the Network Admin.
Fixes #20468 Thanks to WordCamp RI attendees for testing! git-svn-id: https://develop.svn.wordpress.org/trunk@34551 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a6d1621 commit a6a00a3

3 files changed

Lines changed: 52 additions & 15 deletions

File tree

src/wp-admin/includes/class-wp-plugins-list-table.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,21 @@ public function prepare_items() {
129129

130130
set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
131131

132-
if ( ! $screen->in_admin( 'network' ) ) {
132+
if ( $screen->in_admin( 'network' ) ) {
133+
$recently_activated = get_site_option( 'recently_activated', array() );
134+
} else {
133135
$recently_activated = get_option( 'recently_activated', array() );
136+
}
137+
138+
foreach ( $recently_activated as $key => $time ) {
139+
if ( $time + WEEK_IN_SECONDS < time() ) {
140+
unset( $recently_activated[$key] );
141+
}
142+
}
134143

135-
foreach ( $recently_activated as $key => $time )
136-
if ( $time + WEEK_IN_SECONDS < time() )
137-
unset( $recently_activated[$key] );
144+
if ( $screen->in_admin( 'network' ) ) {
145+
update_site_option( 'recently_activated', $recently_activated );
146+
} else {
138147
update_option( 'recently_activated', $recently_activated );
139148
}
140149

@@ -170,8 +179,8 @@ public function prepare_items() {
170179
// On the network-admin screen, populate the active list with plugins that are network activated
171180
$plugins['active'][ $plugin_file ] = $plugin_data;
172181
} else {
173-
if ( ! $screen->in_admin( 'network' ) && isset( $recently_activated[ $plugin_file ] ) ) {
174-
// On the non-network screen, populate the recently activated list with plugins that have been recently activated
182+
if ( isset( $recently_activated[ $plugin_file ] ) ) {
183+
// Populate the recently activated list with plugins that have been recently activated
175184
$plugins['recently_activated'][ $plugin_file ] = $plugin_data;
176185
}
177186
// Populate the inactive list with plugins that aren't activated
@@ -400,7 +409,7 @@ protected function extra_tablenav( $which ) {
400409

401410
echo '<div class="alignleft actions">';
402411

403-
if ( ! $this->screen->in_admin( 'network' ) && 'recently_activated' === $status ) {
412+
if ( 'recently_activated' == $status ) {
404413
submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false );
405414
} elseif ( 'top' === $which && 'mustuse' === $status ) {
406415
echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';

src/wp-admin/plugin-editor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@
7171
if ( is_plugin_active($file) )
7272
deactivate_plugins($file, true);
7373

74-
if ( ! is_network_admin() )
74+
if ( ! is_network_admin() ) {
7575
update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) );
76+
} else {
77+
update_site_option( 'recently_activated', array( $file => time() ) + (array) get_site_option( 'recently_activated' ) );
78+
}
7679

7780
wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide));
7881
exit;

src/wp-admin/plugins.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
$recent = (array) get_option( 'recently_activated' );
5555
unset( $recent[ $plugin ] );
5656
update_option( 'recently_activated', $recent );
57+
} else {
58+
$recent = (array) get_site_option( 'recently_activated' );
59+
unset( $recent[ $plugin ] );
60+
update_site_option( 'recently_activated', $recent );
5761
}
5862

5963
if ( isset($_GET['from']) && 'import' == $_GET['from'] ) {
@@ -96,9 +100,18 @@
96100

97101
if ( ! is_network_admin() ) {
98102
$recent = (array) get_option('recently_activated' );
99-
foreach ( $plugins as $plugin )
100-
unset( $recent[ $plugin ] );
103+
} else {
104+
$recent = (array) get_site_option('recently_activated' );
105+
}
106+
107+
foreach ( $plugins as $plugin ) {
108+
unset( $recent[ $plugin ] );
109+
}
110+
111+
if ( ! is_network_admin() ) {
101112
update_option( 'recently_activated', $recent );
113+
} else {
114+
update_site_option( 'recently_activated', $recent );
102115
}
103116

104117
wp_redirect( self_admin_url("plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s") );
@@ -165,8 +178,13 @@
165178
}
166179

167180
deactivate_plugins( $plugin, false, is_network_admin() );
168-
if ( ! is_network_admin() )
181+
182+
if ( ! is_network_admin() ) {
169183
update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) );
184+
} else {
185+
update_site_option( 'recently_activated', array( $plugin => time() ) + (array) get_site_option( 'recently_activated' ) );
186+
}
187+
170188
if ( headers_sent() )
171189
echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s" ) . "' />";
172190
else
@@ -194,11 +212,15 @@
194212

195213
deactivate_plugins( $plugins, false, is_network_admin() );
196214

215+
$deactivated = array();
216+
foreach ( $plugins as $plugin ) {
217+
$deactivated[ $plugin ] = time();
218+
}
219+
197220
if ( ! is_network_admin() ) {
198-
$deactivated = array();
199-
foreach ( $plugins as $plugin )
200-
$deactivated[ $plugin ] = time();
201221
update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) );
222+
} else {
223+
update_site_option( 'recently_activated', $deactivated + (array) get_site_option( 'recently_activated' ) );
202224
}
203225

204226
wp_redirect( self_admin_url("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s") );
@@ -354,8 +376,11 @@
354376
exit;
355377

356378
case 'clear-recent-list':
357-
if ( ! is_network_admin() )
379+
if ( ! is_network_admin() ) {
358380
update_option( 'recently_activated', array() );
381+
} else {
382+
update_site_option( 'recently_activated', array() );
383+
}
359384
break;
360385
}
361386
}

0 commit comments

Comments
 (0)