home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-admin / network / upgrade.php < prev    next >
Encoding:
PHP Script  |  2017-08-01  |  4.6 KB  |  145 lines

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