do_core_upgrade

Upgrade WordPress core display.

Description

do_core_upgrade( (bool) $reinstall = false ); 

Parameters (1)

0. $reinstall — Optional. (bool) => false
The reinstall.

Usage

  1. if ( !function_exists( 'do_core_upgrade' ) ) { 
  2. require_once ABSPATH . '/wp-admin/update-core.php'; 
  3.  
  4. // The reinstall. 
  5. $reinstall = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = do_core_upgrade($reinstall); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/update-core.php  
  1. function do_core_upgrade( $reinstall = false ) { 
  2. global $wp_filesystem; 
  3.  
  4. include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); 
  5.  
  6. if ( $reinstall ) 
  7. $url = 'update-core.php?action=do-core-reinstall'; 
  8. else 
  9. $url = 'update-core.php?action=do-core-upgrade'; 
  10. $url = wp_nonce_url($url, 'upgrade-core'); 
  11.  
  12. $version = isset( $_POST['version'] )? $_POST['version'] : false; 
  13. $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US'; 
  14. $update = find_core_update( $version, $locale ); 
  15. if ( !$update ) 
  16. return; 
  17.  
  18. // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies 
  19. // that it's safe to do so. This only happens when there are no new files to create. 
  20. $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files; 
  21.  
  22. ?> 
  23. <div class="wrap"> 
  24. <h1><?php _e( 'Update WordPress' ); ?></h1> 
  25. <?php 
  26.  
  27. if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ) ) ) { 
  28. echo '</div>'; 
  29. return; 
  30.  
  31. if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) { 
  32. // Failed to connect, Error and request again 
  33. request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ); 
  34. echo '</div>'; 
  35. return; 
  36.  
  37. if ( $wp_filesystem->errors->get_error_code() ) { 
  38. foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 
  39. show_message($message); 
  40. echo '</div>'; 
  41. return; 
  42.  
  43. if ( $reinstall ) 
  44. $update->response = 'reinstall'; 
  45.  
  46.  
  47. $upgrader = new Core_Upgrader(); 
  48. $result = $upgrader->upgrade( $update, array( 
  49. 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership 
  50. ) ); 
  51.  
  52. if ( is_wp_error($result) ) { 
  53. show_message($result); 
  54. if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() ) 
  55. show_message( __('Installation Failed') ); 
  56. echo '</div>'; 
  57. return; 
  58.  
  59. show_message( __('WordPress updated successfully') ); 
  60. 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>' ); 
  61. 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>' ); 
  62. ?> 
  63. </div> 
  64. <script type="text/javascript"> 
  65. window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>'; 
  66. </script> 
  67. <?php