3 * Update Plugin/Theme administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 if ( ! current_user_can('update_plugins') )
13 wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
16 * Plugin upgrade display.
20 * @param string $plugin Plugin
22 function do_plugin_upgrade($plugin) {
23 global $wp_filesystem;
25 $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin");
26 if ( false === ($credentials = request_filesystem_credentials($url)) )
29 if ( ! WP_Filesystem($credentials) ) {
31 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
32 $error = $wp_filesystem->errors;
33 request_filesystem_credentials($url, '', $error); //Failed to connect, Error and request again
37 echo '<div class="wrap">';
38 echo '<h2>' . __('Upgrade Plugin') . '</h2>';
39 if ( $wp_filesystem->errors->get_error_code() ) {
40 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
41 show_message($message);
46 $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
48 $result = wp_update_plugin($plugin, 'show_message');
50 if ( is_wp_error($result) ) {
51 show_message($result);
52 show_message( __('Plugin upgrade Failed') );
54 $plugin_file = $result;
55 show_message( __('Plugin upgraded successfully') );
56 if( $result && $was_activated ){
57 show_message(__('Attempting reactivation of the plugin'));
58 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) .'"></iframe>';
60 $update_actions = array(
61 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . attribute_escape(__('Activate this plugin')) . '" target="_parent">' . __('Activate Plugin') . '</a>',
62 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . attribute_escape(__('Goto plugins page')) . '" target="_parent">' . __('Return to Plugins page') . '</a>'
65 unset( $update_actions['activate_plugin'] );
67 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $plugin_file);
68 if ( ! empty($update_actions) )
69 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
75 * Theme upgrade display.
79 * @param string $plugin Plugin
81 function do_theme_upgrade($theme) {
82 global $wp_filesystem;
84 $url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($theme), 'upgrade-plugin_' . urlencode($theme));
85 if ( false === ($credentials = request_filesystem_credentials($url)) )
88 if ( ! WP_Filesystem($credentials) ) {
90 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
91 $error = $wp_filesystem->errors;
92 request_filesystem_credentials($url, '', $error); //Failed to connect, Error and request again
96 echo '<div class="wrap">';
97 echo '<h2>' . __('Upgrade Theme') . '</h2>';
98 if ( $wp_filesystem->errors->get_error_code() ) {
99 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
100 show_message($message);
105 //TODO: Is theme currently active?
106 $was_current = false; //is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
108 $result = wp_update_theme($theme, 'show_message');
110 if ( is_wp_error($result) ) {
111 show_message($result);
112 show_message( __('Installation Failed') );
114 //Result is the new plugin file relative to WP_PLUGIN_DIR
115 show_message( __('Theme upgraded successfully') );
116 if( $result && $was_current ){
117 show_message(__('Setting theme as Current'));
118 //TODO: Actually set it as active again.
119 //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 if ( isset($_GET['action']) ) {
126 $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : '';
127 $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
128 $action = isset($_GET['action']) ? $_GET['action'] : '';
130 if ( 'upgrade-plugin' == $action ) {
131 check_admin_referer('upgrade-plugin_' . $plugin);
132 $title = __('Upgrade Plugin');
133 $parent_file = 'plugins.php';
134 require_once('admin-header.php');
135 do_plugin_upgrade($plugin);
136 include('admin-footer.php');
137 } elseif ('activate-plugin' == $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'] );
145 iframe_header( __('Plugin Reactivation'), true );
146 if( isset($_GET['success']) )
147 echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
149 if( isset($_GET['failure']) ){
150 echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
151 error_reporting( E_ALL ^ E_NOTICE );
152 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
153 include(WP_PLUGIN_DIR . '/' . $plugin);
156 } elseif ( 'upgrade-theme' == $action ) {
157 check_admin_referer('upgrade-theme_' . $theme);
158 $title = __('Upgrade Theme');
159 $parent_file = 'themes.php';
160 require_once('admin-header.php');
161 do_theme_upgrade($theme);
162 include('admin-footer.php');