WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/19/2012 03:41:29 AM (10 years ago)
Author:
nacin
Message:

Clean up plugins.php with regards to recently edited files, deactivations, and the network admin. see #20468, #20104.

  • Limit recently_activated to the site dashboard, and properly remove bulk-activated plugins from the array.
  • Remove code used from before the network admin, such as the unused 'network' plugin_status.
  • Don't try to deactivate a plugin already deactivated.
  • Use more specific caps (manage_network_plugins) rather than is_super_admin().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/plugins.php

    r19684 r20525  
    1313    $menu_perms = get_site_option( 'menu_items', array() );
    1414
    15     if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() )
     15    if ( empty( $menu_perms['plugins'] ) && ! current_user_can( 'manage_network_plugins' ) )
    1616        wp_die( __( 'Cheatin’ uh?' ) );
    1717}
     
    3232
    3333if ( $action ) {
    34     $network_wide = false;
    35     if ( ( isset( $_GET['networkwide'] ) || 'network-activate-selected' == $action ) && is_multisite() && current_user_can( 'manage_network_plugins' ) )
    36         $network_wide = true;
    3734
    3835    switch ( $action ) {
     
    4340            check_admin_referer('activate-plugin_' . $plugin);
    4441
    45             $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), $network_wide);
     42            $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), is_network_admin() );
    4643            if ( is_wp_error( $result ) ) {
    4744                if ( 'unexpected_output' == $result->get_error_code() ) {
     
    5451            }
    5552
    56             $recent = (array)get_option('recently_activated');
    57             if ( isset($recent[ $plugin ]) ) {
    58                 unset($recent[ $plugin ]);
    59                 update_option('recently_activated', $recent);
    60             }
     53            if ( ! is_network_admin() ) {
     54                $recent = (array) get_option( 'recently_activated' );
     55                unset( $recent[ $plugin ] );
     56                update_option( 'recently_activated', $recent );
     57            }
     58
    6159            if ( isset($_GET['from']) && 'import' == $_GET['from'] ) {
    6260                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
     
    6765            break;
    6866        case 'activate-selected':
    69         case 'network-activate-selected':
    7067            if ( ! current_user_can('activate_plugins') )
    7168                wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
     
    7673
    7774            // Only activate plugins which are not already active.
    78             $check = $network_wide ? 'is_plugin_active_for_network' : 'is_plugin_active';
     75            $check = is_network_admin() ? 'is_plugin_active_for_network' : 'is_plugin_active';
    7976            foreach ( $plugins as $i => $plugin )
    8077                if ( $check( $plugin ) )
     
    8683            }
    8784
    88             activate_plugins($plugins, self_admin_url('plugins.php?error=true'), $network_wide);
    89 
    90             $recent = (array)get_option('recently_activated');
    91             foreach ( $plugins as $plugin => $time)
    92                 if ( isset($recent[ $plugin ]) )
    93                     unset($recent[ $plugin ]);
    94 
    95             update_option('recently_activated', $recent);
     85            activate_plugins($plugins, self_admin_url('plugins.php?error=true'), is_network_admin() );
     86
     87            if ( ! is_network_admin() ) {
     88                $recent = (array) get_option('recently_activated' );
     89                foreach ( $plugins as $plugin )
     90                    unset( $recent[ $plugin ] );
     91                update_option( 'recently_activated', $recent );
     92            }
    9693
    9794            wp_redirect( self_admin_url("plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s") );
     
    154151
    155152            check_admin_referer('deactivate-plugin_' . $plugin);
    156             deactivate_plugins($plugin);
    157             update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
     153
     154            if ( ! is_network_admin() && is_plugin_active_for_network() ) {
     155                wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
     156                exit;
     157            }
     158
     159            deactivate_plugins( $plugin, false, is_network_admin() );
     160            if ( ! is_network_admin() )
     161                update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) );
    158162            if ( headers_sent() )
    159163                echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s" ) . "' />";
     
    169173
    170174            $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    171             $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated.
     175            // Do not deactivate plugins which are already deactivated.
     176            if ( is_network_admin() ) {
     177                $plugins = array_filter( $plugins, 'is_plugin_active_for_network' );
     178            } else {
     179                $plugins = array_filter( $plugins, 'is_plugin_active' );
     180                $plugins = array_diff( $plugins, array_filter( $plugins, 'is_plugin_active_for_network' ) );
     181            }
    172182            if ( empty($plugins) ) {
    173183                wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
     
    175185            }
    176186
    177             deactivate_plugins($plugins);
    178 
    179             $deactivated = array();
    180             foreach ( $plugins as $plugin )
    181                 $deactivated[ $plugin ] = time();
    182 
    183             update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
     187            deactivate_plugins( $plugins, false, is_network_admin() );
     188
     189            if ( ! is_network_admin() ) {
     190                $deactivated = array();
     191                foreach ( $plugins as $plugin )
     192                    $deactivated[ $plugin ] = time();
     193                update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) );
     194            }
     195
    184196            wp_redirect( self_admin_url("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s") );
    185197            exit;
     
    306318            break;
    307319        case 'clear-recent-list':
    308             update_option('recently_activated', array());
     320            if ( ! is_network_admin() )
     321                update_option( 'recently_activated', array() );
    309322            break;
    310323    }
Note: See TracChangeset for help on using the changeset viewer.