Make WordPress Core

Ticket #20104: 20104.2.diff

File 20104.2.diff, 15.5 KB (added by nacin, 13 years ago)
  • wp-admin/includes/plugin.php

     
    572572 * @since 2.5.0
    573573 *
    574574 * @param string|array $plugins Single plugin or list of plugins to deactivate.
     575 * @param mixed $network_wide Whether to deactivate the plugin for all sites in the network.
     576 *      A value of null (the default) will deactivate plugins for both the site and the network.
    575577 * @param bool $silent Prevent calling deactivation hooks. Default is false.
    576578 */
    577 function deactivate_plugins( $plugins, $silent = false ) {
     579function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) {
    578580        if ( is_multisite() )
    579581                $network_current = get_site_option( 'active_sitewide_plugins', array() );
    580582        $current = get_option( 'active_plugins', array() );
     
    585587                if ( ! is_plugin_active($plugin) )
    586588                        continue;
    587589
    588                 $network_wide = is_plugin_active_for_network( $plugin );
     590                $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin );
    589591
    590592                if ( ! $silent )
    591                         do_action( 'deactivate_plugin', $plugin, $network_wide );
     593                        do_action( 'deactivate_plugin', $plugin, $network_deactivating );
    592594
    593                 if ( $network_wide ) {
     595                if ( false !== $network_wide ) {
     596                        if ( ! is_plugin_active_for_network( $plugin ) )
     597                                continue;
    594598                        $do_network = true;
    595599                        unset( $network_current[ $plugin ] );
    596                 } else {
     600                }
     601
     602                if ( true !== $network_wide ) {
    597603                        $key = array_search( $plugin, $current );
    598604                        if ( false !== $key ) {
    599605                                $do_blog = true;
     
    602608                }
    603609
    604610                if ( ! $silent ) {
    605                         do_action( 'deactivate_' . $plugin, $network_wide );
    606                         do_action( 'deactivated_plugin', $plugin, $network_wide );
     611                        do_action( 'deactivate_' . $plugin, $network_deactivating );
     612                        do_action( 'deactivated_plugin', $plugin, $network_deactivating );
    607613                }
    608614        }
    609615
  • wp-admin/includes/class-wp-plugins-list-table.php

     
    1313                global $status, $page;
    1414
    1515                $status = 'all';
    16                 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'network', 'mustuse', 'dropins', 'search' ) ) )
     16                if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
    1717                        $status = $_REQUEST['plugin_status'];
    1818
    1919                if ( isset($_REQUEST['s']) )
     
    7878
    7979                set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 );
    8080
    81                 $recently_activated = get_option( 'recently_activated', array() );
     81                if ( ! $screen->is_network ) {
     82                        $recently_activated = get_option( 'recently_activated', array() );
    8283
    83                 $one_week = 7*24*60*60;
    84                 foreach ( $recently_activated as $key => $time )
    85                         if ( $time + $one_week < time() )
    86                                 unset( $recently_activated[$key] );
    87                 update_option( 'recently_activated', $recently_activated );
     84                        $one_week = 7*24*60*60;
     85                        foreach ( $recently_activated as $key => $time )
     86                                if ( $time + $one_week < time() )
     87                                        unset( $recently_activated[$key] );
     88                        update_option( 'recently_activated', $recently_activated );
     89                }
    8890
    8991                foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
    9092                        // Filter into individual sections
    91                         if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !$screen->is_network ) {
    92                                 unset( $plugins['all'][ $plugin_file] );
    93                         } elseif ( is_plugin_active_for_network($plugin_file) && !$screen->is_network ) {
     93                        if ( ! $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) {
    9494                                unset( $plugins['all'][ $plugin_file ] );
    95                         } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
    96                                 $plugins['network'][ $plugin_file ] = $plugin_data;
    97                         } elseif ( ( !$screen->is_network && is_plugin_active( $plugin_file ) )
     95                        } elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) )
    9896                                || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
    9997                                $plugins['active'][ $plugin_file ] = $plugin_data;
    10098                        } else {
     
    215213                                case 'inactive':
    216214                                        $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
    217215                                        break;
    218                                 case 'network':
    219                                         $text = _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $count );
    220                                         break;
    221216                                case 'mustuse':
    222217                                        $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
    223218                                        break;
     
    248243
    249244                $screen = get_current_screen();
    250245
    251                 if ( 'active' != $status ) {
    252                         $action = $screen->is_network ? 'network-activate-selected' : 'activate-selected';
    253                         $actions[ $action ] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
    254                 }
     246                if ( 'active' != $status )
     247                        $actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
    255248
    256249                if ( 'inactive' != $status && 'recent' != $status )
    257250                        $actions['deactivate-selected'] = $screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' );
     
    283276
    284277                echo '<div class="alignleft actions">';
    285278
    286                 if ( 'recently_activated' == $status )
     279                $screen = get_current_screen();
     280
     281                if ( ! $screen->is_network && 'recently_activated' == $status )
    287282                        submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false );
    288283                elseif ( 'top' == $which && 'mustuse' == $status )
    289284                        echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
     
    321316
    322317                // preorder
    323318                $actions = array(
    324                         'network_deactivate' => '', 'deactivate' => '',
    325                         'network_only' => '', 'activate' => '',
    326                         'network_activate' => '',
     319                        'deactivate' => '',
     320                        'activate' => '',
    327321                        'edit' => '',
    328322                        'delete' => '',
    329323                );
     
    348342                        if ( $plugin_data['Description'] )
    349343                                $description .= '<p>' . $plugin_data['Description'] . '</p>';
    350344                } else {
    351                         $is_active_for_network = is_plugin_active_for_network($plugin_file);
    352345                        if ( $screen->is_network )
    353                                 $is_active = $is_active_for_network;
     346                                $is_active = is_plugin_active_for_network( $plugin_file );
    354347                        else
    355348                                $is_active = is_plugin_active( $plugin_file );
    356349
    357                         if ( $is_active_for_network && !is_super_admin() && !$screen->is_network )
    358                                 return;
    359 
    360350                        if ( $screen->is_network ) {
    361                                 if ( $is_active_for_network ) {
     351                                if ( $is_active ) {
    362352                                        if ( current_user_can( 'manage_network_plugins' ) )
    363                                                 $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
     353                                                $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
    364354                                } else {
    365355                                        if ( current_user_can( 'manage_network_plugins' ) )
    366                                                 $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
     356                                                $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
    367357                                        if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) )
    368358                                                $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
    369359                                }
  • wp-admin/plugins.php

     
    1212if ( is_multisite() ) {
    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&#8217; uh?' ) );
    1717}
    1818
     
    3131$_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']);
    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 ) {
    3936                case 'activate':
     
    4239
    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() ) {
    4845                                        $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s");
     
    5350                                }
    5451                        }
    5552
    56                         $recent = (array)get_option('recently_activated');
    57                         if ( isset($recent[ $plugin ]) ) {
    58                                 unset($recent[ $plugin ]);
    59                                 update_option('recently_activated', $recent);
     53                        if ( ! is_network_admin() ) {
     54                                $recent = (array) get_option( 'recently_activated' );
     55                                unset( $recent[ $plugin ] );
     56                                update_option( 'recently_activated', $recent );
    6057                        }
     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
    6361                        } else {
     
    6664                        exit;
    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.'));
    7269
     
    7572                        $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    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 ) )
    8178                                        unset( $plugins[ $i ] );
     
    8582                                exit;
    8683                        }
    8784
    88                         activate_plugins($plugins, self_admin_url('plugins.php?error=true'), $network_wide);
     85                        activate_plugins($plugins, self_admin_url('plugins.php?error=true'), is_network_admin() );
    8986
    90                         $recent = (array)get_option('recently_activated');
    91                         foreach ( $plugins as $plugin => $time)
    92                                 if ( isset($recent[ $plugin ]) )
    93                                         unset($recent[ $plugin ]);
     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                        }
    9493
    95                         update_option('recently_activated', $recent);
    96 
    9794                        wp_redirect( self_admin_url("plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s") );
    9895                        exit;
    9996                        break;
     
    153150                                wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.'));
    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" ) . "' />";
    160164                        else
     
    168172                        check_admin_referer('bulk-plugins');
    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") );
    174184                                exit;
    175185                        }
    176186
    177                         deactivate_plugins($plugins);
     187                        deactivate_plugins( $plugins, false, is_network_admin() );
    178188
    179                         $deactivated = array();
    180                         foreach ( $plugins as $plugin )
    181                                 $deactivated[ $plugin ] = time();
     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                        }
    182195
    183                         update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
    184196                        wp_redirect( self_admin_url("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s") );
    185197                        exit;
    186198                        break;
     
    305317                        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        }
    311324}
  • wp-admin/plugin-editor.php

     
    6565                        if ( is_plugin_active($file) )
    6666                                deactivate_plugins($file, true);
    6767
    68                         update_option('recently_activated', array($file => time()) + (array)get_option('recently_activated'));
     68                        if ( ! is_network_admin() )
     69                                update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) );
    6970
    7071                        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));
    7172                        exit;