upgrade.php 4.8 KB

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