PageRenderTime 68ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/update-core.php

https://github.com/markjaquith/WordPress
PHP | 1273 lines | 939 code | 173 blank | 161 comment | 159 complexity | 8ab5030147dcbefd9ecd752643005688 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.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 __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. * @param object $update
  30. */
  31. function list_core_update( $update ) {
  32. global $wp_local_package, $wpdb;
  33. static $first_pass = true;
  34. $wp_version = get_bloginfo( 'version' );
  35. $version_string = sprintf( '%s&ndash;%s', $update->current, get_locale() );
  36. if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
  37. $version_string = $update->current;
  38. } elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
  39. $updates = get_core_updates();
  40. if ( $updates && 1 === count( $updates ) ) {
  41. // If the only available update is a partial builds, it doesn't need a language-specific version string.
  42. $version_string = $update->current;
  43. }
  44. } elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() ) {
  45. $version_string = sprintf( '%s&ndash;%s', $update->current, $update->locale );
  46. }
  47. $current = false;
  48. if ( ! isset( $update->response ) || 'latest' === $update->response ) {
  49. $current = true;
  50. }
  51. $message = '';
  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. // Nightly build versions have two hyphens and a commit number.
  57. if ( preg_match( '/-\w+-\d+/', $update->current ) ) {
  58. // Retrieve the major version number.
  59. preg_match( '/^\d+.\d+/', $update->current, $update_major );
  60. /* translators: %s: WordPress version. */
  61. $submit = sprintf( __( 'Update to latest %s nightly' ), $update_major[0] );
  62. } else {
  63. /* translators: %s: WordPress version. */
  64. $submit = sprintf( __( 'Update to version %s' ), $version_string );
  65. }
  66. if ( 'development' === $update->response ) {
  67. $message = __( 'You can update to the latest nightly build manually:' );
  68. } else {
  69. if ( $current ) {
  70. /* translators: %s: WordPress version. */
  71. $submit = sprintf( __( 'Re-install version %s' ), $version_string );
  72. $form_action = 'update-core.php?action=do-core-reinstall';
  73. } else {
  74. $php_compat = version_compare( $php_version, $update->php_version, '>=' );
  75. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
  76. $mysql_compat = true;
  77. } else {
  78. $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
  79. }
  80. $version_url = sprintf(
  81. /* translators: %s: WordPress version. */
  82. esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
  83. sanitize_title( $update->current )
  84. );
  85. $php_update_message = '</p><p>' . sprintf(
  86. /* translators: %s: URL to Update PHP page. */
  87. __( '<a href="%s">Learn more about updating PHP</a>.' ),
  88. esc_url( wp_get_update_php_url() )
  89. );
  90. $annotation = wp_get_update_php_annotation();
  91. if ( $annotation ) {
  92. $php_update_message .= '</p><p><em>' . $annotation . '</em>';
  93. }
  94. if ( ! $mysql_compat && ! $php_compat ) {
  95. $message = sprintf(
  96. /* 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. */
  97. __( '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.' ),
  98. $version_url,
  99. $update->current,
  100. $update->php_version,
  101. $update->mysql_version,
  102. $php_version,
  103. $mysql_version
  104. ) . $php_update_message;
  105. } elseif ( ! $php_compat ) {
  106. $message = sprintf(
  107. /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
  108. __( '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.' ),
  109. $version_url,
  110. $update->current,
  111. $update->php_version,
  112. $php_version
  113. ) . $php_update_message;
  114. } elseif ( ! $mysql_compat ) {
  115. $message = sprintf(
  116. /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
  117. __( '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.' ),
  118. $version_url,
  119. $update->current,
  120. $update->mysql_version,
  121. $mysql_version
  122. );
  123. } else {
  124. $message = sprintf(
  125. /* translators: 1: Installed WordPress version number, 2: URL to WordPress release notes, 3: New WordPress version number, including locale if necessary. */
  126. __( 'You can update from WordPress %1$s to <a href="%2$s">WordPress %3$s</a> manually:' ),
  127. $wp_version,
  128. $version_url,
  129. $version_string
  130. );
  131. }
  132. if ( ! $mysql_compat || ! $php_compat ) {
  133. $show_buttons = false;
  134. }
  135. }
  136. }
  137. echo '<p>';
  138. echo $message;
  139. echo '</p>';
  140. echo '<form method="post" action="' . esc_url( $form_action ) . '" name="upgrade" class="upgrade">';
  141. wp_nonce_field( 'upgrade-core' );
  142. echo '<p>';
  143. echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden" />';
  144. echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden" />';
  145. if ( $show_buttons ) {
  146. if ( $first_pass ) {
  147. submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
  148. $first_pass = false;
  149. } else {
  150. submit_button( $submit, '', 'upgrade', false );
  151. }
  152. }
  153. if ( 'en_US' !== $update->locale ) {
  154. if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
  155. submit_button( __( 'Hide this update' ), '', 'dismiss', false );
  156. } else {
  157. submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
  158. }
  159. }
  160. echo '</p>';
  161. if ( 'en_US' !== $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
  162. echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes.' ) . '</p>';
  163. } elseif ( 'en_US' === $update->locale && 'en_US' !== get_locale() && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
  164. // Partial builds don't need language-specific warnings.
  165. echo '<p class="hint">' . sprintf(
  166. /* translators: %s: WordPress version. */
  167. __( '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.' ),
  168. 'development' !== $update->response ? $update->current : ''
  169. ) . '</p>';
  170. }
  171. echo '</form>';
  172. }
  173. /**
  174. * Display dismissed updates.
  175. *
  176. * @since 2.7.0
  177. */
  178. function dismissed_updates() {
  179. $dismissed = get_core_updates(
  180. array(
  181. 'dismissed' => true,
  182. 'available' => false,
  183. )
  184. );
  185. if ( $dismissed ) {
  186. $show_text = esc_js( __( 'Show hidden updates' ) );
  187. $hide_text = esc_js( __( 'Hide hidden updates' ) );
  188. ?>
  189. <script type="text/javascript">
  190. jQuery( function( $ ) {
  191. $( '#show-dismissed' ).on( 'click', function() {
  192. var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );
  193. if ( isExpanded ) {
  194. $( this ).text( '<?php echo $show_text; ?>' ).attr( 'aria-expanded', 'false' );
  195. } else {
  196. $( this ).text( '<?php echo $hide_text; ?>' ).attr( 'aria-expanded', 'true' );
  197. }
  198. $( '#dismissed-updates' ).toggle( 'fast' );
  199. });
  200. });
  201. </script>
  202. <?php
  203. echo '<p class="hide-if-no-js"><button type="button" class="button" id="show-dismissed" aria-expanded="false">' . __( 'Show hidden updates' ) . '</button></p>';
  204. echo '<ul id="dismissed-updates" class="core-updates dismissed">';
  205. foreach ( (array) $dismissed as $update ) {
  206. echo '<li>';
  207. list_core_update( $update );
  208. echo '</li>';
  209. }
  210. echo '</ul>';
  211. }
  212. }
  213. /**
  214. * Display upgrade WordPress for downloading latest or upgrading automatically form.
  215. *
  216. * @since 2.7.0
  217. *
  218. * @global string $required_php_version The required PHP version string.
  219. * @global string $required_mysql_version The required MySQL version string.
  220. */
  221. function core_upgrade_preamble() {
  222. global $required_php_version, $required_mysql_version;
  223. $updates = get_core_updates();
  224. // Include an unmodified $wp_version.
  225. require ABSPATH . WPINC . '/version.php';
  226. $is_development_version = preg_match( '/alpha|beta|RC/', $wp_version );
  227. if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
  228. echo '<h2 class="response">';
  229. _e( 'An updated version of WordPress is available.' );
  230. echo '</h2>';
  231. echo '<div class="notice notice-warning inline"><p>';
  232. printf(
  233. /* translators: 1: Documentation on WordPress backups, 2: Documentation on updating WordPress. */
  234. __( '<strong>Important:</strong> Before updating, please <a href="%1$s">back up your database and files</a>. For help with updates, visit the <a href="%2$s">Updating WordPress</a> documentation page.' ),
  235. __( 'https://wordpress.org/support/article/wordpress-backups/' ),
  236. __( 'https://wordpress.org/support/article/updating-wordpress/' )
  237. );
  238. echo '</p></div>';
  239. } elseif ( $is_development_version ) {
  240. echo '<h2 class="response">' . __( 'You are using a development version of WordPress.' ) . '</h2>';
  241. } else {
  242. echo '<h2 class="response">' . __( 'You have the latest version of WordPress.' ) . '</h2>';
  243. }
  244. echo '<ul class="core-updates">';
  245. foreach ( (array) $updates as $update ) {
  246. echo '<li>';
  247. list_core_update( $update );
  248. echo '</li>';
  249. }
  250. echo '</ul>';
  251. // Don't show the maintenance mode notice when we are only showing a single re-install option.
  252. if ( $updates && ( count( $updates ) > 1 || 'latest' !== $updates[0]->response ) ) {
  253. echo '<p>' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, this mode will be deactivated.' ) . '</p>';
  254. } elseif ( ! $updates ) {
  255. list( $normalized_version ) = explode( '-', $wp_version );
  256. echo '<p>' . sprintf(
  257. /* translators: 1: URL to About screen, 2: WordPress version. */
  258. __( '<a href="%1$s">Learn more about WordPress %2$s</a>.' ),
  259. esc_url( self_admin_url( 'about.php' ) ),
  260. $normalized_version
  261. ) . '</p>';
  262. }
  263. dismissed_updates();
  264. }
  265. /**
  266. * Display WordPress auto-updates settings.
  267. *
  268. * @since 5.6.0
  269. */
  270. function core_auto_updates_settings() {
  271. if ( isset( $_GET['core-major-auto-updates-saved'] ) ) {
  272. if ( 'enabled' === $_GET['core-major-auto-updates-saved'] ) {
  273. $notice_text = __( 'Automatic updates for all WordPress versions have been enabled. Thank you!' );
  274. echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
  275. } elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
  276. $notice_text = __( 'WordPress will only receive automatic security and maintenance releases from now on.' );
  277. echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
  278. }
  279. }
  280. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  281. $updater = new WP_Automatic_Updater();
  282. // Defaults:
  283. $upgrade_dev = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
  284. $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
  285. $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
  286. $can_set_update_option = true;
  287. // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false.
  288. if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
  289. if ( false === WP_AUTO_UPDATE_CORE ) {
  290. // Defaults to turned off, unless a filter allows it.
  291. $upgrade_dev = false;
  292. $upgrade_minor = false;
  293. $upgrade_major = false;
  294. } elseif ( true === WP_AUTO_UPDATE_CORE
  295. || in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
  296. ) {
  297. // ALL updates for core.
  298. $upgrade_dev = true;
  299. $upgrade_minor = true;
  300. $upgrade_major = true;
  301. } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
  302. // Only minor updates for core.
  303. $upgrade_dev = false;
  304. $upgrade_minor = true;
  305. $upgrade_major = false;
  306. }
  307. // The UI is overridden by the `WP_AUTO_UPDATE_CORE` constant.
  308. $can_set_update_option = false;
  309. }
  310. if ( $updater->is_disabled() ) {
  311. $upgrade_dev = false;
  312. $upgrade_minor = false;
  313. $upgrade_major = false;
  314. /*
  315. * The UI is overridden by the `AUTOMATIC_UPDATER_DISABLED` constant
  316. * or the `automatic_updater_disabled` filter,
  317. * or by `wp_is_file_mod_allowed( 'automatic_updater' )`.
  318. * See `WP_Automatic_Updater::is_disabled()`.
  319. */
  320. $can_set_update_option = false;
  321. }
  322. // Is the UI overridden by a plugin using the `allow_major_auto_core_updates` filter?
  323. if ( has_filter( 'allow_major_auto_core_updates' ) ) {
  324. $can_set_update_option = false;
  325. }
  326. /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
  327. $upgrade_dev = apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev );
  328. /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
  329. $upgrade_minor = apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
  330. /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
  331. $upgrade_major = apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
  332. $auto_update_settings = array(
  333. 'dev' => $upgrade_dev,
  334. 'minor' => $upgrade_minor,
  335. 'major' => $upgrade_major,
  336. );
  337. if ( $upgrade_major ) {
  338. $wp_version = get_bloginfo( 'version' );
  339. $updates = get_core_updates();
  340. if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
  341. echo '<p>' . wp_get_auto_update_message() . '</p>';
  342. }
  343. }
  344. $action_url = self_admin_url( 'update-core.php?action=core-major-auto-updates-settings' );
  345. ?>
  346. <p class="auto-update-status">
  347. <?php
  348. if ( $updater->is_vcs_checkout( ABSPATH ) ) {
  349. _e( 'This site appears to be under version control. Automatic updates are disabled.' );
  350. } elseif ( $upgrade_major ) {
  351. _e( 'This site is automatically kept up to date with each new version of WordPress.' );
  352. if ( $can_set_update_option ) {
  353. echo '<br>';
  354. printf(
  355. '<a href="%s" class="core-auto-update-settings-link core-auto-update-settings-link-disable">%s</a>',
  356. wp_nonce_url( add_query_arg( 'value', 'disable', $action_url ), 'core-major-auto-updates-nonce' ),
  357. __( 'Switch to automatic updates for maintenance and security releases only.' )
  358. );
  359. }
  360. } elseif ( $upgrade_minor ) {
  361. _e( 'This site is automatically kept up to date with maintenance and security releases of WordPress only.' );
  362. if ( $can_set_update_option ) {
  363. echo '<br>';
  364. printf(
  365. '<a href="%s" class="core-auto-update-settings-link core-auto-update-settings-link-enable">%s</a>',
  366. wp_nonce_url( add_query_arg( 'value', 'enable', $action_url ), 'core-major-auto-updates-nonce' ),
  367. __( 'Enable automatic updates for all new versions of WordPress.' )
  368. );
  369. }
  370. } else {
  371. _e( 'This site will not receive automatic updates for new versions of WordPress.' );
  372. }
  373. ?>
  374. </p>
  375. <?php
  376. /**
  377. * Fires after the major core auto-update settings.
  378. *
  379. * @since 5.6.0
  380. *
  381. * @param array $auto_update_settings {
  382. * Array of core auto-update settings.
  383. *
  384. * @type bool $dev Whether to enable automatic updates for development versions.
  385. * @type bool $minor Whether to enable minor automatic core updates.
  386. * @type bool $major Whether to enable major automatic core updates.
  387. * }
  388. */
  389. do_action( 'after_core_auto_updates_settings', $auto_update_settings );
  390. }
  391. /**
  392. * Display the upgrade plugins form.
  393. *
  394. * @since 2.9.0
  395. */
  396. function list_plugin_updates() {
  397. $wp_version = get_bloginfo( 'version' );
  398. $cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
  399. require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
  400. $plugins = get_plugin_updates();
  401. if ( empty( $plugins ) ) {
  402. echo '<h2>' . __( 'Plugins' ) . '</h2>';
  403. echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
  404. return;
  405. }
  406. $form_action = 'update-core.php?action=do-plugin-upgrade';
  407. $core_updates = get_core_updates();
  408. 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, '=' ) ) {
  409. $core_update_version = false;
  410. } else {
  411. $core_update_version = $core_updates[0]->current;
  412. }
  413. $plugins_count = count( $plugins );
  414. ?>
  415. <h2>
  416. <?php
  417. printf(
  418. '%s <span class="count">(%d)</span>',
  419. __( 'Plugins' ),
  420. number_format_i18n( $plugins_count )
  421. );
  422. ?>
  423. </h2>
  424. <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>
  425. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
  426. <?php wp_nonce_field( 'upgrade-core' ); ?>
  427. <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
  428. <table class="widefat updates-table" id="update-plugins-table">
  429. <thead>
  430. <tr>
  431. <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></td>
  432. <td class="manage-column"><label for="plugins-select-all"><?php _e( 'Select All' ); ?></label></td>
  433. </tr>
  434. </thead>
  435. <tbody class="plugins">
  436. <?php
  437. $auto_updates = array();
  438. if ( wp_is_auto_update_enabled_for_type( 'plugin' ) ) {
  439. $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
  440. $auto_update_notice = ' | ' . wp_get_auto_update_message();
  441. }
  442. foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
  443. $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
  444. $icon = '<span class="dashicons dashicons-admin-plugins"></span>';
  445. $preferred_icons = array( 'svg', '2x', '1x', 'default' );
  446. foreach ( $preferred_icons as $preferred_icon ) {
  447. if ( ! empty( $plugin_data->update->icons[ $preferred_icon ] ) ) {
  448. $icon = '<img src="' . esc_url( $plugin_data->update->icons[ $preferred_icon ] ) . '" alt="" />';
  449. break;
  450. }
  451. }
  452. // Get plugin compat for running version of WordPress.
  453. if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) {
  454. /* translators: %s: WordPress version. */
  455. $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %s: 100%% (according to its author)' ), $cur_wp_version );
  456. } else {
  457. /* translators: %s: WordPress version. */
  458. $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %s: Unknown' ), $cur_wp_version );
  459. }
  460. // Get plugin compat for updated version of WordPress.
  461. if ( $core_update_version ) {
  462. if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
  463. /* translators: %s: WordPress version. */
  464. $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %s: 100%% (according to its author)' ), $core_update_version );
  465. } else {
  466. /* translators: %s: WordPress version. */
  467. $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %s: Unknown' ), $core_update_version );
  468. }
  469. }
  470. $requires_php = isset( $plugin_data->update->requires_php ) ? $plugin_data->update->requires_php : null;
  471. $compatible_php = is_php_version_compatible( $requires_php );
  472. if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
  473. $compat .= '<br>' . __( 'This update doesn&#8217;t work with your version of PHP.' ) . '&nbsp;';
  474. $compat .= sprintf(
  475. /* translators: %s: URL to Update PHP page. */
  476. __( '<a href="%s">Learn more about updating PHP</a>.' ),
  477. esc_url( wp_get_update_php_url() )
  478. );
  479. $annotation = wp_get_update_php_annotation();
  480. if ( $annotation ) {
  481. $compat .= '</p><p><em>' . $annotation . '</em>';
  482. }
  483. }
  484. // Get the upgrade notice for the new plugin version.
  485. if ( isset( $plugin_data->update->upgrade_notice ) ) {
  486. $upgrade_notice = '<br />' . strip_tags( $plugin_data->update->upgrade_notice );
  487. } else {
  488. $upgrade_notice = '';
  489. }
  490. $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' );
  491. $details = sprintf(
  492. '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
  493. esc_url( $details_url ),
  494. /* translators: 1: Plugin name, 2: Version number. */
  495. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
  496. /* translators: %s: Plugin version. */
  497. sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
  498. );
  499. $checkbox_id = 'checkbox_' . md5( $plugin_file );
  500. ?>
  501. <tr>
  502. <td class="check-column">
  503. <?php if ( $compatible_php ) : ?>
  504. <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
  505. <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
  506. <?php
  507. /* translators: %s: Plugin name. */
  508. printf( __( 'Select %s' ), $plugin_data->Name );
  509. ?>
  510. </label>
  511. <?php endif; ?>
  512. </td>
  513. <td class="plugin-title"><p>
  514. <?php echo $icon; ?>
  515. <strong><?php echo $plugin_data->Name; ?></strong>
  516. <?php
  517. printf(
  518. /* translators: 1: Plugin version, 2: New version. */
  519. __( 'You have version %1$s installed. Update to %2$s.' ),
  520. $plugin_data->Version,
  521. $plugin_data->update->new_version
  522. );
  523. echo ' ' . $details . $compat . $upgrade_notice;
  524. if ( in_array( $plugin_file, $auto_updates, true ) ) {
  525. echo $auto_update_notice;
  526. }
  527. ?>
  528. </p></td>
  529. </tr>
  530. <?php
  531. }
  532. ?>
  533. </tbody>
  534. <tfoot>
  535. <tr>
  536. <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></td>
  537. <td class="manage-column"><label for="plugins-select-all-2"><?php _e( 'Select All' ); ?></label></td>
  538. </tr>
  539. </tfoot>
  540. </table>
  541. <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
  542. </form>
  543. <?php
  544. }
  545. /**
  546. * Display the upgrade themes form.
  547. *
  548. * @since 2.9.0
  549. */
  550. function list_theme_updates() {
  551. $themes = get_theme_updates();
  552. if ( empty( $themes ) ) {
  553. echo '<h2>' . __( 'Themes' ) . '</h2>';
  554. echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
  555. return;
  556. }
  557. $form_action = 'update-core.php?action=do-theme-upgrade';
  558. $themes_count = count( $themes );
  559. ?>
  560. <h2>
  561. <?php
  562. printf(
  563. '%s <span class="count">(%d)</span>',
  564. __( 'Themes' ),
  565. number_format_i18n( $themes_count )
  566. );
  567. ?>
  568. </h2>
  569. <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>
  570. <p>
  571. <?php
  572. printf(
  573. /* translators: %s: Link to documentation on child themes. */
  574. __( '<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.' ),
  575. __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' )
  576. );
  577. ?>
  578. </p>
  579. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
  580. <?php wp_nonce_field( 'upgrade-core' ); ?>
  581. <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e( 'Update Themes' ); ?>" name="upgrade" /></p>
  582. <table class="widefat updates-table" id="update-themes-table">
  583. <thead>
  584. <tr>
  585. <td class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></td>
  586. <td class="manage-column"><label for="themes-select-all"><?php _e( 'Select All' ); ?></label></td>
  587. </tr>
  588. </thead>
  589. <tbody class="plugins">
  590. <?php
  591. $auto_updates = array();
  592. if ( wp_is_auto_update_enabled_for_type( 'theme' ) ) {
  593. $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
  594. $auto_update_notice = ' | ' . wp_get_auto_update_message();
  595. }
  596. foreach ( $themes as $stylesheet => $theme ) {
  597. $requires_wp = isset( $theme->update['requires'] ) ? $theme->update['requires'] : null;
  598. $requires_php = isset( $theme->update['requires_php'] ) ? $theme->update['requires_php'] : null;
  599. $compatible_wp = is_wp_version_compatible( $requires_wp );
  600. $compatible_php = is_php_version_compatible( $requires_php );
  601. $compat = '';
  602. if ( ! $compatible_wp && ! $compatible_php ) {
  603. $compat .= '<br>' . __( 'This update doesn&#8217;t work with your versions of WordPress and PHP.' ) . '&nbsp;';
  604. if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
  605. $compat .= sprintf(
  606. /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
  607. __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
  608. self_admin_url( 'update-core.php' ),
  609. esc_url( wp_get_update_php_url() )
  610. );
  611. $annotation = wp_get_update_php_annotation();
  612. if ( $annotation ) {
  613. $compat .= '</p><p><em>' . $annotation . '</em>';
  614. }
  615. } elseif ( current_user_can( 'update_core' ) ) {
  616. $compat .= sprintf(
  617. /* translators: %s: URL to WordPress Updates screen. */
  618. __( '<a href="%s">Please update WordPress</a>.' ),
  619. self_admin_url( 'update-core.php' )
  620. );
  621. } elseif ( current_user_can( 'update_php' ) ) {
  622. $compat .= sprintf(
  623. /* translators: %s: URL to Update PHP page. */
  624. __( '<a href="%s">Learn more about updating PHP</a>.' ),
  625. esc_url( wp_get_update_php_url() )
  626. );
  627. $annotation = wp_get_update_php_annotation();
  628. if ( $annotation ) {
  629. $compat .= '</p><p><em>' . $annotation . '</em>';
  630. }
  631. }
  632. } elseif ( ! $compatible_wp ) {
  633. $compat .= '<br>' . __( 'This update doesn&#8217;t work with your version of WordPress.' ) . '&nbsp;';
  634. if ( current_user_can( 'update_core' ) ) {
  635. $compat .= sprintf(
  636. /* translators: %s: URL to WordPress Updates screen. */
  637. __( '<a href="%s">Please update WordPress</a>.' ),
  638. self_admin_url( 'update-core.php' )
  639. );
  640. }
  641. } elseif ( ! $compatible_php ) {
  642. $compat .= '<br>' . __( 'This update doesn&#8217;t work with your version of PHP.' ) . '&nbsp;';
  643. if ( current_user_can( 'update_php' ) ) {
  644. $compat .= sprintf(
  645. /* translators: %s: URL to Update PHP page. */
  646. __( '<a href="%s">Learn more about updating PHP</a>.' ),
  647. esc_url( wp_get_update_php_url() )
  648. );
  649. $annotation = wp_get_update_php_annotation();
  650. if ( $annotation ) {
  651. $compat .= '</p><p><em>' . $annotation . '</em>';
  652. }
  653. }
  654. }
  655. $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
  656. ?>
  657. <tr>
  658. <td class="check-column">
  659. <?php if ( $compatible_wp && $compatible_php ) : ?>
  660. <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
  661. <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
  662. <?php
  663. /* translators: %s: Theme name. */
  664. printf( __( 'Select %s' ), $theme->display( 'Name' ) );
  665. ?>
  666. </label>
  667. <?php endif; ?>
  668. </td>
  669. <td class="plugin-title"><p>
  670. <img src="<?php echo esc_url( $theme->get_screenshot() ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" />
  671. <strong><?php echo $theme->display( 'Name' ); ?></strong>
  672. <?php
  673. printf(
  674. /* translators: 1: Theme version, 2: New version. */
  675. __( 'You have version %1$s installed. Update to %2$s.' ),
  676. $theme->display( 'Version' ),
  677. $theme->update['new_version']
  678. );
  679. echo ' ' . $compat;
  680. if ( in_array( $stylesheet, $auto_updates, true ) ) {
  681. echo $auto_update_notice;
  682. }
  683. ?>
  684. </p></td>
  685. </tr>
  686. <?php
  687. }
  688. ?>
  689. </tbody>
  690. <tfoot>
  691. <tr>
  692. <td class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></td>
  693. <td class="manage-column"><label for="themes-select-all-2"><?php _e( 'Select All' ); ?></label></td>
  694. </tr>
  695. </tfoot>
  696. </table>
  697. <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Themes' ); ?>" name="upgrade" /></p>
  698. </form>
  699. <?php
  700. }
  701. /**
  702. * Display the update translations form.
  703. *
  704. * @since 3.7.0
  705. */
  706. function list_translation_updates() {
  707. $updates = wp_get_translation_updates();
  708. if ( ! $updates ) {
  709. if ( 'en_US' !== get_locale() ) {
  710. echo '<h2>' . __( 'Translations' ) . '</h2>';
  711. echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
  712. }
  713. return;
  714. }
  715. $form_action = 'update-core.php?action=do-translation-upgrade';
  716. ?>
  717. <h2><?php _e( 'Translations' ); ?></h2>
  718. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
  719. <p><?php _e( 'New translations are available.' ); ?></p>
  720. <?php wp_nonce_field( 'upgrade-translations' ); ?>
  721. <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
  722. </form>
  723. <?php
  724. }
  725. /**
  726. * Upgrade WordPress core display.
  727. *
  728. * @since 2.7.0
  729. *
  730. * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
  731. *
  732. * @param bool $reinstall
  733. */
  734. function do_core_upgrade( $reinstall = false ) {
  735. global $wp_filesystem;
  736. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  737. if ( $reinstall ) {
  738. $url = 'update-core.php?action=do-core-reinstall';
  739. } else {
  740. $url = 'update-core.php?action=do-core-upgrade';
  741. }
  742. $url = wp_nonce_url( $url, 'upgrade-core' );
  743. $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
  744. $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
  745. $update = find_core_update( $version, $locale );
  746. if ( ! $update ) {
  747. return;
  748. }
  749. // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
  750. // that it's safe to do so. This only happens when there are no new files to create.
  751. $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
  752. ?>
  753. <div class="wrap">
  754. <h1><?php _e( 'Update WordPress' ); ?></h1>
  755. <?php
  756. $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
  757. if ( false === $credentials ) {
  758. echo '</div>';
  759. return;
  760. }
  761. if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
  762. // Failed to connect. Error and request again.
  763. request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
  764. echo '</div>';
  765. return;
  766. }
  767. if ( $wp_filesystem->errors->has_errors() ) {
  768. foreach ( $wp_filesystem->errors->get_error_messages() as $message ) {
  769. show_message( $message );
  770. }
  771. echo '</div>';
  772. return;
  773. }
  774. if ( $reinstall ) {
  775. $update->response = 'reinstall';
  776. }
  777. add_filter( 'update_feedback', 'show_message' );
  778. $upgrader = new Core_Upgrader();
  779. $result = $upgrader->upgrade(
  780. $update,
  781. array(
  782. 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
  783. )
  784. );
  785. if ( is_wp_error( $result ) ) {
  786. show_message( $result );
  787. if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() ) {
  788. show_message( __( 'Installation failed.' ) );
  789. }
  790. echo '</div>';
  791. return;
  792. }
  793. show_message( __( 'WordPress updated successfully.' ) );
  794. show_message(
  795. '<span class="hide-if-no-js">' . sprintf(
  796. /* translators: 1: WordPress version, 2: URL to About screen. */
  797. __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ),
  798. $result,
  799. esc_url( self_admin_url( 'about.php?updated' ) )
  800. ) . '</span>'
  801. );
  802. show_message(
  803. '<span class="hide-if-js">' . sprintf(
  804. /* translators: 1: WordPress version, 2: URL to About screen. */
  805. __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ),
  806. $result,
  807. esc_url( self_admin_url( 'about.php?updated' ) )
  808. ) . '</span>'
  809. );
  810. ?>
  811. </div>
  812. <script type="text/javascript">
  813. window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
  814. </script>
  815. <?php
  816. }
  817. /**
  818. * Dismiss a core update.
  819. *
  820. * @since 2.7.0
  821. */
  822. function do_dismiss_core_update() {
  823. $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
  824. $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
  825. $update = find_core_update( $version, $locale );
  826. if ( ! $update ) {
  827. return;
  828. }
  829. dismiss_core_update( $update );
  830. wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
  831. exit;
  832. }
  833. /**
  834. * Undismiss a core update.
  835. *
  836. * @since 2.7.0
  837. */
  838. function do_undismiss_core_update() {
  839. $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
  840. $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
  841. $update = find_core_update( $version, $locale );
  842. if ( ! $update ) {
  843. return;
  844. }
  845. undismiss_core_update( $version, $locale );
  846. wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
  847. exit;
  848. }
  849. $action = isset( $_GET['action'] ) ? $_GET['action'] : 'upgrade-core';
  850. $upgrade_error = false;
  851. if ( ( 'do-theme-upgrade' === $action || ( 'do-plugin-upgrade' === $action && ! isset( $_GET['plugins'] ) ) )
  852. && ! isset( $_POST['checked'] ) ) {
  853. $upgrade_error = ( 'do-theme-upgrade' === $action ) ? 'themes' : 'plugins';
  854. $action = 'upgrade-core';
  855. }
  856. $title = __( 'WordPress Updates' );
  857. $parent_file = 'index.php';
  858. $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>';
  859. $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>';
  860. get_current_screen()->add_help_tab(
  861. array(
  862. 'id' => 'overview',
  863. 'title' => __( 'Overview' ),
  864. 'content' => $updates_overview,
  865. )
  866. );
  867. $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>';
  868. $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>';
  869. if ( 'en_US' !== get_locale() ) {
  870. $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>';
  871. }
  872. get_current_screen()->add_help_tab(
  873. array(
  874. 'id' => 'how-to-update',
  875. 'title' => __( 'How to Update' ),
  876. 'content' => $updates_howto,
  877. )
  878. );
  879. $help_sidebar_autoupdates = '';
  880. if ( ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) || ( current_user_can( 'update_plugins' ) && wp_is_auto_update_enabled_for_type( 'plugin' ) ) ) {
  881. $help_tab_autoupdates = '<p>' . __( 'Auto-updates can be enabled or disabled for WordPress major versions and for each individual theme or plugin. Themes or plugins with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>';
  882. $help_tab_autoupdates .= '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>';
  883. get_current_screen()->add_help_tab(
  884. array(
  885. 'id' => 'plugins-themes-auto-updates',
  886. 'title' => __( 'Auto-updates' ),
  887. 'content' => $help_tab_autoupdates,
  888. )
  889. );
  890. $help_sidebar_autoupdates = '<p>' . __( '<a href="https://wordpress.org/support/article/plugins-themes-auto-updates/">Learn more: Auto-updates documentation</a>' ) . '</p>';
  891. }
  892. get_current_screen()->set_help_sidebar(
  893. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  894. '<p>' . __( '<a href="https://wordpress.org/support/article/dashboard-updates-screen/">Documentation on Updating WordPress</a>' ) . '</p>' .
  895. $help_sidebar_autoupdates .
  896. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  897. );
  898. if ( 'upgrade-core' === $action ) {
  899. // Force a update check when requested.
  900. $force_check = ! empty( $_GET['force-check'] );
  901. wp_version_check( array(), $force_check );
  902. require_once ABSPATH . 'wp-admin/admin-header.php';
  903. ?>
  904. <div class="wrap">
  905. <h1><?php _e( 'WordPress Updates' ); ?></h1>
  906. <p><?php _e( 'Here you can find information about updates, set auto-updates and see what plugins or themes need updating.' ); ?></p>
  907. <?php
  908. if ( $upgrade_error ) {
  909. echo '<div class="error"><p>';
  910. if ( 'themes' === $upgrade_error ) {
  911. _e( 'Please select one or more themes to update.' );
  912. } else {
  913. _e( 'Please select one or more plugins to update.' );
  914. }
  915. echo '</p></div>';
  916. }
  917. $last_update_check = false;
  918. $current = get_site_transient( 'update_core' );
  919. if ( $current && isset( $current->last_checked ) ) {
  920. $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
  921. }
  922. echo '<h2 class="wp-current-version">';
  923. /* translators: Current version of WordPress. */
  924. printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) );
  925. echo '</h2>';
  926. echo '<p class="update-last-checked">';
  927. /* translators: 1: Date, 2: Time. */
  928. printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ), $last_update_check ), date_i18n( __( 'g:i a T' ), $last_update_check ) );
  929. echo ' <a href="' . esc_url( self_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check again.' ) . '</a>';
  930. echo '</p>';
  931. if ( current_user_can( 'update_core' ) ) {
  932. core_auto_updates_settings();
  933. core_upgrade_preamble();
  934. }
  935. if ( current_user_can( 'update_plugins' ) ) {
  936. list_plugin_updates();
  937. }
  938. if ( current_user_can( 'update_themes' ) ) {
  939. list_theme_updates();
  940. }
  941. if ( current_user_can( 'update_languages' ) ) {
  942. list_translation_updates();
  943. }
  944. /**
  945. * Fires after the core, plugin, and theme update tables.
  946. *
  947. * @since 2.9.0
  948. */
  949. do_action( 'core_upgrade_preamble' );
  950. echo '</div>';
  951. wp_localize_script(
  952. 'updates',
  953. '_wpUpdatesItemCounts',
  954. array(
  955. 'totals' => wp_get_update_data(),
  956. )
  957. );
  958. require_once ABSPATH . 'wp-admin/admin-footer.php';
  959. } elseif ( 'do-core-upgrade' === $action || 'do-core-reinstall' === $action ) {
  960. if ( ! current_user_can( 'update_core' ) ) {
  961. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  962. }
  963. check_admin_referer( 'upgrade-core' );
  964. // Do the (un)dismiss actions before headers, so that they can redirect.
  965. if ( isset( $_POST['dismiss'] ) ) {
  966. do_dismiss_core_update();
  967. } elseif ( isset( $_POST['undismiss'] ) ) {
  968. do_undismiss_core_update();
  969. }
  970. require_once ABSPATH . 'wp-admin/admin-header.php';
  971. if ( 'do-core-reinstall' === $action ) {
  972. $reinstall = true;
  973. } else {
  974. $reinstall = false;
  975. }
  976. if ( isset( $_POST['upgrade'] ) ) {
  977. do_core_upgrade( $reinstall );
  978. }
  979. wp_localize_script(
  980. 'updates',
  981. '_wpUpdatesItemCounts',
  982. array(
  983. 'totals' => wp_get_update_data(),
  984. )
  985. );
  986. require_once ABSPATH . 'wp-admin/admin-footer.php';
  987. } elseif ( 'do-plugin-upgrade' === $action ) {
  988. if ( ! current_user_can( 'update_plugins' ) ) {
  989. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  990. }
  991. check_admin_referer( 'upgrade-core' );
  992. if ( isset( $_GET['plugins'] ) ) {
  993. $plugins = explode( ',', $_GET['plugins'] );
  994. } elseif ( isset( $_POST['checked'] ) ) {
  995. $plugins = (array) $_POST['checked'];
  996. } else {
  997. wp_redirect( admin_url( 'update-core.php' ) );
  998. exit;
  999. }
  1000. $url = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
  1001. $url = wp_nonce_url( $url, 'bulk-update-plugins' );
  1002. // Used in the HTML title tag.
  1003. $title = __( 'Update Plugins' );
  1004. require_once ABSPATH . 'wp-admin/admin-header.php';
  1005. ?>
  1006. <div class="wrap">
  1007. <h1><?php _e( 'Update Plugins' ); ?></h1>
  1008. <iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
  1009. </div>
  1010. <?php
  1011. wp_localize_script(
  1012. 'updates',
  1013. '_wpUpdatesItemCounts',
  1014. array(
  1015. 'totals' => wp_get_update_data(),
  1016. )
  1017. );
  1018. require_once ABSPATH . 'wp-admin/admin-footer.php';
  1019. } elseif ( 'do-theme-upgrade' === $action ) {
  1020. if ( ! current_user_can( 'update_themes' ) ) {
  1021. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  1022. }
  1023. check_admin_referer( 'upgrade-core' );
  1024. if ( isset( $_GET['themes'] ) ) {
  1025. $themes = explode( ',', $_GET['themes'] );
  1026. } elseif ( isset( $_POST['checked'] ) ) {
  1027. $themes = (array) $_POST['checked'];
  1028. } else {
  1029. wp_redirect( admin_url( 'update-core.php' ) );
  1030. exit;
  1031. }
  1032. $url = 'update.php?action=update-selected-themes&themes=' . urlencode( implode( ',', $themes ) );
  1033. $url = wp_nonce_url( $url, 'bulk-update-themes' );
  1034. // Used in the HTML title tag.
  1035. $title = __( 'Update Themes' );
  1036. require_once ABSPATH . 'wp-admin/admin-header.php';
  1037. ?>
  1038. <div class="wrap">
  1039. <h1><?php _e( 'Update Themes' ); ?></h1>
  1040. <iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
  1041. </div>
  1042. <?php
  1043. wp_localize_script(
  1044. 'updates',
  1045. '_wpUpdatesItemCounts',
  1046. array(
  1047. 'totals' => wp_get_update_data(),
  1048. )
  1049. );
  1050. require_once ABSPATH . 'wp-admin/admin-footer.php';
  1051. } elseif ( 'do-translation-upgrade' === $action ) {
  1052. if ( ! current_user_can( 'update_languages' ) ) {
  1053. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  1054. }
  1055. check_admin_referer( 'upgrade-translations' );
  1056. require_once ABSPATH . 'wp-admin/admin-header.php';
  1057. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  1058. $url = 'update-core.php?action=do-translation-upgrade';
  1059. $nonce = 'upgrade-translations';
  1060. $title = __( 'Update Translations' );
  1061. $context = WP_LANG_DIR;
  1062. $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
  1063. $result = $upgrader->bulk_upgrade();
  1064. wp_localize_script(
  1065. 'updates',
  1066. '_wpUpdatesItemCounts',
  1067. array(
  1068. 'totals' => wp_get_update_data(),
  1069. )
  1070. );
  1071. require_once ABSPATH . 'wp-admin/admin-footer.php';
  1072. } elseif ( 'core-major-auto-updates-settings' === $action ) {
  1073. if ( ! current_user_can( 'update_core' ) ) {
  1074. wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  1075. }
  1076. $redirect_url = self_admin_url( 'update-core.php' );
  1077. if ( isset( $_GET['value'] ) ) {
  1078. check_admin_referer( 'core-major-auto-updates-nonce' );
  1079. if ( 'enable' === $_GET['value'] ) {
  1080. update_site_option( 'auto_update_core_major', 'enabled' );
  1081. $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'enabled', $redirect_url );
  1082. } elseif ( 'disable' === $_GET['value'] ) {
  1083. update_site_option( 'auto_update_core_major', 'disabled' );
  1084. $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'disabled', $redirect_url );
  1085. }
  1086. }
  1087. wp_redirect( $redirect_url );
  1088. exit;
  1089. } else {
  1090. /**
  1091. * Fires for each custom update action on the WordPress Updates screen.
  1092. *
  1093. * The dynamic portion of the hook name, `$action`, refers to the
  1094. * passed update action. The hook fires in lieu of all available
  1095. * default update actions.
  1096. *
  1097. * @since 3.2.0
  1098. */
  1099. do_action( "update-core-custom_{$action}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  1100. }