upgrade.php 4.6 KB

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