PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/update-core.php

http://github.com/markjaquith/WordPress
PHP | 952 lines | 724 code | 113 blank | 115 comment | 136 complexity | 28ff1dd72e4745c25dce414a7bdcc3a5 MD5 | raw file
Possible License(s): 0BSD
  1. <?php
  2. /**
  3. * Update Core administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once __DIR__ . '/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' ) && ! current_user_can( 'update_languages' ) ) {
  19. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  20. }
  21. /**
  22. * Lists available core updates.
  23. *
  24. * @since 2.7.0
  25. *
  26. * @global string $wp_local_package Locale code of the package.
  27. * @global wpdb $wpdb WordPress database abstraction object.
  28. *
  29. * @staticvar bool $first_pass
  30. *
  31. * @param object $update
  32. */
  33. function list_core_update( $update ) {
  34. global $wp_local_package, $wpdb;
  35. static $first_pass = true;
  36. $wp_version = get_bloginfo( 'version' );
  37. $version_string = sprintf( '%s&ndash;<strong>%s</strong>', $update->current, $update->locale );
  38. if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
  39. $version_string = $update->current;
  40. } elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
  41. $updates = get_core_updates();
  42. if ( $updates && 1 == count( $updates ) ) {
  43. // If the only available update is a partial builds, it doesn't need a language-specific version string.
  44. $version_string = $update->current;
  45. }
  46. }
  47. $current = false;
  48. if ( ! isset( $update->response ) || 'latest' === $update->response ) {
  49. $current = true;
  50. }
  51. $submit = __( 'Update Now' );
  52. $form_action = 'update-core.php?action=do-core-upgrade';
  53. $php_version = phpversion();
  54. $mysql_version = $wpdb->db_version();
  55. $show_buttons = true;
  56. if ( 'development' === $update->response ) {
  57. $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build automatically:' );
  58. } else {
  59. if ( $current ) {
  60. /* translators: %s: WordPress version. */
  61. $message = sprintf( __( 'If you need to re-install version %s, you can do so here:' ), $version_string );
  62. $submit = __( 'Re-install Now' );
  63. $form_action = 'update-core.php?action=do-core-reinstall';
  64. } else {
  65. $php_compat = version_compare( $php_version, $update->php_version, '>=' );
  66. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
  67. $mysql_compat = true;
  68. } else {
  69. $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
  70. }
  71. $version_url = sprintf(
  72. /* translators: %s: WordPress version. */
  73. esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
  74. sanitize_title( $update->current )
  75. );
  76. $php_update_message = '</p><p>' . sprintf(
  77. /* translators: %s: URL to Update PHP page. */
  78. __( '<a href="%s">Learn more about updating PHP</a>.' ),
  79. esc_url( wp_get_update_php_url() )
  80. );
  81. $annotation = wp_get_update_php_annotation();
  82. if ( $annotation ) {
  83. $php_update_message .= '</p><p><em>' . $annotation . '</em>';
  84. }
  85. if ( ! $mysql_compat && ! $php_compat ) {
  86. $message = sprintf(
  87. /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */
  88. __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ),
  89. $version_url,
  90. $update->current,
  91. $update->php_version,
  92. $update->mysql_version,
  93. $php_version,
  94. $mysql_version
  95. ) . $php_update_message;
  96. } elseif ( ! $php_compat ) {
  97. $message = sprintf(
  98. /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
  99. __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ),
  100. $version_url,
  101. $update->current,
  102. $update->php_version,
  103. $php_version
  104. ) . $php_update_message;
  105. } elseif ( ! $mysql_compat ) {
  106. $message = sprintf(
  107. /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
  108. __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ),
  109. $version_url,
  110. $update->current,
  111. $update->mysql_version,
  112. $mysql_version
  113. );
  114. } else {
  115. $message = sprintf(
  116. /* translators: 1: URL to WordPress release notes, 2: WordPress version number including locale if necessary. */
  117. __( 'You can update to <a href="%1$s">WordPress %2$s</a> automatically:' ),
  118. $version_url,
  119. $version_string
  120. );
  121. }
  122. if ( ! $mysql_compat || ! $php_compat ) {
  123. $show_buttons = false;
  124. }
  125. }
  126. }
  127. echo '<p>';
  128. echo $message;
  129. echo '</p>';
  130. echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
  131. wp_nonce_field( 'upgrade-core' );
  132. echo '<p>';
  133. echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden"/>';
  134. echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden"/>';
  135. if ( $show_buttons ) {
  136. if ( $first_pass ) {
  137. submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
  138. $first_pass = false;
  139. } else {
  140. submit_button( $submit, '', 'upgrade', false );
  141. }
  142. }
  143. if ( 'en_US' !== $update->locale ) {
  144. if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
  145. submit_button( __( 'Hide this update' ), '', 'dismiss', false );
  146. } else {
  147. submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
  148. }
  149. }
  150. echo '</p>';
  151. if ( 'en_US' !== $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
  152. echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '</p>';
  153. } elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
  154. // Partial builds don't need language-specific warnings.
  155. echo '<p class="hint">' . sprintf(
  156. /* translators: %s: WordPress version. */
  157. __( '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.' ),
  158. 'development' !== $update->response ? $update->current : ''
  159. ) . '</p>';
  160. }
  161. echo '</form>';
  162. }
  163. /**
  164. * Display dismissed updates.
  165. *
  166. * @since 2.7.0
  167. */
  168. function dismissed_updates() {
  169. $dismissed = get_core_updates(
  170. array(
  171. 'dismissed' => true,
  172. 'available' => false,
  173. )
  174. );
  175. if ( $dismissed ) {
  176. $show_text = esc_js( __( 'Show hidden updates' ) );
  177. $hide_text = esc_js( __( 'Hide hidden updates' ) );
  178. ?>
  179. <script type="text/javascript">
  180. jQuery(function( $ ) {
  181. $( 'dismissed-updates' ).show();
  182. $( '#show-dismissed' ).toggle( function() { $( this ).text( '<?php echo $hide_text; ?>' ).attr( 'aria-expanded', 'true' ); }, function() { $( this ).text( '<?php echo $show_text; ?>' ).attr( 'aria-expanded', 'false' ); } );
  183. $( '#show-dismissed' ).click( function() { $( '#dismissed-updates' ).toggle( 'fast' ); } );
  184. });
  185. </script>
  186. <?php
  187. echo '<p class="hide-if-no-js"><button type="button" class="button" id="show-dismissed" aria-expanded="false">' . __( 'Show hidden updates' ) . '</button></p>';
  188. echo '<ul id="dismissed-updates" class="core-updates dismissed">';
  189. foreach ( (array) $dismissed as $update ) {
  190. echo '<li>';
  191. list_core_update( $update );
  192. echo '</li>';
  193. }
  194. echo '</ul>';
  195. }
  196. }
  197. /**
  198. * Display upgrade WordPress for downloading latest or upgrading automatically form.
  199. *
  200. * @since 2.7.0
  201. *
  202. * @global string $required_php_version The required PHP version string.
  203. * @global string $required_mysql_version The required MySQL version string.
  204. */
  205. function core_upgrade_preamble() {
  206. global $required_php_version, $required_mysql_version;
  207. $wp_version = get_bloginfo( 'version' );
  208. $updates = get_core_updates();
  209. if ( ! isset( $updates[0]->response ) || 'latest' === $updates[0]->response ) {
  210. echo '<h2>';
  211. _e( 'You have the latest version of WordPress.' );
  212. if ( wp_http_supports( array( 'ssl' ) ) ) {
  213. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  214. $upgrader = new WP_Automatic_Updater;
  215. $future_minor_update = (object) array(
  216. 'current' => $wp_version . '.1.next.minor',
  217. 'version' => $wp_version . '.1.next.minor',
  218. 'php_version' => $required_php_version,
  219. 'mysql_version' => $required_mysql_version,
  220. );
  221. $should_auto_update = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
  222. if ( $should_auto_update ) {
  223. echo ' ' . __( 'Future security updates will be applied automatically.' );
  224. }
  225. }
  226. echo '</h2>';
  227. }
  228. if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
  229. echo '<div class="notice notice-warning"><p>';
  230. _e( '<strong>Important:</strong> Before updating, please <a href="https://wordpress.org/support/article/wordpress-backups/">back up your database and files</a>. For help with updates, visit the <a href="https://wordpress.org/support/article/updating-wordpress/">Updating WordPress</a> documentation page.' );
  231. echo '</p></div>';
  232. echo '<h2 class="response">';
  233. _e( 'An updated version of WordPress is available.' );
  234. echo '</h2>';
  235. }
  236. if ( isset( $updates[0] ) && 'development' === $updates[0]->response ) {
  237. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  238. $upgrader = new WP_Automatic_Updater;
  239. if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) ) {
  240. echo '<div class="updated inline"><p>';
  241. echo '<strong>' . __( 'BETA TESTERS:' ) . '</strong> ' . __( 'This site is set up to install updates of future beta versions automatically.' );
  242. echo '</p></div>';
  243. }
  244. }
  245. echo '<ul class="core-updates">';
  246. foreach ( (array) $updates as $update ) {
  247. echo '<li>';
  248. list_core_update( $update );
  249. echo '</li>';
  250. }
  251. echo '</ul>';
  252. // Don't show the maintenance mode notice when we are only showing a single re-install option.
  253. if ( $updates && ( count( $updates ) > 1 || 'latest' !== $updates[0]->response ) ) {
  254. 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>';
  255. } elseif ( ! $updates ) {
  256. list( $normalized_version ) = explode( '-', $wp_version );
  257. echo '<p>' . sprintf(
  258. /* translators: 1: URL to About screen, 2: WordPress version. */
  259. __( '<a href="%1$s">Learn more about WordPress %2$s</a>.' ),
  260. esc_url( self_admin_url( 'about.php' ) ),
  261. $normalized_version
  262. ) . '</p>';
  263. }
  264. dismissed_updates();
  265. }
  266. /**
  267. * Display the upgrade plugins form.
  268. *
  269. * @since 2.9.0
  270. */
  271. function list_plugin_updates() {
  272. $wp_version = get_bloginfo( 'version' );
  273. $cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
  274. require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
  275. $plugins = get_plugin_updates();
  276. if ( empty( $plugins ) ) {
  277. echo '<h2>' . __( 'Plugins' ) . '</h2>';
  278. echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
  279. return;
  280. }
  281. $form_action = 'update-core.php?action=do-plugin-upgrade';
  282. $core_updates = get_core_updates();
  283. 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, '=' ) ) {
  284. $core_update_version = false;
  285. } else {
  286. $core_update_version = $core_updates[0]->current;
  287. }
  288. ?>
  289. <h2><?php _e( 'Plugins' ); ?></h2>
  290. <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>
  291. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
  292. <?php wp_nonce_field( 'upgrade-core' ); ?>
  293. <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
  294. <table class="widefat updates-table" id="update-plugins-table">
  295. <thead>
  296. <tr>
  297. <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></td>
  298. <td class="manage-column"><label for="plugins-select-all"><?php _e( 'Select All' ); ?></label></td>
  299. </tr>
  300. </thead>
  301. <tbody class="plugins">
  302. <?php
  303. foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
  304. $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
  305. $icon = '<span class="dashicons dashicons-admin-plugins"></span>';
  306. $preferred_icons = array( 'svg', '2x', '1x', 'default' );
  307. foreach ( $preferred_icons as $preferred_icon ) {
  308. if ( ! empty( $plugin_data->update->icons[ $preferred_icon ] ) ) {
  309. $icon = '<img src="' . esc_url( $plugin_data->update->icons[ $preferred_icon ] ) . '" alt="" />';
  310. break;
  311. }
  312. }
  313. // Get plugin compat for running version of WordPress.
  314. if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) {
  315. /* translators: %s: WordPress version. */
  316. $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %s: 100%% (according to its author)' ), $cur_wp_version );
  317. } else {
  318. /* translators: %s: WordPress version. */
  319. $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %s: Unknown' ), $cur_wp_version );
  320. }
  321. // Get plugin compat for updated version of WordPress.
  322. if ( $core_update_version ) {
  323. if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
  324. /* translators: %s: WordPress version. */
  325. $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %s: 100%% (according to its author)' ), $core_update_version );
  326. } else {
  327. /* translators: %s: WordPress version. */
  328. $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %s: Unknown' ), $core_update_version );
  329. }
  330. }
  331. $requires_php = isset( $plugin_data->update->requires_php ) ? $plugin_data->update->requires_php : null;
  332. $compatible_php = is_php_version_compatible( $requires_php );
  333. if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
  334. $compat .= '<br>' . __( 'This update doesn&#8217;t work with your version of PHP.' ) . '&nbsp;';
  335. $compat .= sprintf(
  336. /* translators: %s: URL to Update PHP page. */
  337. __( '<a href="%s">Learn more about updating PHP</a>.' ),
  338. esc_url( wp_get_update_php_url() )
  339. );
  340. $annotation = wp_get_update_php_annotation();
  341. if ( $annotation ) {
  342. $compat .= '</p><p><em>' . $annotation . '</em>';
  343. }
  344. }
  345. // Get the upgrade notice for the new plugin version.
  346. if ( isset( $plugin_data->update->upgrade_notice ) ) {
  347. $upgrade_notice = '<br />' . strip_tags( $plugin_data->update->upgrade_notice );
  348. } else {
  349. $upgrade_notice = '';
  350. }
  351. $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' );
  352. $details = sprintf(
  353. '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
  354. esc_url( $details_url ),
  355. /* translators: 1: Plugin name, 2: Version number. */
  356. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
  357. /* translators: %s: Plugin version. */
  358. sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
  359. );
  360. $checkbox_id = 'checkbox_' . md5( $plugin_data->Name );
  361. ?>
  362. <tr>
  363. <td class="check-column">
  364. <?php if ( $compatible_php ) : ?>
  365. <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
  366. <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
  367. <?php
  368. /* translators: %s: Plugin name. */
  369. printf( __( 'Select %s' ), $plugin_data->Name );
  370. ?>
  371. </label>
  372. <?php endif; ?>
  373. </td>
  374. <td class="plugin-title"><p>
  375. <?php echo $icon; ?>
  376. <strong><?php echo $plugin_data->Name; ?></strong>
  377. <?php
  378. printf(
  379. /* translators: 1: Plugin version, 2: New version. */
  380. __( 'You have version %1$s installed. Update to %2$s.' ),
  381. $plugin_data->Version,
  382. $plugin_data->update->new_version
  383. );
  384. echo ' ' . $details . $compat . $upgrade_notice;
  385. ?>
  386. </p></td>
  387. </tr>
  388. <?php
  389. }
  390. ?>
  391. </tbody>
  392. <tfoot>
  393. <tr>
  394. <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></td>
  395. <td class="manage-column"><label for="plugins-select-all-2"><?php _e( 'Select All' ); ?></label></td>
  396. </tr>
  397. </tfoot>
  398. </table>
  399. <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
  400. </form>
  401. <?php
  402. }
  403. /**
  404. * Display the upgrade themes form.
  405. *
  406. * @since 2.9.0
  407. */
  408. function list_theme_updates() {
  409. $themes = get_theme_updates();
  410. if ( empty( $themes ) ) {
  411. echo '<h2>' . __( 'Themes' ) . '</h2>';
  412. echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
  413. return;
  414. }
  415. $form_action = 'update-core.php?action=do-theme-upgrade';
  416. ?>
  417. <h2><?php _e( 'Themes' ); ?></h2>
  418. <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>
  419. <p>
  420. <?php
  421. printf(
  422. /* translators: %s: Link to documentation on child themes. */
  423. __( '<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.' ),
  424. __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' )
  425. );
  426. ?>
  427. </p>
  428. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
  429. <?php wp_nonce_field( 'upgrade-core' ); ?>
  430. <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e( 'Update Themes' ); ?>" name="upgrade" /></p>
  431. <table class="widefat updates-table" id="update-themes-table">
  432. <thead>
  433. <tr>
  434. <td class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></td>
  435. <td class="manage-column"><label for="themes-select-all"><?php _e( 'Select All' ); ?></label></td>
  436. </tr>
  437. </thead>
  438. <tbody class="plugins">
  439. <?php
  440. foreach ( $themes as $stylesheet => $theme ) {
  441. $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
  442. ?>
  443. <tr>
  444. <td class="check-column">
  445. <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
  446. <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
  447. <?php
  448. /* translators: %s: Theme name. */
  449. printf( __( 'Select %s' ), $theme->display( 'Name' ) );
  450. ?>
  451. </label>
  452. </td>
  453. <td class="plugin-title"><p>
  454. <img src="<?php echo esc_url( $theme->get_screenshot() ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" />
  455. <strong><?php echo $theme->display( 'Name' ); ?></strong>
  456. <?php
  457. printf(
  458. /* translators: 1: Theme version, 2: New version. */
  459. __( 'You have version %1$s installed. Update to %2$s.' ),
  460. $theme->display( 'Version' ),
  461. $theme->update['new_version']
  462. );
  463. ?>
  464. </p></td>
  465. </tr>
  466. <?php
  467. }
  468. ?>
  469. </tbody>
  470. <tfoot>
  471. <tr>
  472. <td class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></td>
  473. <td class="manage-column"><label for="themes-select-all-2"><?php _e( 'Select All' ); ?></label></td>
  474. </tr>
  475. </tfoot>
  476. </table>
  477. <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Themes' ); ?>" name="upgrade" /></p>
  478. </form>
  479. <?php
  480. }
  481. /**
  482. * Display the update translations form.
  483. *
  484. * @since 3.7.0
  485. */
  486. function list_translation_updates() {
  487. $updates = wp_get_translation_updates();
  488. if ( ! $updates ) {
  489. if ( 'en_US' !== get_locale() ) {
  490. echo '<h2>' . __( 'Translations' ) . '</h2>';
  491. echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
  492. }
  493. return;
  494. }
  495. $form_action = 'update-core.php?action=do-translation-upgrade';
  496. ?>
  497. <h2><?php _e( 'Translations' ); ?></h2>
  498. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
  499. <p><?php _e( 'New translations are available.' ); ?></p>
  500. <?php wp_nonce_field( 'upgrade-translations' ); ?>
  501. <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
  502. </form>
  503. <?php
  504. }
  505. /**
  506. * Upgrade WordPress core display.
  507. *
  508. * @since 2.7.0
  509. *
  510. * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
  511. *
  512. * @param bool $reinstall
  513. */
  514. function do_core_upgrade( $reinstall = false ) {
  515. global $wp_filesystem;
  516. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  517. if ( $reinstall ) {
  518. $url = 'update-core.php?action=do-core-reinstall';
  519. } else {
  520. $url = 'update-core.php?action=do-core-upgrade';
  521. }
  522. $url = wp_nonce_url( $url, 'upgrade-core' );
  523. $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
  524. $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
  525. $update = find_core_update( $version, $locale );
  526. if ( ! $update ) {
  527. return;
  528. }
  529. // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
  530. // that it's safe to do so. This only happens when there are no new files to create.
  531. $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
  532. ?>
  533. <div class="wrap">
  534. <h1><?php _e( 'Update WordPress' ); ?></h1>
  535. <?php
  536. $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
  537. if ( false === $credentials ) {
  538. echo '</div>';
  539. return;
  540. }
  541. if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
  542. // Failed to connect. Error and request again.
  543. request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
  544. echo '</div>';
  545. return;
  546. }
  547. if ( $wp_filesystem->errors->has_errors() ) {
  548. foreach ( $wp_filesystem->errors->get_error_messages() as $message ) {
  549. show_message( $message );
  550. }
  551. echo '</div>';
  552. return;
  553. }
  554. if ( $reinstall ) {
  555. $update->response = 'reinstall';
  556. }
  557. add_filter( 'update_feedback', 'show_message' );
  558. $upgrader = new Core_Upgrader();
  559. $result = $upgrader->upgrade(
  560. $update,
  561. array(
  562. 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
  563. )
  564. );
  565. if ( is_wp_error( $result ) ) {
  566. show_message( $result );
  567. if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() ) {
  568. show_message( __( 'Installation Failed' ) );
  569. }
  570. echo '</div>';
  571. return;
  572. }
  573. show_message( __( 'WordPress updated successfully' ) );
  574. show_message(
  575. '<span class="hide-if-no-js">' . sprintf(
  576. /* translators: 1: WordPress version, 2: URL to About screen. */
  577. __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ),
  578. $result,
  579. esc_url( self_admin_url( 'about.php?updated' ) )
  580. ) . '</span>'
  581. );
  582. show_message(
  583. '<span class="hide-if-js">' . sprintf(
  584. /* translators: 1: WordPress version, 2: URL to About screen. */
  585. __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ),
  586. $result,
  587. esc_url( self_admin_url( 'about.php?updated' ) )
  588. ) . '</span>'
  589. );
  590. ?>
  591. </div>
  592. <script type="text/javascript">
  593. window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
  594. </script>
  595. <?php
  596. }
  597. /**
  598. * Dismiss a core update.
  599. *
  600. * @since 2.7.0
  601. */
  602. function do_dismiss_core_update() {
  603. $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
  604. $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
  605. $update = find_core_update( $version, $locale );
  606. if ( ! $update ) {
  607. return;
  608. }
  609. dismiss_core_update( $update );
  610. wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
  611. exit;
  612. }
  613. /**
  614. * Undismiss a core update.
  615. *
  616. * @since 2.7.0
  617. */
  618. function do_undismiss_core_update() {
  619. $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
  620. $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
  621. $update = find_core_update( $version, $locale );
  622. if ( ! $update ) {
  623. return;
  624. }
  625. undismiss_core_update( $version, $locale );
  626. wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
  627. exit;
  628. }
  629. $action = isset( $_GET['action'] ) ? $_GET['action'] : 'upgrade-core';
  630. $upgrade_error = false;
  631. if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
  632. && ! isset( $_POST['checked'] ) ) {
  633. $upgrade_error = 'do-theme-upgrade' == $action ? 'themes' : 'plugins';
  634. $action = 'upgrade-core';
  635. }
  636. $title = __( 'WordPress Updates' );
  637. $parent_file = 'index.php';
  638. $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>';
  639. $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>';
  640. get_current_screen()->add_help_tab(
  641. array(
  642. 'id' => 'overview',
  643. 'title' => __( 'Overview' ),
  644. 'content' => $updates_overview,
  645. )
  646. );
  647. $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>';
  648. $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>';
  649. if ( 'en_US' !== get_locale() ) {
  650. $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>';
  651. }
  652. get_current_screen()->add_help_tab(
  653. array(
  654. 'id' => 'how-to-update',
  655. 'title' => __( 'How to Update' ),
  656. 'content' => $updates_howto,
  657. )
  658. );
  659. get_current_screen()->set_help_sidebar(
  660. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  661. '<p>' . __( '<a href="https://wordpress.org/support/article/dashboard-updates-screen/">Documentation on Updating WordPress</a>' ) . '</p>' .
  662. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  663. );
  664. if ( 'upgrade-core' == $action ) {
  665. // Force a update check when requested.
  666. $force_check = ! empty( $_GET['force-check'] );
  667. wp_version_check( array(), $force_check );
  668. require_once ABSPATH . 'wp-admin/admin-header.php';
  669. ?>
  670. <div class="wrap">
  671. <h1><?php _e( 'WordPress Updates' ); ?></h1>
  672. <?php
  673. if ( $upgrade_error ) {
  674. echo '<div class="error"><p>';
  675. if ( 'themes' === $upgrade_error ) {
  676. _e( 'Please select one or more themes to update.' );
  677. } else {
  678. _e( 'Please select one or more plugins to update.' );
  679. }
  680. echo '</p></div>';
  681. }
  682. $last_update_check = false;
  683. $current = get_site_transient( 'update_core' );
  684. if ( $current && isset( $current->last_checked ) ) {
  685. $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
  686. }
  687. echo '<p>';
  688. /* translators: 1: Date, 2: Time. */
  689. 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 ) );
  690. echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check Again' ) . '</a>';
  691. echo '</p>';
  692. if ( current_user_can( 'update_core' ) ) {
  693. core_upgrade_preamble();
  694. }
  695. if ( current_user_can( 'update_plugins' ) ) {
  696. list_plugin_updates();
  697. }
  698. if ( current_user_can( 'update_themes' ) ) {
  699. list_theme_updates();
  700. }
  701. if ( current_user_can( 'update_languages' ) ) {
  702. list_translation_updates();
  703. }
  704. /**
  705. * Fires after the core, plugin, and theme update tables.
  706. *
  707. * @since 2.9.0
  708. */
  709. do_action( 'core_upgrade_preamble' );
  710. echo '</div>';
  711. wp_localize_script(
  712. 'updates',
  713. '_wpUpdatesItemCounts',
  714. array(
  715. 'totals' => wp_get_update_data(),
  716. )
  717. );
  718. require_once ABSPATH . 'wp-admin/admin-footer.php';
  719. } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
  720. if ( ! current_user_can( 'update_core' ) ) {
  721. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  722. }
  723. check_admin_referer( 'upgrade-core' );
  724. // Do the (un)dismiss actions before headers, so that they can redirect.
  725. if ( isset( $_POST['dismiss'] ) ) {
  726. do_dismiss_core_update();
  727. } elseif ( isset( $_POST['undismiss'] ) ) {
  728. do_undismiss_core_update();
  729. }
  730. require_once ABSPATH . 'wp-admin/admin-header.php';
  731. if ( 'do-core-reinstall' == $action ) {
  732. $reinstall = true;
  733. } else {
  734. $reinstall = false;
  735. }
  736. if ( isset( $_POST['upgrade'] ) ) {
  737. do_core_upgrade( $reinstall );
  738. }
  739. wp_localize_script(
  740. 'updates',
  741. '_wpUpdatesItemCounts',
  742. array(
  743. 'totals' => wp_get_update_data(),
  744. )
  745. );
  746. require_once ABSPATH . 'wp-admin/admin-footer.php';
  747. } elseif ( 'do-plugin-upgrade' == $action ) {
  748. if ( ! current_user_can( 'update_plugins' ) ) {
  749. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  750. }
  751. check_admin_referer( 'upgrade-core' );
  752. if ( isset( $_GET['plugins'] ) ) {
  753. $plugins = explode( ',', $_GET['plugins'] );
  754. } elseif ( isset( $_POST['checked'] ) ) {
  755. $plugins = (array) $_POST['checked'];
  756. } else {
  757. wp_redirect( admin_url( 'update-core.php' ) );
  758. exit;
  759. }
  760. $url = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
  761. $url = wp_nonce_url( $url, 'bulk-update-plugins' );
  762. $title = __( 'Update Plugins' );
  763. require_once ABSPATH . 'wp-admin/admin-header.php';
  764. echo '<div class="wrap">';
  765. echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
  766. echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="' . esc_attr__( 'Update progress' ) . '"></iframe>';
  767. echo '</div>';
  768. wp_localize_script(
  769. 'updates',
  770. '_wpUpdatesItemCounts',
  771. array(
  772. 'totals' => wp_get_update_data(),
  773. )
  774. );
  775. require_once ABSPATH . 'wp-admin/admin-footer.php';
  776. } elseif ( 'do-theme-upgrade' == $action ) {
  777. if ( ! current_user_can( 'update_themes' ) ) {
  778. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  779. }
  780. check_admin_referer( 'upgrade-core' );
  781. if ( isset( $_GET['themes'] ) ) {
  782. $themes = explode( ',', $_GET['themes'] );
  783. } elseif ( isset( $_POST['checked'] ) ) {
  784. $themes = (array) $_POST['checked'];
  785. } else {
  786. wp_redirect( admin_url( 'update-core.php' ) );
  787. exit;
  788. }
  789. $url = 'update.php?action=update-selected-themes&themes=' . urlencode( implode( ',', $themes ) );
  790. $url = wp_nonce_url( $url, 'bulk-update-themes' );
  791. $title = __( 'Update Themes' );
  792. require_once ABSPATH . 'wp-admin/admin-header.php';
  793. ?>
  794. <div class="wrap">
  795. <h1><?php _e( 'Update Themes' ); ?></h1>
  796. <iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
  797. </div>
  798. <?php
  799. wp_localize_script(
  800. 'updates',
  801. '_wpUpdatesItemCounts',
  802. array(
  803. 'totals' => wp_get_update_data(),
  804. )
  805. );
  806. require_once ABSPATH . 'wp-admin/admin-footer.php';
  807. } elseif ( 'do-translation-upgrade' == $action ) {
  808. if ( ! current_user_can( 'update_languages' ) ) {
  809. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  810. }
  811. check_admin_referer( 'upgrade-translations' );
  812. require_once ABSPATH . 'wp-admin/admin-header.php';
  813. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  814. $url = 'update-core.php?action=do-translation-upgrade';
  815. $nonce = 'upgrade-translations';
  816. $title = __( 'Update Translations' );
  817. $context = WP_LANG_DIR;
  818. $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
  819. $result = $upgrader->bulk_upgrade();
  820. wp_localize_script(
  821. 'updates',
  822. '_wpUpdatesItemCounts',
  823. array(
  824. 'totals' => wp_get_update_data(),
  825. )
  826. );
  827. require_once ABSPATH . 'wp-admin/admin-footer.php';
  828. } else {
  829. /**
  830. * Fires for each custom update action on the WordPress Updates screen.
  831. *
  832. * The dynamic portion of the hook name, `$action`, refers to the
  833. * passed update action. The hook fires in lieu of all available
  834. * default update actions.
  835. *
  836. * @since 3.2.0
  837. */
  838. do_action( "update-core-custom_{$action}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  839. }