WordPress.org

Make WordPress Core

Changeset 7465


Ignore:
Timestamp:
03/21/2008 11:02:00 PM (10 years ago)
Author:
ryan
Message:

Deactivate plugins during plugin update. Props DD32. see #6262

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/plugin.php

    r7456 r7465  
    3232}
    3333
    34 function get_plugins() {
     34function get_plugins($plugin_folder = '') {
    3535    global $wp_plugins;
    3636
     
    4141    $wp_plugins = array ();
    4242    $plugin_root = ABSPATH . PLUGINDIR;
     43    if( !empty($plugin_folder) )
     44        $plugin_root .= $plugin_folder;
    4345
    4446    // Files in wp-content/plugins directory
     
    8789}
    8890
     91function is_plugin_active($plugin){
     92    return in_array($plugin, get_option('active_plugins'));
     93}
     94
    8995function activate_plugin($plugin, $redirect = '') {
    9096        $current = get_option('active_plugins');
     
    110116}
    111117
    112 function deactivate_plugins($plugins) {
     118function deactivate_plugins($plugins, $silent= false) {
    113119    $current = get_option('active_plugins');
    114120
     
    122128        if ( ( $key = array_search( $plugin, $current) ) !== false )
    123129            array_splice($current, $key, 1 ); // Fixed Array-fu!
    124         do_action('deactivate_' . trim( $plugin ));
     130        if ( ! $silent )
     131            do_action('deactivate_' . trim( $plugin ));
    125132    }
    126133
  • trunk/wp-admin/includes/update.php

    r7434 r7465  
    198198    unlink($file);
    199199
     200    if ( is_plugin_active($plugin) ) {
     201        //Deactivate the plugin
     202        apply_filters('update_feedback', __('Deactivating the plugin'));
     203        deactivate_plugins($plugin, true);
     204    }
     205
    200206    // Remove the existing plugin.
    201207    apply_filters('update_feedback', __('Removing the old version of the plugin'));
     
    204210   
    205211    // If plugin is in its own directory, recursively delete the directory.
    206     if( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' )
     212    if ( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' )
    207213        $deleted = $wp_filesystem->delete($plugin_dir, true);
    208214    else
     
    226232    // Force refresh of plugin update information
    227233    delete_option('update_plugins');
     234   
     235    //Return the new plugin file.
     236    if ( ! preg_match('!/([a-z0-9\-]+)/?$!i', $working_dir, $mat) )
     237        return false;
     238    $plugin = get_plugins('/' . $mat[1]); //Pass it with a leading slash
     239    $list = array_keys($plugin);
     240    return $mat[1] . '/' . $list[0]; //Pass it without a leading slash.
    228241}
    229242
  • trunk/wp-admin/update.php

    r7460 r7465  
    8787            $message = $message->get_error_message();
    8888    }
    89     echo "<p>$message</p>";
     89    echo "<p>$message</p>\n";
    9090}
    9191
     
    9696    if ( false === ($credentials = request_filesystem_credentials($url)) )
    9797        return;
    98        
    99     if( ! WP_Filesystem($credentials) ){
     98
     99    if ( ! WP_Filesystem($credentials) ) {
    100100        request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
    101101        return;
    102102    }
    103        
     103
    104104    echo '<div class="wrap">';
    105105    echo '<h2>' . __('Upgrade Plugin') . '</h2>';
     
    111111    }
    112112
     113    $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is,
     114
    113115    $result = wp_update_plugin($plugin, 'show_message');
    114116
    115     if ( is_wp_error($result) )
     117    if ( is_wp_error($result) ) {
    116118        show_message($result);
    117     else
    118         echo __('Plugin upgraded successfully');
     119    } else {
     120        //Result is the new plugin file relative to PLUGINDIR
     121        show_message(__('Plugin upgraded successfully'));   
     122        if( $result && $was_activated ){
     123            show_message(__('Attempting reactivation of the plugin'));
     124            echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>';
     125        }
     126    }
    119127    echo '</div>';
    120128}
    121129
    122130if ( isset($_GET['action']) ) {
    123     if ( isset($_GET['plugin']) )
    124         $plugin = trim($_GET['plugin']);
     131    $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : '';
    125132
    126133    if ( 'upgrade-plugin' == $_GET['action'] ) {
     
    131138        do_plugin_upgrade($plugin);
    132139        include('admin-footer.php');
     140    } elseif ('activate-plugin' == $_GET['action'] ) {
     141        check_admin_referer('activate-plugin_' . $plugin);
     142        if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
     143            wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
     144            activate_plugin($plugin);
     145            wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
     146            die();
     147        }
     148            ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     149<html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
     150<head>
     151<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
     152<title><?php bloginfo('name') ?> &rsaquo; <?php _e('Plugin Reactivation'); ?> &#8212; <?php _e('WordPress'); ?></title>
     153<?php
     154wp_admin_css( 'css/global' );
     155wp_admin_css( 'css/colors' );
     156?>
     157</head>
     158<body>
     159<?php
     160        if( isset($_GET['success']) )
     161            echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
     162
     163        if( isset($_GET['failure']) ){
     164            echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
     165            error_reporting( E_ALL ^ E_NOTICE );
     166            @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
     167            include(ABSPATH . PLUGINDIR . '/' . $plugin);
     168        }
     169        echo "</body></html>";
    133170    }
    134171}
Note: See TracChangeset for help on using the changeset viewer.