PageRenderTime 77ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/update-core.php

https://gitlab.com/geyson/geyson
PHP | 693 lines | 520 code | 93 blank | 80 comment | 139 complexity | c6625741d6e0a3c252633dc7545ceeb4 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  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' ) )
  19. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  20. /**
  21. *
  22. * @global string $wp_local_package
  23. * @global wpdb $wpdb
  24. * @global string $wp_version
  25. *
  26. * @staticvar bool $first_pass
  27. *
  28. * @param object $update
  29. */
  30. function list_core_update( $update ) {
  31. global $wp_local_package, $wpdb, $wp_version;
  32. static $first_pass = true;
  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 or download the nightly build and install it manually:');
  50. $download = __('Download nightly build');
  51. } else {
  52. if ( $current ) {
  53. $message = sprintf( __( 'If you need to re-install version %s, you can do so here or download the package and re-install manually:' ), $version_string );
  54. $submit = __('Re-install Now');
  55. $form_action = 'update-core.php?action=do-core-reinstall';
  56. } else {
  57. $php_compat = version_compare( $php_version, $update->php_version, '>=' );
  58. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
  59. $mysql_compat = true;
  60. else
  61. $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
  62. if ( !$mysql_compat && !$php_compat )
  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. $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 );
  66. elseif ( !$mysql_compat )
  67. $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 );
  68. else
  69. $message = sprintf(__('You can update to <a href="https://codex.wordpress.org/Version_%1$s">WordPress %2$s</a> automatically or download the package and install it manually:'), $update->current, $version_string);
  70. if ( !$mysql_compat || !$php_compat )
  71. $show_buttons = false;
  72. }
  73. $download = sprintf(__('Download %s'), $version_string);
  74. }
  75. echo '<p>';
  76. echo $message;
  77. echo '</p>';
  78. echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
  79. wp_nonce_field('upgrade-core');
  80. echo '<p>';
  81. echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
  82. echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
  83. if ( $show_buttons ) {
  84. if ( $first_pass ) {
  85. submit_button( $submit, $current ? 'button' : 'primary regular', 'upgrade', false );
  86. $first_pass = false;
  87. } else {
  88. submit_button( $submit, 'button', 'upgrade', false );
  89. }
  90. echo '&nbsp;<a href="' . esc_url( $update->download ) . '" class="button">' . $download . '</a>&nbsp;';
  91. }
  92. if ( 'en_US' != $update->locale )
  93. if ( !isset( $update->dismissed ) || !$update->dismissed )
  94. submit_button( __('Hide this update'), 'button', 'dismiss', false );
  95. else
  96. submit_button( __('Bring back this update'), 'button', 'undismiss', false );
  97. echo '</p>';
  98. if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
  99. 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>';
  100. // Partial builds don't need language-specific warnings.
  101. elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
  102. 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>';
  103. }
  104. echo '</form>';
  105. }
  106. /**
  107. * @since 2.7.0
  108. */
  109. function dismissed_updates() {
  110. $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
  111. if ( $dismissed ) {
  112. $show_text = esc_js(__('Show hidden updates'));
  113. $hide_text = esc_js(__('Hide hidden updates'));
  114. ?>
  115. <script type="text/javascript">
  116. jQuery(function($) {
  117. $('dismissed-updates').show();
  118. $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
  119. $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
  120. });
  121. </script>
  122. <?php
  123. echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
  124. echo '<ul id="dismissed-updates" class="core-updates dismissed">';
  125. foreach( (array) $dismissed as $update) {
  126. echo '<li>';
  127. list_core_update( $update );
  128. echo '</li>';
  129. }
  130. echo '</ul>';
  131. }
  132. }
  133. /**
  134. * Display upgrade WordPress for downloading latest or upgrading automatically form.
  135. *
  136. * @since 2.7.0
  137. *
  138. * @global string $wp_version
  139. * @global string $required_php_version
  140. * @global string $required_mysql_version
  141. */
  142. function core_upgrade_preamble() {
  143. global $wp_version, $required_php_version, $required_mysql_version;
  144. $updates = get_core_updates();
  145. if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
  146. echo '<h3>';
  147. _e('You have the latest version of WordPress.');
  148. if ( wp_http_supports( array( 'ssl' ) ) ) {
  149. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  150. $upgrader = new WP_Automatic_Updater;
  151. $future_minor_update = (object) array(
  152. 'current' => $wp_version . '.1.next.minor',
  153. 'version' => $wp_version . '.1.next.minor',
  154. 'php_version' => $required_php_version,
  155. 'mysql_version' => $required_mysql_version,
  156. );
  157. $should_auto_update = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
  158. if ( $should_auto_update )
  159. echo ' ' . __( 'Future security updates will be applied automatically.' );
  160. }
  161. echo '</h3>';
  162. } else {
  163. echo '<div class="notice notice-warning"><p>';
  164. _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.');
  165. echo '</p></div>';
  166. echo '<h3 class="response">';
  167. _e( 'An updated version of WordPress is available.' );
  168. echo '</h3>';
  169. }
  170. if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) {
  171. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  172. $upgrader = new WP_Automatic_Updater;
  173. if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) ) {
  174. echo '<div class="updated inline"><p>';
  175. echo '<strong>' . __( 'BETA TESTERS:' ) . '</strong> ' . __( 'This site is set up to install updates of future beta versions automatically.' );
  176. echo '</p></div>';
  177. }
  178. }
  179. echo '<ul class="core-updates">';
  180. foreach( (array) $updates as $update ) {
  181. echo '<li>';
  182. list_core_update( $update );
  183. echo '</li>';
  184. }
  185. echo '</ul>';
  186. // Don't show the maintenance mode notice when we are only showing a single re-install option.
  187. if ( $updates && ( count( $updates ) > 1 || $updates[0]->response != 'latest' ) ) {
  188. 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>';
  189. } elseif ( ! $updates ) {
  190. list( $normalized_version ) = explode( '-', $wp_version );
  191. echo '<p>' . sprintf( __( '<a href="%s">Learn more about WordPress %s</a>.' ), esc_url( self_admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
  192. }
  193. dismissed_updates();
  194. }
  195. /**
  196. *
  197. * @global string $wp_version
  198. */
  199. function list_plugin_updates() {
  200. global $wp_version;
  201. $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
  202. require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
  203. $plugins = get_plugin_updates();
  204. if ( empty( $plugins ) ) {
  205. echo '<h3>' . __( 'Plugins' ) . '</h3>';
  206. echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
  207. return;
  208. }
  209. $form_action = 'update-core.php?action=do-plugin-upgrade';
  210. $core_updates = get_core_updates();
  211. 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, '=') )
  212. $core_update_version = false;
  213. else
  214. $core_update_version = $core_updates[0]->current;
  215. ?>
  216. <h3><?php _e( 'Plugins' ); ?></h3>
  217. <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>
  218. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
  219. <?php wp_nonce_field('upgrade-core'); ?>
  220. <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
  221. <table class="widefat" id="update-plugins-table">
  222. <thead>
  223. <tr>
  224. <td scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></td>
  225. <th scope="col" class="manage-column"><label for="plugins-select-all"><?php _e('Select All'); ?></label></th>
  226. </tr>
  227. </thead>
  228. <tbody class="plugins">
  229. <?php
  230. foreach ( (array) $plugins as $plugin_file => $plugin_data) {
  231. $info = plugins_api('plugin_information', array('slug' => $plugin_data->update->slug ));
  232. if ( is_wp_error( $info ) ) {
  233. $info = false;
  234. }
  235. // Get plugin compat for running version of WordPress.
  236. if ( isset($info->tested) && version_compare($info->tested, $cur_wp_version, '>=') ) {
  237. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
  238. } elseif ( isset($info->compatibility[$cur_wp_version][$plugin_data->update->new_version]) ) {
  239. $compat = $info->compatibility[$cur_wp_version][$plugin_data->update->new_version];
  240. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $cur_wp_version, $compat[0], $compat[2], $compat[1]);
  241. } else {
  242. $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
  243. }
  244. // Get plugin compat for updated version of WordPress.
  245. if ( $core_update_version ) {
  246. if ( isset($info->compatibility[$core_update_version][$plugin_data->update->new_version]) ) {
  247. $update_compat = $info->compatibility[$core_update_version][$plugin_data->update->new_version];
  248. $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $core_update_version, $update_compat[0], $update_compat[2], $update_compat[1]);
  249. } else {
  250. $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
  251. }
  252. }
  253. // Get the upgrade notice for the new plugin version.
  254. if ( isset($plugin_data->update->upgrade_notice) ) {
  255. $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
  256. } else {
  257. $upgrade_notice = '';
  258. }
  259. $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');
  260. $details_text = sprintf(__('View version %1$s details'), $plugin_data->update->new_version);
  261. $details = sprintf('<a href="%1$s" class="thickbox" title="%2$s">%3$s</a>.', esc_url($details_url), esc_attr($plugin_data->Name), $details_text);
  262. echo "
  263. <tr>
  264. <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
  265. <td><p><strong>{$plugin_data->Name}</strong><br />" . sprintf(__('You have version %1$s installed. Update to %2$s.'), $plugin_data->Version, $plugin_data->update->new_version) . ' ' . $details . $compat . $upgrade_notice . "</p></td>
  266. </tr>";
  267. }
  268. ?>
  269. </tbody>
  270. <tfoot>
  271. <tr>
  272. <td scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></td>
  273. <th scope="col" class="manage-column"><label for="plugins-select-all-2"><?php _e( 'Select All' ); ?></label></th>
  274. </tr>
  275. </tfoot>
  276. </table>
  277. <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
  278. </form>
  279. <?php
  280. }
  281. /**
  282. * @since 2.9.0
  283. */
  284. function list_theme_updates() {
  285. $themes = get_theme_updates();
  286. if ( empty( $themes ) ) {
  287. echo '<h3>' . __( 'Themes' ) . '</h3>';
  288. echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
  289. return;
  290. }
  291. $form_action = 'update-core.php?action=do-theme-upgrade';
  292. ?>
  293. <h3><?php _e( 'Themes' ); ?></h3>
  294. <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>
  295. <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>
  296. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
  297. <?php wp_nonce_field('upgrade-core'); ?>
  298. <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
  299. <table class="widefat" id="update-themes-table">
  300. <thead>
  301. <tr>
  302. <td scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></td>
  303. <th scope="col" class="manage-column"><label for="themes-select-all"><?php _e('Select All'); ?></label></th>
  304. </tr>
  305. </thead>
  306. <tbody class="plugins">
  307. <?php
  308. foreach ( $themes as $stylesheet => $theme ) {
  309. echo "
  310. <tr>
  311. <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr( $stylesheet ) . "' /></th>
  312. <td class='plugin-title'><img src='" . esc_url( $theme->get_screenshot() ) . "' width='85' height='64' style='float:left; padding: 0 5px 5px' /><strong>" . $theme->display('Name') . '</strong> ' . sprintf( __( 'You have version %1$s installed. Update to %2$s.' ), $theme->display('Version'), $theme->update['new_version'] ) . "</td>
  313. </tr>";
  314. }
  315. ?>
  316. </tbody>
  317. <tfoot>
  318. <tr>
  319. <td scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></td>
  320. <th scope="col" class="manage-column"><label for="themes-select-all-2"><?php _e( 'Select All' ); ?></label></th>
  321. </tr>
  322. </tfoot>
  323. </table>
  324. <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
  325. </form>
  326. <?php
  327. }
  328. /**
  329. * @since 3.7.0
  330. */
  331. function list_translation_updates() {
  332. $updates = wp_get_translation_updates();
  333. if ( ! $updates ) {
  334. if ( 'en_US' != get_locale() ) {
  335. echo '<h3>' . __( 'Translations' ) . '</h3>';
  336. echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
  337. }
  338. return;
  339. }
  340. $form_action = 'update-core.php?action=do-translation-upgrade';
  341. ?>
  342. <h3><?php _e( 'Translations' ); ?></h3>
  343. <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
  344. <p><?php _e( 'New translations are available.' ); ?></p>
  345. <?php wp_nonce_field( 'upgrade-translations' ); ?>
  346. <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
  347. </form>
  348. <?php
  349. }
  350. /**
  351. * Upgrade WordPress core display.
  352. *
  353. * @since 2.7.0
  354. *
  355. * @global WP_Filesystem_Base $wp_filesystem Subclass
  356. *
  357. * @param bool $reinstall
  358. */
  359. function do_core_upgrade( $reinstall = false ) {
  360. global $wp_filesystem;
  361. include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  362. if ( $reinstall )
  363. $url = 'update-core.php?action=do-core-reinstall';
  364. else
  365. $url = 'update-core.php?action=do-core-upgrade';
  366. $url = wp_nonce_url($url, 'upgrade-core');
  367. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  368. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  369. $update = find_core_update( $version, $locale );
  370. if ( !$update )
  371. return;
  372. // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
  373. // that it's safe to do so. This only happens when there are no new files to create.
  374. $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
  375. ?>
  376. <div class="wrap">
  377. <h1><?php _e( 'Update WordPress' ); ?></h1>
  378. <?php
  379. if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ) ) ) {
  380. echo '</div>';
  381. return;
  382. }
  383. if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
  384. // Failed to connect, Error and request again
  385. request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
  386. echo '</div>';
  387. return;
  388. }
  389. if ( $wp_filesystem->errors->get_error_code() ) {
  390. foreach ( $wp_filesystem->errors->get_error_messages() as $message )
  391. show_message($message);
  392. echo '</div>';
  393. return;
  394. }
  395. if ( $reinstall )
  396. $update->response = 'reinstall';
  397. add_filter( 'update_feedback', 'show_message' );
  398. $upgrader = new Core_Upgrader();
  399. $result = $upgrader->upgrade( $update, array(
  400. 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership
  401. ) );
  402. if ( is_wp_error($result) ) {
  403. show_message($result);
  404. if ('up_to_date' != $result->get_error_code() )
  405. show_message( __('Installation Failed') );
  406. echo '</div>';
  407. return;
  408. }
  409. show_message( __('WordPress updated successfully') );
  410. 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>' );
  411. 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>' );
  412. ?>
  413. </div>
  414. <script type="text/javascript">
  415. window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
  416. </script>
  417. <?php
  418. }
  419. /**
  420. * @since 2.7.0
  421. */
  422. function do_dismiss_core_update() {
  423. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  424. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  425. $update = find_core_update( $version, $locale );
  426. if ( !$update )
  427. return;
  428. dismiss_core_update( $update );
  429. wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
  430. exit;
  431. }
  432. /**
  433. * @since 2.7.0
  434. */
  435. function do_undismiss_core_update() {
  436. $version = isset( $_POST['version'] )? $_POST['version'] : false;
  437. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
  438. $update = find_core_update( $version, $locale );
  439. if ( !$update )
  440. return;
  441. undismiss_core_update( $version, $locale );
  442. wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
  443. exit;
  444. }
  445. $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
  446. $upgrade_error = false;
  447. if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
  448. && ! isset( $_POST['checked'] ) ) {
  449. $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
  450. $action = 'upgrade-core';
  451. }
  452. $title = __('WordPress Updates');
  453. $parent_file = 'index.php';
  454. $updates_overview = '<p>' . __( 'On this screen, you can update to the latest version of WordPress, as well as update your themes and plugins from the WordPress.org repositories.' ) . '</p>';
  455. $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>';
  456. get_current_screen()->add_help_tab( array(
  457. 'id' => 'overview',
  458. 'title' => __( 'Overview' ),
  459. 'content' => $updates_overview
  460. ) );
  461. $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>';
  462. $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>';
  463. if ( 'en_US' != get_locale() ) {
  464. $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>';
  465. }
  466. get_current_screen()->add_help_tab( array(
  467. 'id' => 'how-to-update',
  468. 'title' => __( 'How to Update' ),
  469. 'content' => $updates_howto
  470. ) );
  471. get_current_screen()->set_help_sidebar(
  472. '<p><strong>' . __('For more information:') . '</strong></p>' .
  473. '<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_Updates_Screen" target="_blank">Documentation on Updating WordPress</a>' ) . '</p>' .
  474. '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
  475. );
  476. if ( 'upgrade-core' == $action ) {
  477. // Force a update check when requested
  478. $force_check = ! empty( $_GET['force-check'] );
  479. wp_version_check( array(), $force_check );
  480. require_once(ABSPATH . 'wp-admin/admin-header.php');
  481. ?>
  482. <div class="wrap">
  483. <h1><?php _e( 'WordPress Updates' ); ?></h1>
  484. <?php
  485. if ( $upgrade_error ) {
  486. echo '<div class="error"><p>';
  487. if ( $upgrade_error == 'themes' )
  488. _e('Please select one or more themes to update.');
  489. else
  490. _e('Please select one or more plugins to update.');
  491. echo '</p></div>';
  492. }
  493. echo '<p>';
  494. /* translators: %1 date, %2 time. */
  495. printf( __('Last checked on %1$s at %2$s.'), date_i18n( get_option( 'date_format' ) ), date_i18n( get_option( 'time_format' ) ) );
  496. echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php?force-check=1') ) . '">' . __( 'Check Again' ) . '</a>';
  497. echo '</p>';
  498. if ( $core = current_user_can( 'update_core' ) )
  499. core_upgrade_preamble();
  500. if ( $plugins = current_user_can( 'update_plugins' ) )
  501. list_plugin_updates();
  502. if ( $themes = current_user_can( 'update_themes' ) )
  503. list_theme_updates();
  504. if ( $core || $plugins || $themes )
  505. list_translation_updates();
  506. unset( $core, $plugins, $themes );
  507. /**
  508. * Fires after the core, plugin, and theme update tables.
  509. *
  510. * @since 2.9.0
  511. */
  512. do_action( 'core_upgrade_preamble' );
  513. echo '</div>';
  514. include(ABSPATH . 'wp-admin/admin-footer.php');
  515. } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
  516. if ( ! current_user_can( 'update_core' ) )
  517. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  518. check_admin_referer('upgrade-core');
  519. // Do the (un)dismiss actions before headers, so that they can redirect.
  520. if ( isset( $_POST['dismiss'] ) )
  521. do_dismiss_core_update();
  522. elseif ( isset( $_POST['undismiss'] ) )
  523. do_undismiss_core_update();
  524. require_once(ABSPATH . 'wp-admin/admin-header.php');
  525. if ( 'do-core-reinstall' == $action )
  526. $reinstall = true;
  527. else
  528. $reinstall = false;
  529. if ( isset( $_POST['upgrade'] ) )
  530. do_core_upgrade($reinstall);
  531. include(ABSPATH . 'wp-admin/admin-footer.php');
  532. } elseif ( 'do-plugin-upgrade' == $action ) {
  533. if ( ! current_user_can( 'update_plugins' ) )
  534. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  535. check_admin_referer('upgrade-core');
  536. if ( isset( $_GET['plugins'] ) ) {
  537. $plugins = explode( ',', $_GET['plugins'] );
  538. } elseif ( isset( $_POST['checked'] ) ) {
  539. $plugins = (array) $_POST['checked'];
  540. } else {
  541. wp_redirect( admin_url('update-core.php') );
  542. exit;
  543. }
  544. $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
  545. $url = wp_nonce_url($url, 'bulk-update-plugins');
  546. $title = __('Update Plugins');
  547. require_once(ABSPATH . 'wp-admin/admin-header.php');
  548. echo '<div class="wrap">';
  549. echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
  550. echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0"></iframe>';
  551. echo '</div>';
  552. include(ABSPATH . 'wp-admin/admin-footer.php');
  553. } elseif ( 'do-theme-upgrade' == $action ) {
  554. if ( ! current_user_can( 'update_themes' ) )
  555. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  556. check_admin_referer('upgrade-core');
  557. if ( isset( $_GET['themes'] ) ) {
  558. $themes = explode( ',', $_GET['themes'] );
  559. } elseif ( isset( $_POST['checked'] ) ) {
  560. $themes = (array) $_POST['checked'];
  561. } else {
  562. wp_redirect( admin_url('update-core.php') );
  563. exit;
  564. }
  565. $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
  566. $url = wp_nonce_url($url, 'bulk-update-themes');
  567. $title = __('Update Themes');
  568. require_once(ABSPATH . 'wp-admin/admin-header.php');
  569. ?>
  570. <div class="wrap">
  571. <h1><?php _e( 'Update Themes' ); ?></h1>
  572. <iframe src="<?php echo $url ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0"></iframe>
  573. </div>
  574. <?php
  575. include(ABSPATH . 'wp-admin/admin-footer.php');
  576. } elseif ( 'do-translation-upgrade' == $action ) {
  577. if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
  578. wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
  579. check_admin_referer( 'upgrade-translations' );
  580. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  581. include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  582. $url = 'update-core.php?action=do-translation-upgrade';
  583. $nonce = 'upgrade-translations';
  584. $title = __( 'Update Translations' );
  585. $context = WP_LANG_DIR;
  586. $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
  587. $result = $upgrader->bulk_upgrade();
  588. require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  589. } else {
  590. /**
  591. * Fires for each custom update action on the WordPress Updates screen.
  592. *
  593. * The dynamic portion of the hook name, `$action`, refers to the
  594. * passed update action. The hook fires in lieu of all available
  595. * default update actions.
  596. *
  597. * @since 3.2.0
  598. */
  599. do_action( "update-core-custom_{$action}" );
  600. }