upgrade.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Multisite upgrade administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.0.0
  8. */
  9. /** Load WordPress Administration Bootstrap */
  10. require_once( dirname( __FILE__ ) . '/admin.php' );
  11. require_once( ABSPATH . WPINC . '/http.php' );
  12. $title = __( 'Upgrade Network' );
  13. $parent_file = 'upgrade.php';
  14. get_current_screen()->add_help_tab(
  15. array(
  16. 'id' => 'overview',
  17. 'title' => __( 'Overview' ),
  18. 'content' =>
  19. '<p>' . __( 'Only use this screen once you have updated to a new version of WordPress through Updates/Available Updates (via the Network Administration navigation menu or the Toolbar). Clicking the Upgrade Network button will step through each site in the network, five at a time, and make sure any database updates are applied.' ) . '</p>' .
  20. '<p>' . __( 'If a version update to core has not happened, clicking this button won&#8217;t affect anything.' ) . '</p>' .
  21. '<p>' . __( 'If this process fails for any reason, users logging in to their sites will force the same update.' ) . '</p>',
  22. )
  23. );
  24. get_current_screen()->set_help_sidebar(
  25. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  26. '<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-updates-screen/">Documentation on Upgrade Network</a>' ) . '</p>' .
  27. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  28. );
  29. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  30. if ( ! current_user_can( 'upgrade_network' ) ) {
  31. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  32. }
  33. echo '<div class="wrap">';
  34. echo '<h1>' . __( 'Upgrade Network' ) . '</h1>';
  35. $action = isset( $_GET['action'] ) ? $_GET['action'] : 'show';
  36. switch ( $action ) {
  37. case 'upgrade':
  38. $n = ( isset( $_GET['n'] ) ) ? intval( $_GET['n'] ) : 0;
  39. if ( $n < 5 ) {
  40. /**
  41. * @global int $wp_db_version WordPress database version.
  42. */
  43. global $wp_db_version;
  44. update_site_option( 'wpmu_upgrade_site', $wp_db_version );
  45. }
  46. $site_ids = get_sites(
  47. array(
  48. 'spam' => 0,
  49. 'deleted' => 0,
  50. 'archived' => 0,
  51. 'network_id' => get_current_network_id(),
  52. 'number' => 5,
  53. 'offset' => $n,
  54. 'fields' => 'ids',
  55. 'order' => 'DESC',
  56. 'orderby' => 'id',
  57. 'update_site_meta_cache' => false,
  58. )
  59. );
  60. if ( empty( $site_ids ) ) {
  61. echo '<p>' . __( 'All done!' ) . '</p>';
  62. break;
  63. }
  64. echo '<ul>';
  65. foreach ( (array) $site_ids as $site_id ) {
  66. switch_to_blog( $site_id );
  67. $siteurl = site_url();
  68. $upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' );
  69. restore_current_blog();
  70. echo "<li>$siteurl</li>";
  71. $response = wp_remote_get(
  72. $upgrade_url,
  73. array(
  74. 'timeout' => 120,
  75. 'httpversion' => '1.1',
  76. 'sslverify' => false,
  77. )
  78. );
  79. if ( is_wp_error( $response ) ) {
  80. wp_die(
  81. sprintf(
  82. /* translators: 1: Site URL, 2: Server error message. */
  83. __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: %2$s' ),
  84. $siteurl,
  85. '<em>' . $response->get_error_message() . '</em>'
  86. )
  87. );
  88. }
  89. /**
  90. * Fires after the Multisite DB upgrade for each site is complete.
  91. *
  92. * @since MU (3.0.0)
  93. *
  94. * @param array|WP_Error $response The upgrade response array or WP_Error on failure.
  95. */
  96. do_action( 'after_mu_upgrade', $response );
  97. /**
  98. * Fires after each site has been upgraded.
  99. *
  100. * @since MU (3.0.0)
  101. *
  102. * @param int $site_id The Site ID.
  103. */
  104. do_action( 'wpmu_upgrade_site', $site_id );
  105. }
  106. echo '</ul>';
  107. ?><p><?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this link:' ); ?> <a class="button" href="upgrade.php?action=upgrade&amp;n=<?php echo ( $n + 5 ); ?>"><?php _e( 'Next Sites' ); ?></a></p>
  108. <script type="text/javascript">
  109. <!--
  110. function nextpage() {
  111. location.href = "upgrade.php?action=upgrade&n=<?php echo ( $n + 5 ); ?>";
  112. }
  113. setTimeout( "nextpage()", 250 );
  114. //-->
  115. </script>
  116. <?php
  117. break;
  118. case 'show':
  119. default:
  120. if ( get_site_option( 'wpmu_upgrade_site' ) != $GLOBALS['wp_db_version'] ) :
  121. ?>
  122. <h2><?php _e( 'Database Update Required' ); ?></h2>
  123. <p><?php _e( 'WordPress has been updated! Before we send you on your way, we need to individually upgrade the sites in your network.' ); ?></p>
  124. <?php endif; ?>
  125. <p><?php _e( 'The database update process may take a little while, so please be patient.' ); ?></p>
  126. <p><a class="button button-primary" href="upgrade.php?action=upgrade"><?php _e( 'Upgrade Network' ); ?></a></p>
  127. <?php
  128. /**
  129. * Fires before the footer on the network upgrade screen.
  130. *
  131. * @since MU (3.0.0)
  132. */
  133. do_action( 'wpmu_upgrade_page' );
  134. break;
  135. }
  136. ?>
  137. </div>
  138. <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>