diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 01fcaeb216..a1ce53abb5 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -13,7 +13,7 @@ class WP_Plugins_List_Table extends WP_List_Table { global $status, $page; $status = 'all'; - if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'network', 'mustuse', 'dropins', 'search' ) ) ) + if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) $status = $_REQUEST['plugin_status']; if ( isset($_REQUEST['s']) ) @@ -78,23 +78,21 @@ class WP_Plugins_List_Table extends WP_List_Table { set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 ); - $recently_activated = get_option( 'recently_activated', array() ); + if ( ! $screen->is_network ) { + $recently_activated = get_option( 'recently_activated', array() ); - $one_week = 7*24*60*60; - foreach ( $recently_activated as $key => $time ) - if ( $time + $one_week < time() ) - unset( $recently_activated[$key] ); - update_option( 'recently_activated', $recently_activated ); + $one_week = 7*24*60*60; + foreach ( $recently_activated as $key => $time ) + if ( $time + $one_week < time() ) + unset( $recently_activated[$key] ); + update_option( 'recently_activated', $recently_activated ); + } foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { // Filter into individual sections - if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !$screen->is_network ) { - unset( $plugins['all'][ $plugin_file] ); - } elseif ( is_plugin_active_for_network($plugin_file) && !$screen->is_network ) { + if ( ! $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) { unset( $plugins['all'][ $plugin_file ] ); - } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) { - $plugins['network'][ $plugin_file ] = $plugin_data; - } elseif ( ( !$screen->is_network && is_plugin_active( $plugin_file ) ) + } elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) ) || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) { $plugins['active'][ $plugin_file ] = $plugin_data; } else { @@ -215,9 +213,6 @@ class WP_Plugins_List_Table extends WP_List_Table { case 'inactive': $text = _n( 'Inactive (%s)', 'Inactive (%s)', $count ); break; - case 'network': - $text = _n( 'Network (%s)', 'Network (%s)', $count ); - break; case 'mustuse': $text = _n( 'Must-Use (%s)', 'Must-Use (%s)', $count ); break; @@ -248,10 +243,8 @@ class WP_Plugins_List_Table extends WP_List_Table { $screen = get_current_screen(); - if ( 'active' != $status ) { - $action = $screen->is_network ? 'network-activate-selected' : 'activate-selected'; - $actions[ $action ] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' ); - } + if ( 'active' != $status ) + $actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' ); if ( 'inactive' != $status && 'recent' != $status ) $actions['deactivate-selected'] = $screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' ); @@ -283,7 +276,9 @@ class WP_Plugins_List_Table extends WP_List_Table { echo '
' . sprintf( __( 'Files in the %s
directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '
' . $plugin_data['Description'] . '
'; } else { - $is_active_for_network = is_plugin_active_for_network($plugin_file); if ( $screen->is_network ) - $is_active = $is_active_for_network; + $is_active = is_plugin_active_for_network( $plugin_file ); else $is_active = is_plugin_active( $plugin_file ); - if ( $is_active_for_network && !is_super_admin() && !$screen->is_network ) - return; - if ( $screen->is_network ) { - if ( $is_active_for_network ) { + if ( $is_active ) { if ( current_user_can( 'manage_network_plugins' ) ) - $actions['network_deactivate'] = '' . __('Network Deactivate') . ''; + $actions['deactivate'] = '' . __('Network Deactivate') . ''; } else { if ( current_user_can( 'manage_network_plugins' ) ) - $actions['network_activate'] = '' . __('Network Activate') . ''; + $actions['activate'] = '' . __('Network Activate') . ''; if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) $actions['delete'] = '' . __('Delete') . ''; } diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 9e86160eb6..98b6136e41 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -572,9 +572,11 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen * @since 2.5.0 * * @param string|array $plugins Single plugin or list of plugins to deactivate. + * @param mixed $network_wide Whether to deactivate the plugin for all sites in the network. + * A value of null (the default) will deactivate plugins for both the site and the network. * @param bool $silent Prevent calling deactivation hooks. Default is false. */ -function deactivate_plugins( $plugins, $silent = false ) { +function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) { if ( is_multisite() ) $network_current = get_site_option( 'active_sitewide_plugins', array() ); $current = get_option( 'active_plugins', array() ); @@ -585,15 +587,19 @@ function deactivate_plugins( $plugins, $silent = false ) { if ( ! is_plugin_active($plugin) ) continue; - $network_wide = is_plugin_active_for_network( $plugin ); + $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin ); if ( ! $silent ) - do_action( 'deactivate_plugin', $plugin, $network_wide ); + do_action( 'deactivate_plugin', $plugin, $network_deactivating ); - if ( $network_wide ) { + if ( false !== $network_wide ) { + if ( ! is_plugin_active_for_network( $plugin ) ) + continue; $do_network = true; unset( $network_current[ $plugin ] ); - } else { + } + + if ( true !== $network_wide ) { $key = array_search( $plugin, $current ); if ( false !== $key ) { $do_blog = true; @@ -602,8 +608,8 @@ function deactivate_plugins( $plugins, $silent = false ) { } if ( ! $silent ) { - do_action( 'deactivate_' . $plugin, $network_wide ); - do_action( 'deactivated_plugin', $plugin, $network_wide ); + do_action( 'deactivate_' . $plugin, $network_deactivating ); + do_action( 'deactivated_plugin', $plugin, $network_deactivating ); } } diff --git a/wp-admin/plugin-editor.php b/wp-admin/plugin-editor.php index 9ce0648234..b7758d225d 100644 --- a/wp-admin/plugin-editor.php +++ b/wp-admin/plugin-editor.php @@ -65,7 +65,8 @@ case 'update': if ( is_plugin_active($file) ) deactivate_plugins($file, true); - update_option('recently_activated', array($file => time()) + (array)get_option('recently_activated')); + if ( ! is_network_admin() ) + update_option( 'recently_activated', array( $file => time() ) + (array) get_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/wp-admin/plugins.php b/wp-admin/plugins.php index f1b6164fa5..eb8563d636 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -12,7 +12,7 @@ require_once('./admin.php'); if ( is_multisite() ) { $menu_perms = get_site_option( 'menu_items', array() ); - if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() ) + if ( empty( $menu_perms['plugins'] ) && ! current_user_can( 'manage_network_plugins' ) ) wp_die( __( 'Cheatin’ uh?' ) ); } @@ -31,9 +31,6 @@ $s = isset($_REQUEST['s']) ? urlencode($_REQUEST['s']) : ''; $_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']); if ( $action ) { - $network_wide = false; - if ( ( isset( $_GET['networkwide'] ) || 'network-activate-selected' == $action ) && is_multisite() && current_user_can( 'manage_network_plugins' ) ) - $network_wide = true; switch ( $action ) { case 'activate': @@ -42,7 +39,7 @@ if ( $action ) { check_admin_referer('activate-plugin_' . $plugin); - $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), $network_wide); + $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), is_network_admin() ); if ( is_wp_error( $result ) ) { if ( 'unexpected_output' == $result->get_error_code() ) { $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s"); @@ -53,11 +50,12 @@ if ( $action ) { } } - $recent = (array)get_option('recently_activated'); - if ( isset($recent[ $plugin ]) ) { - unset($recent[ $plugin ]); - update_option('recently_activated', $recent); + if ( ! is_network_admin() ) { + $recent = (array) get_option( 'recently_activated' ); + unset( $recent[ $plugin ] ); + update_option( 'recently_activated', $recent ); } + if ( isset($_GET['from']) && 'import' == $_GET['from'] ) { wp_redirect( self_admin_url("import.php?import=" . str_replace('-importer', '', dirname($plugin))) ); // overrides the ?error=true one above and redirects to the Imports page, stripping the -importer suffix } else { @@ -66,7 +64,6 @@ if ( $action ) { exit; break; case 'activate-selected': - case 'network-activate-selected': if ( ! current_user_can('activate_plugins') ) wp_die(__('You do not have sufficient permissions to activate plugins for this site.')); @@ -75,7 +72,7 @@ if ( $action ) { $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); // Only activate plugins which are not already active. - $check = $network_wide ? 'is_plugin_active_for_network' : 'is_plugin_active'; + $check = is_network_admin() ? 'is_plugin_active_for_network' : 'is_plugin_active'; foreach ( $plugins as $i => $plugin ) if ( $check( $plugin ) ) unset( $plugins[ $i ] ); @@ -85,14 +82,14 @@ if ( $action ) { exit; } - activate_plugins($plugins, self_admin_url('plugins.php?error=true'), $network_wide); + activate_plugins($plugins, self_admin_url('plugins.php?error=true'), is_network_admin() ); - $recent = (array)get_option('recently_activated'); - foreach ( $plugins as $plugin => $time) - if ( isset($recent[ $plugin ]) ) - unset($recent[ $plugin ]); - - update_option('recently_activated', $recent); + if ( ! is_network_admin() ) { + $recent = (array) get_option('recently_activated' ); + foreach ( $plugins as $plugin ) + unset( $recent[ $plugin ] ); + update_option( 'recently_activated', $recent ); + } wp_redirect( self_admin_url("plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s") ); exit; @@ -153,8 +150,15 @@ if ( $action ) { wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.')); check_admin_referer('deactivate-plugin_' . $plugin); - deactivate_plugins($plugin); - update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated')); + + if ( ! is_network_admin() && is_plugin_active_for_network() ) { + wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") ); + exit; + } + + deactivate_plugins( $plugin, false, is_network_admin() ); + if ( ! is_network_admin() ) + update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); if ( headers_sent() ) echo ""; else @@ -168,19 +172,27 @@ if ( $action ) { check_admin_referer('bulk-plugins'); $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); - $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated. + // Do not deactivate plugins which are already deactivated. + if ( is_network_admin() ) { + $plugins = array_filter( $plugins, 'is_plugin_active_for_network' ); + } else { + $plugins = array_filter( $plugins, 'is_plugin_active' ); + $plugins = array_diff( $plugins, array_filter( $plugins, 'is_plugin_active_for_network' ) ); + } if ( empty($plugins) ) { wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") ); exit; } - deactivate_plugins($plugins); + 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' ) ); + } - update_option('recently_activated', $deactivated + (array)get_option('recently_activated')); wp_redirect( self_admin_url("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s") ); exit; break; @@ -305,7 +317,8 @@ if ( $action ) { exit; break; case 'clear-recent-list': - update_option('recently_activated', array()); + if ( ! is_network_admin() ) + update_option( 'recently_activated', array() ); break; } }