balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

upgrade.php (4944B)


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