WordPress.org

Make WordPress Core

Ticket #22704: 22704-reactivate-plugins.patch

File 22704-reactivate-plugins.patch, 1.9 KB (added by kurtpayne, 3 years ago)

Reactivate plugins after updating

  • wp-admin/includes/class-wp-upgrader.php

     
    482482 
    483483                add_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'), 10, 2); 
    484484                add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4); 
     485                add_filter( 'upgrader_post_install', array( $this, 'activate_plugin_after_upgrade' ), 10, 3 ); 
    485486                //'source_selection' => array($this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins. 
    486487 
    487488                $this->run( array( 
     
    497498                // Cleanup our hooks, in case something else does a upgrade on this connection. 
    498499                remove_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade')); 
    499500                remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin')); 
     501                remove_filter( 'upgrader_post_install', array( $this, 'activate_plugin_after_upgrade' ) ); 
    500502 
    501503                if ( ! $this->result || is_wp_error($this->result) ) 
    502504                        return $this->result; 
     
    660662                } 
    661663        } 
    662664 
     665        /** 
     666         * Re-activate a plugin after it's been upgraded 
     667         * @param bool $return 
     668         * @param array $plugin 
     669         * @return null|WP_Error 
     670         */ 
     671        function activate_plugin_after_upgrade( $return, $plugin ) { 
     672                $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; 
     673                if ( empty( $plugin ) ) 
     674                        return new WP_Error( 'bad_request', $this->strings['bad_request'] ); 
     675 
     676                if ( is_plugin_active( $plugin ) ) 
     677                        return $return; 
     678 
     679                return activate_plugin( $plugin, '', false, true ); 
     680        } 
     681         
    663682        //Hooked to upgrade_clear_destination 
    664683        function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) { 
    665684                global $wp_filesystem;