Make WordPress Core

Ticket #14915: class-wp-upgrader.15646.2.diff

File class-wp-upgrader.15646.2.diff, 3.4 KB (added by joelhardi, 13 years ago)

newer patch per my comment (but slightly more complicated). Doesn't set and then immediately unset $update_actionsactivate_plugin?.

  • class-wp-upgrader.php

     
    422423                // Get the URL to the zip file
    423424                $r = $current->response[ $plugin ];
    424425
    425                 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
    426426                add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
    427427                //'source_selection' => array(&$this, 'source_selection'), //theres a track ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
    428428
     
    437437                                ));
    438438
    439439                // Cleanup our hooks, incase something else does a upgrade on this connection.
    440                 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
    441440                remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
    442441
    443442                if ( ! $this->result || is_wp_error($this->result) )
     
    546545                return $this->result['destination_name'] . '/' . $pluginfiles[0];
    547546        }
    548547
    549         //Hooked to pre_install
    550         function deactivate_plugin_before_upgrade($return, $plugin) {
    551 
    552                 if ( is_wp_error($return) ) //Bypass.
    553                         return $return;
    554 
    555                 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
    556                 if ( empty($plugin) )
    557                         return new WP_Error('bad_request', $this->strings['bad_request']);
    558 
    559                 if ( is_plugin_active($plugin) ) {
    560                         $this->skin->feedback('deactivate_plugin');
    561                         //Deactivate the plugin silently, Prevent deactivation hooks from running.
    562                         deactivate_plugins($plugin, true);
    563                 }
    564         }
    565 
    566548        //Hooked to upgrade_clear_destination
    567549        function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
    568550                global $wp_filesystem;
     
    10301012
    10311013        function after() {
    10321014                $this->plugin = $this->upgrader->plugin_info();
    1033                 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
    1034                         show_message(__('Reactivating the plugin…'));
    1035                         echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>';
    1036                 }
    10371015
    10381016                $update_actions =  array(
    1039                         'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
    10401017                        'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
    10411018                );
    1042                 if ( $this->plugin_active )
    1043                         unset( $update_actions['activate_plugin'] );
    1044                 if ( ! $this->result || is_wp_error($this->result) )
    1045                         unset( $update_actions['activate_plugin'] );
     1019                if ( !$this->plugin_active && !is_wp_error($this->result) && $this->result )
     1020                        $update_actions[ 'activate_plugin' ] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
    10461021
    10471022                $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
    10481023                if ( ! empty($update_actions) )