Geen omschrijving

update-core.php 43KB

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