PageRenderTime 78ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/update-core.php

https://bitbucket.org/stephenharris/stephenharris
PHP | 765 lines | 578 code | 103 blank | 84 comment | 143 complexity | d74641e309fad17dd4f23689087e70eb MD5 | raw file
  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. wp_enqueue_script( 'updates' );
  13. add_thickbox();
  14. if ( is_multisite() && ! is_network_admin() ) {
  15. wp_redirect( network_admin_url( 'update-core.php' ) );
  16. exit();
  17. }
  18. if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) )
  19. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  20. /**
  21. *
  22. * @global string $wp_local_package
  23. * @global wpdb $wpdb
  24. *
  25. * @staticvar bool $first_pass
  26. *
  27. * @param object $update
  28. */
  29. function list_core_update( $update ) {
  30. global $wp_local_package, $wpdb;
  31. static $first_pass = true;
  32. $wp_version = get_bloginfo( 'version' );
  33. if ( 'en_US' == $update->locale && 'en_US' == get_locale() )
  34. $version_string = $update->current;
  35. // If the only available update is a partial builds, it doesn't need a language-specific version string.
  36. elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version && ( $updates = get_core_updates() ) && 1 == count( $updates ) )
  37. $version_string = $update->current;
  38. else
  39. $version_string = sprintf( "%s&ndash;<strong>%s</strong>", $update->current, $update->locale );
  40. $current = false;
  41. if ( !isset($update->response) || 'latest' == $update->response )
  42. $current = true;
  43. $submit = __('Update Now');
  44. $form_action = 'update-core.php?action=do-core-upgrade';
  45. $php_version = phpversion();
  46. $mysql_version = $wpdb->db_version();
  47. $show_buttons = true;
  48. if ( 'development' == $update->response ) {
  49. $message = __('You are using a development version of WordPress. You can update to the latest nightly build automatically:');
  50. } else {
  51. if ( $current ) {
  52. $message = sprintf( __( 'If you need to re-install version %s, you can do so here:' ), $version_string );
  53. $submit = __('Re-install Now');
  54. $form_action = 'update-core.php?action=do-core-reinstall';
  55. } else {
  56. $php_compat = version_compare( $php_version, $update->php_version, '>=' );
  57. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
  58. $mysql_compat = true;
  59. else
  60. $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
  61. if ( !$mysql_compat && !$php_compat )
  62. /* translators: 1: WordPress version number, 2: Minimum required PHP version number, 3: Minimum required MySQL version number, 4: Current PHP version number, 5: Current MySQL version number */
  63. $message = sprintf( __('You cannot update because <a href="https://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 );
  64. elseif ( !$php_compat )
  65. /* translators: 1: WordPress version number, 2: Minimum required PHP version number, 3: Current PHP version number */
  66. $message = sprintf( __('You cannot update because <a href="https://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 );
  67. elseif ( !$mysql_compat )
  68. /* translators: 1: WordPress version number, 2: Minimum required MySQL version number, 3: Current MySQL version number */
  69. $message = sprintf( __('You cannot update because <a href="https://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 );
  70. else
  71. /* translators: 1: WordPress version number, 2: WordPress version number including locale if necessary */
  72. $message = sprintf(__('You can update to <a href="https://codex.wordpress.org/Version_%1$s">WordPress %2$s</a> automatically:'), $update->current, $version_string);
  73. if ( !$mysql_compat || !$php_compat )
  74. $show_buttons = false;
  75. }
  76. }
  77. echo '<p>';
  78. echo $message;
  79. echo '</p>';
  80. echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
  81. wp_nonce_field('upgrade-core');
  82. echo '<p>';
  83. echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
  84. echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
  85. if ( $show_buttons ) {
  86. if ( $first_pass ) {
  87. submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
  88. $first_pass = false;
  89. } else {
  90. submit_button( $submit, '', 'upgrade', false );
  91. }
  92. }
  93. if ( 'en_US' != $update->locale )
  94. if ( !isset( $update->dismissed ) || !$update->dismissed )
  95. submit_button( __( 'Hide this update' ), '', 'dismiss', false );
  96. else
  97. submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
  98. echo '</p>';
  99. if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
  100. 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>';
  101. // Partial builds don't need language-specific warnings.
  102. elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
  103. 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>';
  104. }
  105. echo '</form>';
  106. }
  107. /**
  108. * @since 2.7.0
  109. */
  110. function dismissed_updates() {
  111. $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
  112. if ( $dismissed ) {
  113. $show_text = esc_js(__('Show hidden updates'));
  114. $hide_text = esc_js(__('Hide hidden updates'));
  115. ?>
  116. <script type="text/javascript">
  117. jQuery(function($) {
  118. $('dismissed-updates').show();
  119. $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
  120. $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
  121. });
  122. </script>
  123. <?php
  124. echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
  125. echo '<ul id="dismissed-updates" class="core-updates dismissed">';
  126. foreach ( (array) $dismissed as $update) {
  127. echo '<li>';
  128. list_core_update( $update );
  129. echo '</li>';
  130. }
  131. echo '</ul>';
  132. }
  133. }
  134. /**
  135. * Display upgrade WordPress for downloading latest or upgrading automatically form.
  136. *
  137. * @since 2.7.0
  138. *
  139. * @global string $required_php_version
  140. * @global string $required_mysql_version
  141. */
  142. function core_upgrade_preamble() {
  143. global $required_php_version, $required_mysql_version;
  144. $wp_version = get_bloginfo( 'version' );
  145. $updates = get_core_updates();
  146. if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
  147. echo '<h2>';
  148. _e('You have the latest version of WordPress.');
  149. if ( wp_http_supports( array( 'ssl' ) ) ) {
  150. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  151. $upgrader = new WP_Automatic_Updater;
  152. $future_minor_update = (object) array(
  153. 'current' => $wp_version . '.1.next.minor',
  154. 'version' => $wp_version . '.1.next.minor',
  155. 'php_version' => $required_php_version,
  156. 'mysql_version' => $required_mysql_version,
  157. );
  158. $should_auto_update = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
  159. if ( $should_auto_update )
  160. echo ' ' . __( 'Future security updates will be applied automatically.' );
  161. }
  162. echo '</h2>';
  163. } else {
  164. echo '<div class="notice notice-warning"><p>';
  165. _e('<strong>Important:</strong> before updating, please <a href="https://codex.wordpress.org/WordPress_Backups">back up your database and files</a>. For help with updates, visit the <a href="https://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.');
  166. echo '</p></div>';
  167. echo '<h2 class="response">';
  168. _e( 'An updated version of WordPress is available.' );
  169. echo '</h2>';
  170. }
  171. if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) {
  172. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  173. $upgrader = new WP_Automatic_Updater;
  174. if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) ) {
  175. echo '<div class="updated inline"><p>';
  176. echo '<strong>' . __( 'BETA TESTERS:' ) . '</strong> ' . __( 'This site is set up to install updates of future beta versions automatically.' );
  177. echo '</p></div>';
  178. }
  179. }
  180. echo '<ul class="core-updates">';
  181. foreach ( (array) $updates as $update ) {
  182. echo '<li>';
  183. list_core_update( $update );
  184. echo '</li>';
  185. }
  186. echo '</ul>';
  187. // Don't show the maintenance mode notice when we are only showing a single re-install option.
  188. if ( $updates && ( count( $updates ) > 1 || $updates[0]->response != 'latest' ) ) {
  189. 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>';
  190. } elseif ( ! $updates ) {
  191. list( $normalized_version ) = explode( '-', $wp_version );
  192. echo '<p>' . sprintf( __( '<a href="%s">Learn more about WordPress %s</a>.' ), esc_url( self_admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
  193. }
  194. dismissed_updates();
  195. }
  196. function list_plugin_updates() {
  197. $wp_version = get_bloginfo( 'version' );
  198. $cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
  199. require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
  200. $plugins = get_plugin_updates();
  201. if ( empty( $plugins ) ) {
  202. echo '<h2>' . __( 'Plugins' ) . '</h2>';
  203. echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
  204. return;
  205. }
  206. $form_action = 'update-core.php?action=do-plugin-upgrade';
  207. $core_updates = get_core_updates();
  208. 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, '=') )
  209. $core_update_version = false;
  210. else
  211. $core_update_version = $core_updates[0]->current;
  212. ?>
  213. <h2><?php _e( 'Plugins' ); ?></h2>
  214. <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>
  215. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
  216. <?php wp_nonce_field('upgrade-core'); ?>
  217. <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
  218. <table class="widefat updates-table" id="update-plugins-table">
  219. <thead>
  220. <tr>
  221. <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></td>
  222. <td class="manage-column"><label for="plugins-select-all"><?php _e( 'Select All' ); ?></label></td>
  223. </tr>
  224. </thead>
  225. <tbody class="plugins">
  226. <?php
  227. foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
  228. $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
  229. // Get plugin compat for running version of WordPress.
  230. if ( isset($plugin_data->update->tested) && version_compare($plugin_data->update->tested, $cur_wp_version, '>=') ) {
  231. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
  232. } elseif ( isset($plugin_data->update->compatibility->{$cur_wp_version}) ) {
  233. $compat = $plugin_data->update->compatibility->{$cur_wp_version};
  234. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $cur_wp_version, $compat->percent, $compat->votes, $compat->total_votes);
  235. } else {
  236. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
  237. }
  238. // Get plugin compat for updated version of WordPress.
  239. if ( $core_update_version ) {
  240. if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
  241. $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version );
  242. } elseif ( isset( $plugin_data->update->compatibility->{$core_update_version} ) ) {
  243. $update_compat = $plugin_data->update->compatibility->{$core_update_version};
  244. $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $core_update_version, $update_compat->percent, $update_compat->votes, $update_compat->total_votes);
  245. } else {
  246. $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
  247. }
  248. }
  249. // Get the upgrade notice for the new plugin version.
  250. if ( isset($plugin_data->update->upgrade_notice) ) {
  251. $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
  252. } else {
  253. $upgrade_notice = '';
  254. }
  255. $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');
  256. $details = sprintf(
  257. '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
  258. esc_url( $details_url ),
  259. /* translators: 1: plugin name, 2: version number */
  260. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
  261. /* translators: %s: plugin version */
  262. sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
  263. );
  264. $checkbox_id = "checkbox_" . md5( $plugin_data->Name );
  265. ?>
  266. <tr>
  267. <td class="check-column">
  268. <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
  269. <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text"><?php
  270. /* translators: %s: plugin name */
  271. printf( __( 'Select %s' ),
  272. $plugin_data->Name
  273. );
  274. ?></label>
  275. </td>
  276. <td class="plugin-title"><p>
  277. <strong><?php echo $plugin_data->Name; ?></strong>
  278. <?php
  279. /* translators: 1: plugin version, 2: new version */
  280. printf( __( 'You have version %1$s installed. Update to %2$s.' ),
  281. $plugin_data->Version,
  282. $plugin_data->update->new_version
  283. );
  284. echo ' ' . $details . $compat . $upgrade_notice;
  285. ?>
  286. </p></td>
  287. </tr>
  288. <?php
  289. }
  290. ?>
  291. </tbody>
  292. <tfoot>
  293. <tr>
  294. <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></td>
  295. <td class="manage-column"><label for="plugins-select-all-2"><?php _e( 'Select All' ); ?></label></td>
  296. </tr>
  297. </tfoot>
  298. </table>
  299. <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
  300. </form>
  301. <?php
  302. }
  303. /**
  304. * @since 2.9.0
  305. */
  306. function list_theme_updates() {
  307. $themes = get_theme_updates();
  308. if ( empty( $themes ) ) {
  309. echo '<h2>' . __( 'Themes' ) . '</h2>';
  310. echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
  311. return;
  312. }
  313. $form_action = 'update-core.php?action=do-theme-upgrade';
  314. ?>
  315. <h2><?php _e( 'Themes' ); ?></h2>
  316. <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>
  317. <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.' ), __( 'https://codex.wordpress.org/Child_Themes' ) ); ?></p>
  318. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
  319. <?php wp_nonce_field('upgrade-core'); ?>
  320. <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
  321. <table class="widefat updates-table" id="update-themes-table">
  322. <thead>
  323. <tr>
  324. <td class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></td>
  325. <td class="manage-column"><label for="themes-select-all"><?php _e( 'Select All' ); ?></label></td>
  326. </tr>
  327. </thead>
  328. <tbody class="plugins">
  329. <?php
  330. foreach ( $themes as $stylesheet => $theme ) {
  331. $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
  332. ?>
  333. <tr>
  334. <td class="check-column">
  335. <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
  336. <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text"><?php
  337. /* translators: %s: theme name */
  338. printf( __( 'Select %s' ),
  339. $theme->display( 'Name' )
  340. );
  341. ?></label>
  342. </td>
  343. <td class="plugin-title"><p>
  344. <img src="<?php echo esc_url( $theme->get_screenshot() ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" />
  345. <strong><?php echo $theme->display( 'Name' ); ?></strong>
  346. <?php
  347. /* translators: 1: theme version, 2: new version */
  348. printf( __( 'You have version %1$s installed. Update to %2$s.' ),
  349. $theme->display( 'Version' ),
  350. $theme->update['new_version']
  351. );
  352. ?>
  353. </p></td>
  354. </tr>
  355. <?php
  356. }
  357. ?>
  358. </tbody>
  359. <tfoot>
  360. <tr>
  361. <td class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></td>
  362. <td class="manage-column"><label for="themes-select-all-2"><?php _e( 'Select All' ); ?></label></td>
  363. </tr>
  364. </tfoot>
  365. </table>
  366. <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
  367. </form>
  368. <?php
  369. }
  370. /**
  371. * @since 3.7.0
  372. */
  373. function list_translation_updates() {
  374. $updates = wp_get_translation_updates();
  375. if ( ! $updates ) {
  376. if ( 'en_US' != get_locale() ) {
  377. echo '<h2>' . __( 'Translations' ) . '</h2>';
  378. echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
  379. }
  380. return;
  381. }
  382. $form_action = 'update-core.php?action=do-translation-upgrade';
  383. ?>
  384. <h2><?php _e( 'Translations' ); ?></h2>
  385. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
  386. <p><?php _e( 'New translations are available.' ); ?></p>
  387. <?php wp_nonce_field( 'upgrade-translations' ); ?>
  388. <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
  389. </form>
  390. <?php
  391. }
  392. /**
  393. * Upgrade WordPress core display.
  394. *
  395. * @since 2.7.0
  396. *
  397. * @global WP_Filesystem_Base $wp_filesystem Subclass
  398. *
  399. * @param bool $reinstall
  400. */
  401. function do_core_upgrade( $reinstall = false ) {
  402. global $wp_filesystem;
  403. include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  404. if ( $reinstall )
  405. $url = 'update-core.php?action=do-core-reinstall';
  406. else
  407. $url = 'update-core.php?action=do-core-upgrade';
  408. $url = wp_nonce_url($url, 'upgrade-core');
  409. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  410. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  411. $update = find_core_update( $version, $locale );
  412. if ( !$update )
  413. return;
  414. // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
  415. // that it's safe to do so. This only happens when there are no new files to create.
  416. $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
  417. ?>
  418. <div class="wrap">
  419. <h1><?php _e( 'Update WordPress' ); ?></h1>
  420. <?php
  421. if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ) ) ) {
  422. echo '</div>';
  423. return;
  424. }
  425. if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
  426. // Failed to connect, Error and request again
  427. request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
  428. echo '</div>';
  429. return;
  430. }
  431. if ( $wp_filesystem->errors->get_error_code() ) {
  432. foreach ( $wp_filesystem->errors->get_error_messages() as $message )
  433. show_message($message);
  434. echo '</div>';
  435. return;
  436. }
  437. if ( $reinstall )
  438. $update->response = 'reinstall';
  439. add_filter( 'update_feedback', 'show_message' );
  440. $upgrader = new Core_Upgrader();
  441. $result = $upgrader->upgrade( $update, array(
  442. 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership
  443. ) );
  444. if ( is_wp_error($result) ) {
  445. show_message($result);
  446. if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() )
  447. show_message( __('Installation Failed') );
  448. echo '</div>';
  449. return;
  450. }
  451. show_message( __('WordPress updated successfully') );
  452. 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>' );
  453. 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>' );
  454. ?>
  455. </div>
  456. <script type="text/javascript">
  457. window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
  458. </script>
  459. <?php
  460. }
  461. /**
  462. * @since 2.7.0
  463. */
  464. function do_dismiss_core_update() {
  465. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  466. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  467. $update = find_core_update( $version, $locale );
  468. if ( !$update )
  469. return;
  470. dismiss_core_update( $update );
  471. wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
  472. exit;
  473. }
  474. /**
  475. * @since 2.7.0
  476. */
  477. function do_undismiss_core_update() {
  478. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  479. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  480. $update = find_core_update( $version, $locale );
  481. if ( !$update )
  482. return;
  483. undismiss_core_update( $version, $locale );
  484. wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
  485. exit;
  486. }
  487. $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
  488. $upgrade_error = false;
  489. if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
  490. && ! isset( $_POST['checked'] ) ) {
  491. $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
  492. $action = 'upgrade-core';
  493. }
  494. $title = __('WordPress Updates');
  495. $parent_file = 'index.php';
  496. $updates_overview = '<p>' . __( 'On this screen, you can update to the latest version of WordPress, as well as update your themes, plugins, and translations from the WordPress.org repositories.' ) . '</p>';
  497. $updates_overview .= '<p>' . __( 'If an update is available, you&#8127;ll see a notification appear in the Toolbar and navigation menu.' ) . ' ' . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' ) . '</p>';
  498. get_current_screen()->add_help_tab( array(
  499. 'id' => 'overview',
  500. 'title' => __( 'Overview' ),
  501. 'content' => $updates_overview
  502. ) );
  503. $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>';
  504. $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>';
  505. if ( 'en_US' != get_locale() ) {
  506. $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>';
  507. }
  508. get_current_screen()->add_help_tab( array(
  509. 'id' => 'how-to-update',
  510. 'title' => __( 'How to Update' ),
  511. 'content' => $updates_howto
  512. ) );
  513. get_current_screen()->set_help_sidebar(
  514. '<p><strong>' . __('For more information:') . '</strong></p>' .
  515. '<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_Updates_Screen">Documentation on Updating WordPress</a>' ) . '</p>' .
  516. '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
  517. );
  518. if ( 'upgrade-core' == $action ) {
  519. // Force a update check when requested
  520. $force_check = ! empty( $_GET['force-check'] );
  521. wp_version_check( array(), $force_check );
  522. require_once(ABSPATH . 'wp-admin/admin-header.php');
  523. ?>
  524. <div class="wrap">
  525. <h1><?php _e( 'WordPress Updates' ); ?></h1>
  526. <?php
  527. if ( $upgrade_error ) {
  528. echo '<div class="error"><p>';
  529. if ( $upgrade_error == 'themes' )
  530. _e('Please select one or more themes to update.');
  531. else
  532. _e('Please select one or more plugins to update.');
  533. echo '</p></div>';
  534. }
  535. $last_update_check = false;
  536. $current = get_site_transient( 'update_core' );
  537. if ( $current && isset ( $current->last_checked ) ) {
  538. $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
  539. }
  540. echo '<p>';
  541. /* translators: %1 date, %2 time. */
  542. printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ), $last_update_check ), date_i18n( __( 'g:i a' ), $last_update_check ) );
  543. echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php?force-check=1') ) . '">' . __( 'Check Again' ) . '</a>';
  544. echo '</p>';
  545. if ( $core = current_user_can( 'update_core' ) )
  546. core_upgrade_preamble();
  547. if ( $plugins = current_user_can( 'update_plugins' ) )
  548. list_plugin_updates();
  549. if ( $themes = current_user_can( 'update_themes' ) )
  550. list_theme_updates();
  551. if ( $core || $plugins || $themes )
  552. list_translation_updates();
  553. unset( $core, $plugins, $themes );
  554. /**
  555. * Fires after the core, plugin, and theme update tables.
  556. *
  557. * @since 2.9.0
  558. */
  559. do_action( 'core_upgrade_preamble' );
  560. echo '</div>';
  561. wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
  562. 'totals' => wp_get_update_data(),
  563. ) );
  564. include(ABSPATH . 'wp-admin/admin-footer.php');
  565. } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
  566. if ( ! current_user_can( 'update_core' ) )
  567. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  568. check_admin_referer('upgrade-core');
  569. // Do the (un)dismiss actions before headers, so that they can redirect.
  570. if ( isset( $_POST['dismiss'] ) )
  571. do_dismiss_core_update();
  572. elseif ( isset( $_POST['undismiss'] ) )
  573. do_undismiss_core_update();
  574. require_once(ABSPATH . 'wp-admin/admin-header.php');
  575. if ( 'do-core-reinstall' == $action )
  576. $reinstall = true;
  577. else
  578. $reinstall = false;
  579. if ( isset( $_POST['upgrade'] ) )
  580. do_core_upgrade($reinstall);
  581. wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
  582. 'totals' => wp_get_update_data(),
  583. ) );
  584. include(ABSPATH . 'wp-admin/admin-footer.php');
  585. } elseif ( 'do-plugin-upgrade' == $action ) {
  586. if ( ! current_user_can( 'update_plugins' ) )
  587. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  588. check_admin_referer('upgrade-core');
  589. if ( isset( $_GET['plugins'] ) ) {
  590. $plugins = explode( ',', $_GET['plugins'] );
  591. } elseif ( isset( $_POST['checked'] ) ) {
  592. $plugins = (array) $_POST['checked'];
  593. } else {
  594. wp_redirect( admin_url('update-core.php') );
  595. exit;
  596. }
  597. $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
  598. $url = wp_nonce_url($url, 'bulk-update-plugins');
  599. $title = __('Update Plugins');
  600. require_once(ABSPATH . 'wp-admin/admin-header.php');
  601. echo '<div class="wrap">';
  602. echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
  603. echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="' . esc_attr__( 'Update progress' ) . '"></iframe>';
  604. echo '</div>';
  605. wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
  606. 'totals' => wp_get_update_data(),
  607. ) );
  608. include(ABSPATH . 'wp-admin/admin-footer.php');
  609. } elseif ( 'do-theme-upgrade' == $action ) {
  610. if ( ! current_user_can( 'update_themes' ) )
  611. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  612. check_admin_referer('upgrade-core');
  613. if ( isset( $_GET['themes'] ) ) {
  614. $themes = explode( ',', $_GET['themes'] );
  615. } elseif ( isset( $_POST['checked'] ) ) {
  616. $themes = (array) $_POST['checked'];
  617. } else {
  618. wp_redirect( admin_url('update-core.php') );
  619. exit;
  620. }
  621. $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
  622. $url = wp_nonce_url($url, 'bulk-update-themes');
  623. $title = __('Update Themes');
  624. require_once(ABSPATH . 'wp-admin/admin-header.php');
  625. ?>
  626. <div class="wrap">
  627. <h1><?php _e( 'Update Themes' ); ?></h1>
  628. <iframe src="<?php echo $url ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
  629. </div>
  630. <?php
  631. wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
  632. 'totals' => wp_get_update_data(),
  633. ) );
  634. include(ABSPATH . 'wp-admin/admin-footer.php');
  635. } elseif ( 'do-translation-upgrade' == $action ) {
  636. if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
  637. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  638. check_admin_referer( 'upgrade-translations' );
  639. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  640. include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  641. $url = 'update-core.php?action=do-translation-upgrade';
  642. $nonce = 'upgrade-translations';
  643. $title = __( 'Update Translations' );
  644. $context = WP_LANG_DIR;
  645. $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
  646. $result = $upgrader->bulk_upgrade();
  647. wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
  648. 'totals' => wp_get_update_data(),
  649. ) );
  650. require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  651. } else {
  652. /**
  653. * Fires for each custom update action on the WordPress Updates screen.
  654. *
  655. * The dynamic portion of the hook name, `$action`, refers to the
  656. * passed update action. The hook fires in lieu of all available
  657. * default update actions.
  658. *
  659. * @since 3.2.0
  660. */
  661. do_action( "update-core-custom_{$action}" );
  662. }