Make WordPress Core

Ticket #20241: wptrac20241_allow_plugin_to_register_other_plugins_v3.patch

File wptrac20241_allow_plugin_to_register_other_plugins_v3.patch, 2.5 KB (added by magnus78, 13 years ago)

proposed fix, v3

  • wp-admin/includes/plugin.php

     
    522522                        do_action( 'activate_plugin', $plugin, $network_wide );
    523523                        do_action( 'activate_' . $plugin, $network_wide );
    524524                }
    525 
    526525                if ( $network_wide ) {
     526                        // Check active_plugins again - the activated plugin may have activated
     527                        // other plugins during activation.
     528                        $current = get_site_option( 'active_sitewide_plugins', array() );
    527529                        $current[$plugin] = time();
    528530                        update_site_option( 'active_sitewide_plugins', $current );
    529531                } else {
     532                        // Check active_sitewide_plugins again - the activated plugin may have
     533                        // activated other plugins during activation.
     534                        $current = get_option( 'active_plugins', array() );
    530535                        $current[] = $plugin;
    531536                        sort($current);
    532537                        update_option('active_plugins', $current);
     
    558563 * @param bool $silent Prevent calling deactivation hooks. Default is false.
    559564 */
    560565function deactivate_plugins( $plugins, $silent = false ) {
    561         if ( is_multisite() )
    562                 $network_current = get_site_option( 'active_sitewide_plugins', array() );
    563         $current = get_option( 'active_plugins', array() );
    564566        $do_blog = $do_network = false;
    565567
    566568        foreach ( (array) $plugins as $plugin ) {
     
    570572
    571573                $network_wide = is_plugin_active_for_network( $plugin );
    572574
    573                 if ( ! $silent )
     575                if ( ! $silent ) {
    574576                        do_action( 'deactivate_plugin', $plugin, $network_wide );
     577                        do_action( 'deactivate_' . $plugin, $network_wide );
     578                        do_action( 'deactivated_plugin', $plugin, $network_wide );
     579                }
     580               
     581                // Check active plugins now, not earlier - the activated plugin may have
     582                // deactivated other plugins during deactivation.
     583                if ( is_multisite() )
     584                  $network_current = get_site_option( 'active_sitewide_plugins', array() );
     585                $current = get_option( 'active_plugins', array() );
    575586
    576587                if ( $network_wide ) {
    577588                        $do_network = true;
     
    583594                                array_splice( $current, $key, 1 );
    584595                        }
    585596                }
    586 
    587                 if ( ! $silent ) {
    588                         do_action( 'deactivate_' . $plugin, $network_wide );
    589                         do_action( 'deactivated_plugin', $plugin, $network_wide );
    590                 }
     597               
     598                if ( $do_blog )
     599                  update_option('active_plugins', $current);
     600                if ( $do_network )
     601                  update_site_option( 'active_sitewide_plugins', $network_current );
    591602        }
    592 
    593         if ( $do_blog )
    594                 update_option('active_plugins', $current);
    595         if ( $do_network )
    596                 update_site_option( 'active_sitewide_plugins', $network_current );
    597603}
    598604
    599605/**