upgrade.php 4.5 KB

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