Make WordPress Core

Ticket #20241: 20241.diff

File 20241.diff, 7.3 KB (added by nacin, 11 years ago)
  • src/wp-admin/includes/plugin.php

     
    541541
    542542                if ( ! $silent ) {
    543543                        /**
    544                          * Fires before a plugin is activated in activate_plugin() when the $silent parameter is false.
     544                         * Fires before a plugin is activated in activate_plugin().
     545                         *
     546                         * Does not fire when a plugin is "silently" activated, such as during updates.
    545547                         *
    546548                         * @since 2.9.0
    547549                         *
    548550                         * @param string $plugin       Plugin path to main plugin file with plugin data.
    549                          * @param bool   $network_wide Whether to enable the plugin for all sites in the network
     551                         * @param bool   $network_wide Whether the plugin is being enabled for all sites in the network
    550552                         *                             or just the current site. Multisite only. Default is false.
    551553                         */
    552554                        do_action( 'activate_plugin', $plugin, $network_wide );
    553555
    554556                        /**
    555                          * Fires before a plugin is activated in activate_plugin() when the $silent parameter is false.
     557                         * Fires as a plugin is being activated in activate_plugin().
     558                         *
     559                         * Does not fire when a plugin is "silently" activated, such as during updates.
    556560                         *
     561                         * This is the hook used by register_activation_hook().
     562                         *
    557563                         * The action concatenates the 'activate_' prefix with the $plugin value passed to
    558564                         * activate_plugin() to create a dynamically-named action.
    559565                         *
    560566                         * @since 2.0.0
    561567                         *
    562                          * @param bool $network_wide Whether to enable the plugin for all sites in the network
     568                         * @param bool $network_wide Whether the plugin is being enabled for all sites in the network
    563569                         *                           or just the current site. Multisite only. Default is false.
    564570                         */
    565571                        do_action( 'activate_' . $plugin, $network_wide );
     
    566572                }
    567573
    568574                if ( $network_wide ) {
     575                        // Refresh this in case a plugin performed any (de)activations.
     576                        $current = get_site_option( 'active_sitewide_plugins', array() );
    569577                        $current[$plugin] = time();
    570578                        update_site_option( 'active_sitewide_plugins', $current );
    571579                } else {
     580                        // Refresh this in case a plugin performed any (de)activations.
     581                        $current = get_option( 'active_plugins', array() );
    572582                        $current[] = $plugin;
    573583                        sort($current);
    574584                        update_option('active_plugins', $current);
     
    576586
    577587                if ( ! $silent ) {
    578588                        /**
    579                          * Fires after a plugin has been activated in activate_plugin() when the $silent parameter is false.
     589                         * Fires after a plugin has been activated in activate_plugin().
     590                         *
     591                         * Does not fire when a plugin is "silently" activated, such as during updates.
    580592                         *
    581593                         * @since 2.9.0
    582594                         *
    583595                         * @param string $plugin       Plugin path to main plugin file with plugin data.
    584                          * @param bool   $network_wide Whether to enable the plugin for all sites in the network
    585                          *                             or just the current site. Multisite only. Default is false.
     596                         * @param bool $network_wide Whether the plugin was enabled for all sites in the network
     597                         *                           or just the current site. Multisite only. Default is false.
    586598                         */
    587599                        do_action( 'activated_plugin', $plugin, $network_wide );
    588600                }
     
    611623 *      A value of null (the default) will deactivate plugins for both the site and the network.
    612624 */
    613625function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) {
    614         if ( is_multisite() )
    615                 $network_current = get_site_option( 'active_sitewide_plugins', array() );
    616626        $current = get_option( 'active_plugins', array() );
    617         $do_blog = $do_network = false;
     627        $do_blog = $do_network = array();
    618628
    619629        foreach ( (array) $plugins as $plugin ) {
    620630                $plugin = plugin_basename( trim( $plugin ) );
     
    623633
    624634                $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin );
    625635
    626                 if ( ! $silent )
     636                if ( ! $silent ) {
    627637                        /**
    628                          * Fires for each plugin being deactivated in deactivate_plugins(), before deactivation
    629                          * and when the $silent parameter is false.
     638                         * Fires for each plugin being deactivated in deactivate_plugins().
     639                         *
     640                         * Does not fire when a plugin is "silently" deactivated, such as during updates.
    630641                         *
    631642                         * @since 2.9.0
    632643                         *
    633644                         * @param string $plugin               Plugin path to main plugin file with plugin data.
    634                          * @param bool   $network_deactivating Whether the plugin is deactivated for all sites in the network
     645                         * @param bool   $network_deactivating Whether the plugin is being deactivated for all sites in the network
    635646                         *                                     or just the current site. Multisite only. Default is false.
    636647                         */
    637648                        do_action( 'deactivate_plugin', $plugin, $network_deactivating );
     649                }
    638650
    639651                if ( false !== $network_wide ) {
    640652                        if ( is_plugin_active_for_network( $plugin ) ) {
    641                                 $do_network = true;
    642                                 unset( $network_current[ $plugin ] );
     653                                $do_network[ $plugin ] = true;
    643654                        } elseif ( $network_wide ) {
    644655                                continue;
    645656                        }
     
    648659                if ( true !== $network_wide ) {
    649660                        $key = array_search( $plugin, $current );
    650661                        if ( false !== $key ) {
    651                                 $do_blog = true;
    652                                 unset( $current[ $key ] );
     662                                $do_blog[ $key ] = true;
    653663                        }
    654664                }
    655665
    656666                if ( ! $silent ) {
    657667                        /**
    658                          * Fires for each plugin being deactivated in deactivate_plugins(), after deactivation
    659                          * and when the $silent parameter is false.
     668                         * Fires for each plugin being deactivated in deactivate_plugins().
     669                         *
     670                         * Does not fire when a plugin is "silently" deactivated, such as during updates.
    660671                         *
     672                         * This is the hook used by register_deactivation_hook().
     673                         *
    661674                         * The action concatenates the 'deactivate_' prefix with the plugin's basename
    662675                         * to create a dynamically-named action.
    663676                         *
    664677                         * @since 2.0.0
    665678                         *
    666                          * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network
     679                         * @param bool $network_deactivating Whether the plugin is being deactivated for all sites in the network
    667680                         *                                   or just the current site. Multisite only. Default is false.
    668681                         */
    669682                        do_action( 'deactivate_' . $plugin, $network_deactivating );
    670683
    671684                        /**
    672                          * Fires for each plugin being deactivated in deactivate_plugins(), after deactivation
    673                          * and when the $silent parameter is false.
     685                         * Fires for each plugin being deactivated in deactivate_plugins()
    674686                         *
    675687                         * @since 2.9.0
    676688                         *
    677689                         * @param string $plugin               Plugin path to main plugin file with plugin data.
    678                          * @param bool   $network_deactivating Whether the plugin is deactivated for all sites in the network
     690                         * @param bool   $network_deactivating Whether the plugin was deactivated for all sites in the network
    679691                         *                                     or just the current site. Multisite only. Default is false.
    680692                         */
    681693                        do_action( 'deactivated_plugin', $plugin, $network_deactivating );
     
    682694                }
    683695        }
    684696
    685         if ( $do_blog )
     697        if ( $do_blog ) {
     698                $current = get_option( 'active_plugins', array() );
     699                $current = array_diff_key( $current, $do_blog );
    686700                update_option('active_plugins', $current);
    687         if ( $do_network )
     701        }
     702        if ( $do_network ) {
     703                $network_current = get_site_option( 'active_sitewide_plugins', array() );
     704                $network_current = array_diff_key( $network_current, $do_network );
    688705                update_site_option( 'active_sitewide_plugins', $network_current );
     706        }
    689707}
    690708
    691709/**