From a6a00a362583669ca23b90e6738a2d07a02735c2 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 25 Sep 2015 19:15:08 +0000 Subject: [PATCH] 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 --- .../includes/class-wp-plugins-list-table.php | 23 +++++++---- src/wp-admin/plugin-editor.php | 5 ++- src/wp-admin/plugins.php | 39 +++++++++++++++---- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index 7c9bb68a10..38b09e3c8c 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -129,12 +129,21 @@ class WP_Plugins_List_Table extends WP_List_Table { set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS ); - if ( ! $screen->in_admin( 'network' ) ) { + if ( $screen->in_admin( 'network' ) ) { + $recently_activated = get_site_option( 'recently_activated', array() ); + } else { $recently_activated = get_option( 'recently_activated', array() ); + } - foreach ( $recently_activated as $key => $time ) - if ( $time + WEEK_IN_SECONDS < time() ) - unset( $recently_activated[$key] ); + foreach ( $recently_activated as $key => $time ) { + if ( $time + WEEK_IN_SECONDS < time() ) { + unset( $recently_activated[$key] ); + } + } + + if ( $screen->in_admin( 'network' ) ) { + update_site_option( 'recently_activated', $recently_activated ); + } else { update_option( 'recently_activated', $recently_activated ); } @@ -170,8 +179,8 @@ class WP_Plugins_List_Table extends WP_List_Table { // On the network-admin screen, populate the active list with plugins that are network activated $plugins['active'][ $plugin_file ] = $plugin_data; } else { - if ( ! $screen->in_admin( 'network' ) && isset( $recently_activated[ $plugin_file ] ) ) { - // On the non-network screen, populate the recently activated list with plugins that have been recently activated + if ( isset( $recently_activated[ $plugin_file ] ) ) { + // Populate the recently activated list with plugins that have been recently activated $plugins['recently_activated'][ $plugin_file ] = $plugin_data; } // Populate the inactive list with plugins that aren't activated @@ -400,7 +409,7 @@ class WP_Plugins_List_Table extends WP_List_Table { echo '
'; - if ( ! $this->screen->in_admin( 'network' ) && 'recently_activated' === $status ) { + if ( 'recently_activated' == $status ) { submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false ); } elseif ( 'top' === $which && 'mustuse' === $status ) { echo '

' . sprintf( __( 'Files in the %s directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '

'; diff --git a/src/wp-admin/plugin-editor.php b/src/wp-admin/plugin-editor.php index 96bface13f..f347da93b5 100644 --- a/src/wp-admin/plugin-editor.php +++ b/src/wp-admin/plugin-editor.php @@ -71,8 +71,11 @@ case 'update': if ( is_plugin_active($file) ) deactivate_plugins($file, true); - if ( ! is_network_admin() ) + if ( ! is_network_admin() ) { update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) ); + } else { + update_site_option( 'recently_activated', array( $file => time() ) + (array) get_site_option( 'recently_activated' ) ); + } 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)); exit; diff --git a/src/wp-admin/plugins.php b/src/wp-admin/plugins.php index 32bf7dc586..57bad92a6d 100644 --- a/src/wp-admin/plugins.php +++ b/src/wp-admin/plugins.php @@ -54,6 +54,10 @@ if ( $action ) { $recent = (array) get_option( 'recently_activated' ); unset( $recent[ $plugin ] ); update_option( 'recently_activated', $recent ); + } else { + $recent = (array) get_site_option( 'recently_activated' ); + unset( $recent[ $plugin ] ); + update_site_option( 'recently_activated', $recent ); } if ( isset($_GET['from']) && 'import' == $_GET['from'] ) { @@ -96,9 +100,18 @@ if ( $action ) { if ( ! is_network_admin() ) { $recent = (array) get_option('recently_activated' ); - foreach ( $plugins as $plugin ) - unset( $recent[ $plugin ] ); + } else { + $recent = (array) get_site_option('recently_activated' ); + } + + foreach ( $plugins as $plugin ) { + unset( $recent[ $plugin ] ); + } + + if ( ! is_network_admin() ) { update_option( 'recently_activated', $recent ); + } else { + update_site_option( 'recently_activated', $recent ); } wp_redirect( self_admin_url("plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s") ); @@ -165,8 +178,13 @@ if ( $action ) { } deactivate_plugins( $plugin, false, is_network_admin() ); - if ( ! is_network_admin() ) + + if ( ! is_network_admin() ) { update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); + } else { + update_site_option( 'recently_activated', array( $plugin => time() ) + (array) get_site_option( 'recently_activated' ) ); + } + if ( headers_sent() ) echo ""; else @@ -194,11 +212,15 @@ if ( $action ) { deactivate_plugins( $plugins, false, is_network_admin() ); + $deactivated = array(); + foreach ( $plugins as $plugin ) { + $deactivated[ $plugin ] = time(); + } + if ( ! is_network_admin() ) { - $deactivated = array(); - foreach ( $plugins as $plugin ) - $deactivated[ $plugin ] = time(); update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) ); + } else { + update_site_option( 'recently_activated', $deactivated + (array) get_site_option( 'recently_activated' ) ); } wp_redirect( self_admin_url("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s") ); @@ -354,8 +376,11 @@ if ( $action ) { exit; case 'clear-recent-list': - if ( ! is_network_admin() ) + if ( ! is_network_admin() ) { update_option( 'recently_activated', array() ); + } else { + update_site_option( 'recently_activated', array() ); + } break; } }