Ticket #6262: 6262.2.diff
| File 6262.2.diff, 5.9 kB (added by DD32, 8 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); … … 86 88 return $wp_plugins; 87 89 } 88 90 91 function is_plugin_active($plugin){ 92 return in_array($plugin, get_option('active_plugins')); 93 } 94 89 95 function activate_plugin($plugin, $redirect = '') { 90 96 $current = get_option('active_plugins'); 91 97 $plugin = trim($plugin); … … 109 115 return null; 110 116 } 111 117 112 function deactivate_plugins($plugins ) {118 function deactivate_plugins($plugins, $silent= false) { 113 119 $current = get_option('active_plugins'); 114 120 115 121 if ( !is_array($plugins) ) … … 121 127 continue; 122 128 if ( ( $key = array_search( $plugin, $current) ) !== false ) 123 129 array_splice($current, $key, 1 ); // Fixed Array-fu! 124 do_action('deactivate_' . trim( $plugin )); 130 if ( ! $silent ) 131 do_action('deactivate_' . trim( $plugin )); 125 132 } 126 133 127 134 update_option('active_plugins', $current); -
wp-admin/includes/update.php
old new 197 197 // Once installed, delete the package 198 198 unlink($file); 199 199 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 200 206 // Remove the existing plugin. 201 207 apply_filters('update_feedback', __('Removing the old version of the plugin')); 202 208 $plugin_dir = dirname($base . PLUGINDIR . "/$plugin"); … … 225 231 226 232 // Force refresh of plugin update information 227 233 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. 228 241 } 229 242 230 243 ?> -
wp-admin/update.php
old new 86 86 else 87 87 $message = $message->get_error_message(); 88 88 } 89 echo "<p>$message</p> ";89 echo "<p>$message</p>\n"; 90 90 } 91 91 92 92 function do_plugin_upgrade($plugin) { … … 95 95 $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin"); 96 96 if ( false === ($credentials = request_filesystem_credentials($url)) ) 97 97 return; 98 98 99 99 if( ! WP_Filesystem($credentials) ){ 100 100 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again 101 101 return; 102 102 } 103 103 104 104 echo '<div class="wrap">'; 105 105 echo '<h2>' . __('Upgrade Plugin') . '</h2>'; 106 106 if ( $wp_filesystem->errors->get_error_code() ) { … … 110 110 return; 111 111 } 112 112 113 $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is, 114 113 115 $result = wp_update_plugin($plugin, 'show_message'); 114 116 115 if ( is_wp_error($result) ) 117 if ( is_wp_error($result) ){ 116 118 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 } 119 127 echo '</div>'; 120 128 } 121 129 122 130 if ( isset($_GET['action']) ) { 123 if ( isset($_GET['plugin']) ) 124 $plugin = trim($_GET['plugin']); 131 $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : ''; 125 132 126 133 if ( 'upgrade-plugin' == $_GET['action'] ) { 127 134 check_admin_referer('upgrade-plugin_' . $plugin); … … 130 137 require_once('admin-header.php'); 131 138 do_plugin_upgrade($plugin); 132 139 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') ?> › <?php _e('Plugin Reactivation'); ?> — <?php _e('WordPress'); ?></title> 153 <?php 154 wp_admin_css( 'css/global' ); 155 wp_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>"; 133 170 } 134 171 } 135 172
