Ticket #6262: 6262.diff
| File 6262.diff, 5.6 kB (added by DD32, 9 months ago) |
|---|
-
wp-admin/includes/plugin.php
old new 31 31 return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version); 32 32 } 33 33 34 function get_plugins( ) {34 function get_plugins($plugin_folder = '') { 35 35 global $wp_plugins; 36 36 37 37 if ( isset( $wp_plugins ) ) { … … 40 40 41 41 $wp_plugins = array (); 42 42 $plugin_root = ABSPATH . PLUGINDIR; 43 if( !empty($plugin_folder) ) 44 $plugin_root .= $plugin_folder; 43 45 44 46 // Files in wp-content/plugins directory 45 47 $plugins_dir = @ opendir( $plugin_root); … … 109 111 return null; 110 112 } 111 113 112 function deactivate_plugins($plugins ) {114 function deactivate_plugins($plugins, $silent= false) { 113 115 $current = get_option('active_plugins'); 114 116 115 117 if ( !is_array($plugins) ) … … 120 122 if( false === $item) 121 123 continue; 122 124 array_splice($current, $item, 1 ); // Array-fu! 123 do_action('deactivate_' . trim( $plugin )); 125 if ( ! $silent ) 126 do_action('deactivate_' . trim( $plugin )); 124 127 } 125 128 126 129 update_option('active_plugins', $current); -
wp-admin/includes/update.php
old new 191 191 // Once installed, delete the package 192 192 unlink($file); 193 193 194 //Deactivate the plugin 195 apply_filters('deactivate_plugin', __('Deactivating the plugin')); 196 deactivate_plugins($plugin, true); 197 194 198 // Remove the existing plugin. 195 199 apply_filters('update_feedback', __('Removing the old version of the plugin')); 196 200 $plugin_dir = dirname($base . PLUGINDIR . "/$plugin"); … … 219 223 220 224 // Force refresh of plugin update information 221 225 delete_option('update_plugins'); 226 227 //Return the new plugin file. 228 if( ! preg_match('!/([a-z0-9\-]+)/?$!i', $working_dir, $mat) ) 229 return false; 230 $plugin = get_plugins('/' . $mat[1]); //Pass it with a leading slash 231 $list = array_keys($plugin); 232 return $mat[1] . '/' . $list[0]; //Pass it without a leading slash. 222 233 } 223 234 224 235 ?> -
wp-admin/update.php
old new 82 82 else 83 83 $message = $message->get_error_message(); 84 84 } 85 echo "<p>$message</p> ";85 echo "<p>$message</p>\n"; 86 86 } 87 87 88 88 function do_plugin_upgrade($plugin) { … … 91 91 $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin"); 92 92 if ( false === ($credentials = request_filesystem_credentials($url)) ) 93 93 return; 94 94 95 95 if( ! WP_Filesystem($credentials) ){ 96 96 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again 97 97 return; 98 98 } 99 99 100 100 echo '<div class="wrap">'; 101 101 echo '<h2>' . __('Upgrade Plugin') . '</h2>'; 102 102 if ( $wp_filesystem->errors->get_error_code() ) { … … 106 106 return; 107 107 } 108 108 109 //Todo: is_plugin_active() wrapper? 110 $was_activated = in_array($plugin, get_option('active_plugins')); 111 109 112 $result = wp_update_plugin($plugin, 'show_message'); 110 113 111 if ( is_wp_error($result) ) 114 if ( is_wp_error($result) ){ 112 115 show_message($result); 113 else 114 echo __('Plugin upgraded successfully'); 116 } else { 117 //Result is the new plugin file relative to PLUGINDIR 118 show_message(__('Plugin upgraded successfully')); 119 if( $result && $was_activated ){ 120 show_message(__('Attempting reactivation of the plugin')); 121 echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>'; 122 } 123 } 115 124 echo '</div>'; 116 125 } 117 126 118 127 if ( isset($_GET['action']) ) { 119 if ( isset($_GET['plugin']) ) 120 $plugin = trim($_GET['plugin']); 128 $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : ''; 121 129 122 130 if ( 'upgrade-plugin' == $_GET['action'] ) { 123 131 check_admin_referer('upgrade-plugin_' . $plugin); … … 126 134 require_once('admin-header.php'); 127 135 do_plugin_upgrade($plugin); 128 136 include('admin-footer.php'); 137 } elseif ('activate-plugin' == $_GET['action'] ) { 138 check_admin_referer('activate-plugin_' . $plugin); 139 if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) { 140 wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] ); 141 activate_plugin($plugin); 142 wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] ); 143 die(); 144 } 145 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 146 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>> 147 <head> 148 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> 149 <title><?php bloginfo('name') ?> › <?php _e('Plugin Reactivation'); ?> — <?php _e('WordPress'); ?></title> 150 <?php 151 wp_admin_css( 'css/global' ); 152 wp_admin_css( 'css/colors' ); 153 ?> 154 </head> 155 <body> 156 <?php 157 if( isset($_GET['success']) ) 158 echo '<p>' . __('Plugin reactivated successfully.') . '</p>'; 159 160 if( isset($_GET['failure']) ){ 161 echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>'; 162 error_reporting( E_ALL ^ E_NOTICE ); 163 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed. 164 include(ABSPATH . PLUGINDIR . '/' . $plugin); 165 } 166 echo "</body></html>"; 129 167 } 130 168 } 131 169
