Make WordPress Core

Ticket #20241: allow_plugin_to_register_other_plugins_v2.patch

File allow_plugin_to_register_other_plugins_v2.patch, 2.1 KB (added by magnus78, 13 years ago)

proposed fix

  • wp-admin/includes/plugin.php

     
    522522                        do_action( 'activate_plugin', $plugin, $network_wide );
    523523                        do_action( 'activate_' . $plugin, $network_wide );
    524524                }
     525               
     526                // Check active_plugins again - the activated plugin may have activated
     527                // other plugins during activation.
     528                $current = get_option( 'active_plugins', array() );
    525529
    526530                if ( $network_wide ) {
    527531                        $current[$plugin] = time();
     
    558562 * @param bool $silent Prevent calling deactivation hooks. Default is false.
    559563 */
    560564function 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() );
    564565        $do_blog = $do_network = false;
    565566
    566567        foreach ( (array) $plugins as $plugin ) {
     
    573574                if ( ! $silent )
    574575                        do_action( 'deactivate_plugin', $plugin, $network_wide );
    575576
     577                if ( ! $silent ) {
     578                        do_action( 'deactivate_' . $plugin, $network_wide );
     579                        do_action( 'deactivated_plugin', $plugin, $network_wide );
     580                }
     581               
     582                // Check active plugins now, not earlier - the activated plugin may have
     583                // deactivated other plugins during deactivation.
     584                if ( is_multisite() )
     585                  $network_current = get_site_option( 'active_sitewide_plugins', array() );
     586                $current = get_option( 'active_plugins', array() );
     587
    576588                if ( $network_wide ) {
    577589                        $do_network = true;
    578590                        unset( $network_current[ $plugin ] );
     
    583595                                array_splice( $current, $key, 1 );
    584596                        }
    585597                }
    586 
    587                 if ( ! $silent ) {
    588                         do_action( 'deactivate_' . $plugin, $network_wide );
    589                         do_action( 'deactivated_plugin', $plugin, $network_wide );
    590                 }
     598               
     599                if ( $do_blog )
     600                  update_option('active_plugins', $current);
     601                if ( $do_network )
     602                  update_site_option( 'active_sitewide_plugins', $network_current );
    591603        }
    592 
    593         if ( $do_blog )
    594                 update_option('active_plugins', $current);
    595         if ( $do_network )
    596                 update_site_option( 'active_sitewide_plugins', $network_current );
    597604}
    598605
    599606/**