PageRenderTime 23ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/php/wp-admin/update-core.php

https://bitbucket.org/cubeee/wp-fin
PHP | 631 lines | 509 code | 90 blank | 32 comment | 136 complexity | 9c86a314666baebfc6384a02258a159c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Update Core administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once( dirname( __FILE__ ) . '/admin.php' );
  10. wp_enqueue_style( 'plugin-install' );
  11. wp_enqueue_script( 'plugin-install' );
  12. add_thickbox();
  13. if ( is_multisite() && ! is_network_admin() ) {
  14. wp_redirect( network_admin_url( 'update-core.php' ) );
  15. exit();
  16. }
  17. if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) )
  18. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  19. function list_core_update( $update ) {
  20. global $wp_local_package, $wpdb, $wp_version;
  21. static $first_pass = true;
  22. if ( 'en_US' == $update->locale && 'en_US' == get_locale() )
  23. $version_string = $update->current;
  24. // If the only available update is a partial builds, it doesn't need a language-specific version string.
  25. elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version && ( $updates = get_core_updates() ) && 1 == count( $updates ) )
  26. $version_string = $update->current;
  27. else
  28. $version_string = sprintf( "%s&ndash;<strong>%s</strong>", $update->current, $update->locale );
  29. $current = false;
  30. if ( !isset($update->response) || 'latest' == $update->response )
  31. $current = true;
  32. $submit = __('Update Now');
  33. $form_action = 'update-core.php?action=do-core-upgrade';
  34. $php_version = phpversion();
  35. $mysql_version = $wpdb->db_version();
  36. $show_buttons = true;
  37. if ( 'development' == $update->response ) {
  38. $message = __('You are using a development version of WordPress. You can update to the latest nightly build automatically or download the nightly build and install it manually:');
  39. $download = __('Download nightly build');
  40. } else {
  41. if ( $current ) {
  42. $message = sprintf( __( 'If you need to re-install version %s, you can do so here or download the package and re-install manually:' ), $version_string );
  43. $submit = __('Re-install Now');
  44. $form_action = 'update-core.php?action=do-core-reinstall';
  45. } else {
  46. $php_compat = version_compare( $php_version, $update->php_version, '>=' );
  47. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
  48. $mysql_compat = true;
  49. else
  50. $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
  51. if ( !$mysql_compat && !$php_compat )
  52. $message = sprintf( __('You cannot update because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $update->current, $update->php_version, $update->mysql_version, $php_version, $mysql_version );
  53. elseif ( !$php_compat )
  54. $message = sprintf( __('You cannot update because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher. You are running version %3$s.'), $update->current, $update->php_version, $php_version );
  55. elseif ( !$mysql_compat )
  56. $message = sprintf( __('You cannot update because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires MySQL version %2$s or higher. You are running version %3$s.'), $update->current, $update->mysql_version, $mysql_version );
  57. else
  58. $message = sprintf(__('You can update to <a href="http://codex.wordpress.org/Version_%1$s">WordPress %2$s</a> automatically or download the package and install it manually:'), $update->current, $version_string);
  59. if ( !$mysql_compat || !$php_compat )
  60. $show_buttons = false;
  61. }
  62. $download = sprintf(__('Download %s'), $version_string);
  63. }
  64. echo '<p>';
  65. echo $message;
  66. echo '</p>';
  67. echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
  68. wp_nonce_field('upgrade-core');
  69. echo '<p>';
  70. echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
  71. echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
  72. if ( $show_buttons ) {
  73. if ( $first_pass ) {
  74. submit_button( $submit, $current ? 'button' : 'primary regular', 'upgrade', false );
  75. $first_pass = false;
  76. } else {
  77. submit_button( $submit, 'button', 'upgrade', false );
  78. }
  79. echo '&nbsp;<a href="' . esc_url( $update->download ) . '" class="button">' . $download . '</a>&nbsp;';
  80. }
  81. if ( 'en_US' != $update->locale )
  82. if ( !isset( $update->dismissed ) || !$update->dismissed )
  83. submit_button( __('Hide this update'), 'button', 'dismiss', false );
  84. else
  85. submit_button( __('Bring back this update'), 'button', 'undismiss', false );
  86. echo '</p>';
  87. if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
  88. echo '<p class="hint">'.__('This localized version contains both the translation and various other localization fixes. You can skip upgrading if you want to keep your current translation.').'</p>';
  89. // Partial builds don't need language-specific warnings.
  90. elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
  91. echo '<p class="hint">'.sprintf( __('You are about to install WordPress %s <strong>in English (US).</strong> There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.'), $update->response != 'development' ? $update->current : '' ).'</p>';
  92. }
  93. echo '</form>';
  94. }
  95. function dismissed_updates() {
  96. $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
  97. if ( $dismissed ) {
  98. $show_text = esc_js(__('Show hidden updates'));
  99. $hide_text = esc_js(__('Hide hidden updates'));
  100. ?>
  101. <script type="text/javascript">
  102. jQuery(function($) {
  103. $('dismissed-updates').show();
  104. $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
  105. $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
  106. });
  107. </script>
  108. <?php
  109. echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
  110. echo '<ul id="dismissed-updates" class="core-updates dismissed">';
  111. foreach( (array) $dismissed as $update) {
  112. echo '<li>';
  113. list_core_update( $update );
  114. echo '</li>';
  115. }
  116. echo '</ul>';
  117. }
  118. }
  119. /**
  120. * Display upgrade WordPress for downloading latest or upgrading automatically form.
  121. *
  122. * @since 2.7
  123. *
  124. * @return null
  125. */
  126. function core_upgrade_preamble() {
  127. global $wp_version, $required_php_version, $required_mysql_version;
  128. $updates = get_core_updates();
  129. if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
  130. echo '<h3>';
  131. _e('You have the latest version of WordPress.');
  132. if ( wp_http_supports( array( 'ssl' ) ) ) {
  133. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  134. $upgrader = new WP_Automatic_Updater;
  135. $future_minor_update = (object) array(
  136. 'current' => $wp_version . '.1.next.minor',
  137. 'version' => $wp_version . '.1.next.minor',
  138. 'php_version' => $required_php_version,
  139. 'mysql_version' => $required_mysql_version,
  140. );
  141. $should_auto_update = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
  142. if ( $should_auto_update )
  143. echo ' ' . __( 'Future security updates will be applied automatically.' );
  144. }
  145. echo '</h3>';
  146. } else {
  147. echo '<div class="updated inline"><p>';
  148. _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">back up your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.');
  149. echo '</p></div>';
  150. echo '<h3 class="response">';
  151. _e( 'An updated version of WordPress is available.' );
  152. echo '</h3>';
  153. }
  154. if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) {
  155. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  156. $upgrader = new WP_Automatic_Updater;
  157. if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) )
  158. echo '<div class="updated inline"><p><strong>BETA TESTERS:</strong> This site is set up to install updates of future beta versions automatically.</p></div>';
  159. }
  160. echo '<ul class="core-updates">';
  161. $alternate = true;
  162. foreach( (array) $updates as $update ) {
  163. echo '<li>';
  164. list_core_update( $update );
  165. echo '</li>';
  166. }
  167. echo '</ul>';
  168. // Don't show the maintenance mode notice when we are only showing a single re-install option.
  169. if ( $updates && ( count( $updates ) > 1 || $updates[0]->response != 'latest' ) ) {
  170. echo '<p>' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, your site will return to normal.' ) . '</p>';
  171. } elseif ( ! $updates ) {
  172. list( $normalized_version ) = explode( '-', $wp_version );
  173. echo '<p>' . sprintf( __( '<a href="%s">Learn more about WordPress %s</a>.' ), esc_url( self_admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
  174. }
  175. dismissed_updates();
  176. }
  177. function list_plugin_updates() {
  178. global $wp_version;
  179. $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
  180. require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
  181. $plugins = get_plugin_updates();
  182. if ( empty( $plugins ) ) {
  183. echo '<h3>' . __( 'Plugins' ) . '</h3>';
  184. echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
  185. return;
  186. }
  187. $form_action = 'update-core.php?action=do-plugin-upgrade';
  188. $core_updates = get_core_updates();
  189. if ( !isset($core_updates[0]->response) || 'latest' == $core_updates[0]->response || 'development' == $core_updates[0]->response || version_compare( $core_updates[0]->current, $cur_wp_version, '=') )
  190. $core_update_version = false;
  191. else
  192. $core_update_version = $core_updates[0]->current;
  193. ?>
  194. <h3><?php _e( 'Plugins' ); ?></h3>
  195. <p><?php _e( 'The following plugins have new versions available. Check the ones you want to update and then click &#8220;Update Plugins&#8221;.' ); ?></p>
  196. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
  197. <?php wp_nonce_field('upgrade-core'); ?>
  198. <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
  199. <table class="widefat" cellspacing="0" id="update-plugins-table">
  200. <thead>
  201. <tr>
  202. <th scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></th>
  203. <th scope="col" class="manage-column"><label for="plugins-select-all"><?php _e('Select All'); ?></label></th>
  204. </tr>
  205. </thead>
  206. <tfoot>
  207. <tr>
  208. <th scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></th>
  209. <th scope="col" class="manage-column"><label for="plugins-select-all-2"><?php _e('Select All'); ?></label></th>
  210. </tr>
  211. </tfoot>
  212. <tbody class="plugins">
  213. <?php
  214. foreach ( (array) $plugins as $plugin_file => $plugin_data) {
  215. $info = plugins_api('plugin_information', array('slug' => $plugin_data->update->slug ));
  216. // Get plugin compat for running version of WordPress.
  217. if ( isset($info->tested) && version_compare($info->tested, $cur_wp_version, '>=') ) {
  218. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
  219. } elseif ( isset($info->compatibility[$cur_wp_version][$plugin_data->update->new_version]) ) {
  220. $compat = $info->compatibility[$cur_wp_version][$plugin_data->update->new_version];
  221. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $cur_wp_version, $compat[0], $compat[2], $compat[1]);
  222. } else {
  223. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
  224. }
  225. // Get plugin compat for updated version of WordPress.
  226. if ( $core_update_version ) {
  227. if ( isset($info->compatibility[$core_update_version][$plugin_data->update->new_version]) ) {
  228. $update_compat = $info->compatibility[$core_update_version][$plugin_data->update->new_version];
  229. $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $core_update_version, $update_compat[0], $update_compat[2], $update_compat[1]);
  230. } else {
  231. $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
  232. }
  233. }
  234. // Get the upgrade notice for the new plugin version.
  235. if ( isset($plugin_data->update->upgrade_notice) ) {
  236. $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
  237. } else {
  238. $upgrade_notice = '';
  239. }
  240. $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin_data->update->slug . '&section=changelog&TB_iframe=true&width=640&height=662');
  241. $details_text = sprintf(__('View version %1$s details'), $plugin_data->update->new_version);
  242. $details = sprintf('<a href="%1$s" class="thickbox" title="%2$s">%3$s</a>.', esc_url($details_url), esc_attr($plugin_data->Name), $details_text);
  243. echo "
  244. <tr>
  245. <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
  246. <td><p><strong>{$plugin_data->Name}</strong><br />" . sprintf(__('You have version %1$s installed. Update to %2$s.'), $plugin_data->Version, $plugin_data->update->new_version) . ' ' . $details . $compat . $upgrade_notice . "</p></td>
  247. </tr>";
  248. }
  249. ?>
  250. </tbody>
  251. </table>
  252. <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
  253. </form>
  254. <?php
  255. }
  256. function list_theme_updates() {
  257. $themes = get_theme_updates();
  258. if ( empty( $themes ) ) {
  259. echo '<h3>' . __( 'Themes' ) . '</h3>';
  260. echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
  261. return;
  262. }
  263. $form_action = 'update-core.php?action=do-theme-upgrade';
  264. ?>
  265. <h3><?php _e( 'Themes' ); ?></h3>
  266. <p><?php _e( 'The following themes have new versions available. Check the ones you want to update and then click &#8220;Update Themes&#8221;.' ); ?></p>
  267. <p><?php printf( __( '<strong>Please Note:</strong> Any customizations you have made to theme files will be lost. Please consider using <a href="%s">child themes</a> for modifications.' ), __( 'http://codex.wordpress.org/Child_Themes' ) ); ?></p>
  268. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
  269. <?php wp_nonce_field('upgrade-core'); ?>
  270. <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
  271. <table class="widefat" cellspacing="0" id="update-themes-table">
  272. <thead>
  273. <tr>
  274. <th scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></th>
  275. <th scope="col" class="manage-column"><label for="themes-select-all"><?php _e('Select All'); ?></label></th>
  276. </tr>
  277. </thead>
  278. <tfoot>
  279. <tr>
  280. <th scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></th>
  281. <th scope="col" class="manage-column"><label for="themes-select-all-2"><?php _e('Select All'); ?></label></th>
  282. </tr>
  283. </tfoot>
  284. <tbody class="plugins">
  285. <?php
  286. foreach ( $themes as $stylesheet => $theme ) {
  287. echo "
  288. <tr>
  289. <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr( $stylesheet ) . "' /></th>
  290. <td class='plugin-title'><img src='" . esc_url( $theme->get_screenshot() ) . "' width='85' height='64' style='float:left; padding: 0 5px 5px' /><strong>" . $theme->display('Name') . '</strong> ' . sprintf( __( 'You have version %1$s installed. Update to %2$s.' ), $theme->display('Version'), $theme->update['new_version'] ) . "</td>
  291. </tr>";
  292. }
  293. ?>
  294. </tbody>
  295. </table>
  296. <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
  297. </form>
  298. <?php
  299. }
  300. function list_translation_updates() {
  301. $updates = wp_get_translation_updates();
  302. if ( ! $updates ) {
  303. if ( 'en_US' != get_locale() ) {
  304. echo '<h3>' . __( 'Translations' ) . '</h3>';
  305. echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
  306. }
  307. return;
  308. }
  309. $form_action = 'update-core.php?action=do-translation-upgrade';
  310. ?>
  311. <h3><?php _e( 'Translations' ); ?></h3>
  312. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
  313. <p><?php _e( 'Some of your translations are out of date.' ); ?></p>
  314. <?php wp_nonce_field('upgrade-translations'); ?>
  315. <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
  316. </form>
  317. <?php
  318. }
  319. /**
  320. * Upgrade WordPress core display.
  321. *
  322. * @since 2.7
  323. *
  324. * @return null
  325. */
  326. function do_core_upgrade( $reinstall = false ) {
  327. global $wp_filesystem;
  328. include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  329. if ( $reinstall )
  330. $url = 'update-core.php?action=do-core-reinstall';
  331. else
  332. $url = 'update-core.php?action=do-core-upgrade';
  333. $url = wp_nonce_url($url, 'upgrade-core');
  334. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  335. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  336. $update = find_core_update( $version, $locale );
  337. if ( !$update )
  338. return;
  339. ?>
  340. <div class="wrap">
  341. <h2><?php _e('Update WordPress'); ?></h2>
  342. <?php
  343. if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH ) ) ) {
  344. echo '</div>';
  345. return;
  346. }
  347. if ( ! WP_Filesystem( $credentials, ABSPATH ) ) {
  348. // Failed to connect, Error and request again
  349. request_filesystem_credentials( $url, '', true, ABSPATH );
  350. echo '</div>';
  351. return;
  352. }
  353. if ( $wp_filesystem->errors->get_error_code() ) {
  354. foreach ( $wp_filesystem->errors->get_error_messages() as $message )
  355. show_message($message);
  356. echo '</div>';
  357. return;
  358. }
  359. if ( $reinstall )
  360. $update->response = 'reinstall';
  361. add_filter( 'update_feedback', 'show_message' );
  362. $upgrader = new Core_Upgrader();
  363. $result = $upgrader->upgrade( $update );
  364. if ( is_wp_error($result) ) {
  365. show_message($result);
  366. if ('up_to_date' != $result->get_error_code() )
  367. show_message( __('Installation Failed') );
  368. echo '</div>';
  369. return;
  370. }
  371. show_message( __('WordPress updated successfully') );
  372. show_message( '<span class="hide-if-no-js">' . sprintf( __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ), $result, esc_url( self_admin_url( 'about.php?updated' ) ) ) . '</span>' );
  373. show_message( '<span class="hide-if-js">' . sprintf( __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ), $result, esc_url( self_admin_url( 'about.php?updated' ) ) ) . '</span>' );
  374. ?>
  375. </div>
  376. <script type="text/javascript">
  377. window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
  378. </script>
  379. <?php
  380. }
  381. function do_dismiss_core_update() {
  382. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  383. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  384. $update = find_core_update( $version, $locale );
  385. if ( !$update )
  386. return;
  387. dismiss_core_update( $update );
  388. wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
  389. exit;
  390. }
  391. function do_undismiss_core_update() {
  392. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  393. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  394. $update = find_core_update( $version, $locale );
  395. if ( !$update )
  396. return;
  397. undismiss_core_update( $version, $locale );
  398. wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
  399. exit;
  400. }
  401. $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
  402. $upgrade_error = false;
  403. if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
  404. && ! isset( $_POST['checked'] ) ) {
  405. $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
  406. $action = 'upgrade-core';
  407. }
  408. $title = __('WordPress Updates');
  409. $parent_file = 'tools.php';
  410. $updates_overview = '<p>' . __( 'On this screen, you can update to the latest version of WordPress, as well as update your themes and plugins from the WordPress.org repositories.' ) . '</p>';
  411. $updates_overview .= '<p>' . __( 'If an update is available, you&#8127;ll see a notification appear in the Toolbar and navigation menu.' ) . ' ' . __( 'Keeping your site up to date is important for your site&#8217;s security, and makes the internet a safer place for you and your readers.' ) . '</p>';
  412. get_current_screen()->add_help_tab( array(
  413. 'id' => 'overview',
  414. 'title' => __( 'Overview' ),
  415. 'content' => $updates_overview
  416. ) );
  417. $updates_howto = '<p>' . __( '<strong>WordPress</strong> &mdash; Updating your WordPress installation is a simple one-click procedure: just <strong>click on the &#8220;Update Now&#8221; button</strong> when you are notified that a new version is available.' ) . ' ' . __( 'In most cases, WordPress will automatically apply maintenance and security updates in the background for you.' ) . '</p>';
  418. $updates_howto .= '<p>' . __( '<strong>Themes and Plugins</strong> &mdash; To update individual themes or plugins from this screen, use the checkboxes to make your selection, then <strong>click on the appropriate &#8220;Update&#8221; button</strong>. To update all of your themes or plugins at once, you can check the box at the top of the section to select all before clicking the update button.' ) . '</p>';
  419. if ( 'en_US' != get_locale() ) {
  420. $updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; The files translating WordPress into your language are updated for you whenever any other updates occur. But if these files are out of date, you can <strong>click the &#8220;Update Translations&#8221;</strong> button.' ) . '</p>';
  421. }
  422. get_current_screen()->add_help_tab( array(
  423. 'id' => 'how-to-update',
  424. 'title' => __( 'How to Update' ),
  425. 'content' => $updates_howto
  426. ) );
  427. get_current_screen()->set_help_sidebar(
  428. '<p><strong>' . __('For more information:') . '</strong></p>' .
  429. '<p>' . __( '<a href="http://codex.wordpress.org/Dashboard_Updates_Screen" target="_blank">Documentation on Updating WordPress</a>' ) . '</p>' .
  430. '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
  431. );
  432. if ( 'upgrade-core' == $action ) {
  433. // Force a update check when requested
  434. $force_check = ! empty( $_GET['force-check'] );
  435. wp_version_check( array(), $force_check );
  436. require_once(ABSPATH . 'wp-admin/admin-header.php');
  437. ?>
  438. <div class="wrap">
  439. <h2><?php _e('WordPress Updates'); ?></h2>
  440. <?php
  441. if ( $upgrade_error ) {
  442. echo '<div class="error"><p>';
  443. if ( $upgrade_error == 'themes' )
  444. _e('Please select one or more themes to update.');
  445. else
  446. _e('Please select one or more plugins to update.');
  447. echo '</p></div>';
  448. }
  449. echo '<p>';
  450. /* translators: %1 date, %2 time. */
  451. printf( __('Last checked on %1$s at %2$s.'), date_i18n( get_option( 'date_format' ) ), date_i18n( get_option( 'time_format' ) ) );
  452. echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php?force-check=1') ) . '">' . __( 'Check Again' ) . '</a>';
  453. echo '</p>';
  454. if ( $core = current_user_can( 'update_core' ) )
  455. core_upgrade_preamble();
  456. if ( $plugins = current_user_can( 'update_plugins' ) )
  457. list_plugin_updates();
  458. if ( $themes = current_user_can( 'update_themes' ) )
  459. list_theme_updates();
  460. if ( $core || $plugins || $themes )
  461. list_translation_updates();
  462. unset( $core, $plugins, $themes );
  463. do_action('core_upgrade_preamble');
  464. echo '</div>';
  465. include(ABSPATH . 'wp-admin/admin-footer.php');
  466. } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
  467. if ( ! current_user_can( 'update_core' ) )
  468. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  469. check_admin_referer('upgrade-core');
  470. // do the (un)dismiss actions before headers,
  471. // so that they can redirect
  472. if ( isset( $_POST['dismiss'] ) )
  473. do_dismiss_core_update();
  474. elseif ( isset( $_POST['undismiss'] ) )
  475. do_undismiss_core_update();
  476. require_once(ABSPATH . 'wp-admin/admin-header.php');
  477. if ( 'do-core-reinstall' == $action )
  478. $reinstall = true;
  479. else
  480. $reinstall = false;
  481. if ( isset( $_POST['upgrade'] ) )
  482. do_core_upgrade($reinstall);
  483. include(ABSPATH . 'wp-admin/admin-footer.php');
  484. } elseif ( 'do-plugin-upgrade' == $action ) {
  485. if ( ! current_user_can( 'update_plugins' ) )
  486. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  487. check_admin_referer('upgrade-core');
  488. if ( isset( $_GET['plugins'] ) ) {
  489. $plugins = explode( ',', $_GET['plugins'] );
  490. } elseif ( isset( $_POST['checked'] ) ) {
  491. $plugins = (array) $_POST['checked'];
  492. } else {
  493. wp_redirect( admin_url('update-core.php') );
  494. exit;
  495. }
  496. $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
  497. $url = wp_nonce_url($url, 'bulk-update-plugins');
  498. $title = __('Update Plugins');
  499. require_once(ABSPATH . 'wp-admin/admin-header.php');
  500. echo '<div class="wrap">';
  501. echo '<h2>' . esc_html__('Update Plugins') . '</h2>';
  502. echo "<iframe src='$url' style='width: 100%; height: 100%; min-height: 750px;' frameborder='0'></iframe>";
  503. echo '</div>';
  504. include(ABSPATH . 'wp-admin/admin-footer.php');
  505. } elseif ( 'do-theme-upgrade' == $action ) {
  506. if ( ! current_user_can( 'update_themes' ) )
  507. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  508. check_admin_referer('upgrade-core');
  509. if ( isset( $_GET['themes'] ) ) {
  510. $themes = explode( ',', $_GET['themes'] );
  511. } elseif ( isset( $_POST['checked'] ) ) {
  512. $themes = (array) $_POST['checked'];
  513. } else {
  514. wp_redirect( admin_url('update-core.php') );
  515. exit;
  516. }
  517. $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
  518. $url = wp_nonce_url($url, 'bulk-update-themes');
  519. $title = __('Update Themes');
  520. require_once(ABSPATH . 'wp-admin/admin-header.php');
  521. echo '<div class="wrap">';
  522. echo '<h2>' . esc_html__('Update Themes') . '</h2>';
  523. echo "<iframe src='$url' style='width: 100%; height: 100%; min-height: 750px;' frameborder='0'></iframe>";
  524. echo '</div>';
  525. include(ABSPATH . 'wp-admin/admin-footer.php');
  526. } elseif ( 'do-translation-upgrade' == $action ) {
  527. if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
  528. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  529. check_admin_referer( 'upgrade-translations' );
  530. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  531. include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  532. $url = 'update-core.php?action=do-translation-upgrade';
  533. $nonce = 'upgrade-translations';
  534. $title = __( 'Update Translations' );
  535. $context = WP_LANG_DIR;
  536. $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
  537. $result = $upgrader->bulk_upgrade();
  538. require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  539. } else {
  540. do_action('update-core-custom_' . $action);
  541. }