Make WordPress Core

Ticket #37470: 37470.2.diff

File 37470.2.diff, 1.2 KB (added by Otto42, 8 years ago)

Minimal patch to deactivate and reactivate the plugin during upgrades via ajax actions

  • wp-admin/includes/ajax-actions.php

     
    36783678
    36793679        wp_update_plugins();
    36803680
     3681        // save whether the plugin is active or not
     3682        $plugin_active = is_plugin_active( $plugin );
     3683        $plugin_network_active = is_plugin_active_for_network( $plugin );
     3684       
     3685        // silently deactivates the plugin prior to upgrading it
     3686        add_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'), 10, 2);
     3687
    36813688        $skin     = new Automatic_Upgrader_Skin();
    36823689        $upgrader = new Plugin_Upgrader( $skin );
    36833690        $result   = $upgrader->bulk_upgrade( array( $plugin ) );
     
    36913698        }
    36923699
    36933700        if ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) {
     3701       
     3702                // Silently reactivate the plugin afterwards
     3703                if ( !is_wp_error( $result ) && $plugin_active ) {
     3704                        // plugin_info() is called in case the main plugin file name changed
     3705                        $plugin = $upgrader->plugin_info();
     3706                        activate_plugin( $plugin, '', $plugin_network_active, true );
     3707                }
     3708               
    36943709                $plugin_update_data = current( $result );
    36953710
    36963711                /*