]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/update.php
Wordpress 2.7.1-scripts
[autoinstalls/wordpress.git] / wp-admin / update.php
1 <?php
2 /**
3  * Update Plugin/Theme administration panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
11
12 if ( ! current_user_can('update_plugins') )
13         wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
14
15 /**
16  * Plugin upgrade display.
17  *
18  * @since 2.5
19  *
20  * @param string $plugin Plugin
21  */
22 function do_plugin_upgrade($plugin) {
23         global $wp_filesystem;
24
25         $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin");
26         if ( false === ($credentials = request_filesystem_credentials($url)) )
27                 return;
28
29         if ( ! WP_Filesystem($credentials) ) {
30                 $error = true;
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
34                 return;
35         }
36
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);
42                 echo '</div>';
43                 return;
44         }
45
46         $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
47
48         $result = wp_update_plugin($plugin, 'show_message');
49
50         if ( is_wp_error($result) ) {
51                 show_message($result);
52                 show_message( __('Plugin upgrade Failed') );
53         } else {
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>';
59                 }
60                 $update_actions =  array(
61                         'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;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>'
63                 );
64                 if ( $was_activated )
65                         unset( $update_actions['activate_plugin'] );
66
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));
70         }
71         echo '</div>';
72 }
73
74 /**
75  * Theme upgrade display.
76  *
77  * @since 2.5
78  *
79  * @param string $plugin Plugin
80  */
81 function do_theme_upgrade($theme) {
82         global $wp_filesystem;
83
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)) )
86                 return;
87
88         if ( ! WP_Filesystem($credentials) ) {
89                 $error = true;
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
93                 return;
94         }
95
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);
101                 echo '</div>';
102                 return;
103         }
104
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
107
108         $result = wp_update_theme($theme, 'show_message');
109
110         if ( is_wp_error($result) ) {
111                 show_message($result);
112                 show_message( __('Installation Failed') );
113         } else {
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>';
120                 }
121         }
122         echo '</div>';
123 }
124
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'] : '';
129
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'] );
143                         die();
144                 }
145                 iframe_header( __('Plugin Reactivation'), true );
146                 if( isset($_GET['success']) )
147                         echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
148
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);
154                 }
155                 iframe_footer();
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');
163         }
164 }
165
166 ?>