update-core.php 33 KB

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