PageRenderTime 66ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/wordpress-dev/wp-admin/update-core.php

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