/wp-admin/update-core.php

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