wp/wp-admin/network/upgrade.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Multisite upgrade administration panel.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Multisite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/** Load WordPress Administration Bootstrap */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
require_once( dirname( __FILE__ ) . '/admin.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
	wp_die( __( 'Multisite support is not enabled.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
require_once( ABSPATH . WPINC . '/http.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
$title = __( 'Upgrade Network' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
$parent_file = 'upgrade.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	'id'      => 'overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	'title'   => __('Overview'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	'content' =>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		'<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>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		'<p>' . __('If a version update to core has not happened, clicking this button won&#8217;t affect anything.') . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		'<p>' . __('If this process fails for any reason, users logging in to their sites will force the same update.') . '</p>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
get_current_screen()->set_help_sidebar(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	'<p><strong>' . __('For more information:') . '</strong></p>' .
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Updates_Screen" target="_blank">Documentation on Upgrade Network</a>') . '</p>' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
require_once( ABSPATH . 'wp-admin/admin-header.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
if ( ! current_user_can( 'manage_network' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
	wp_die( __( 'You do not have permission to access this page.' ), 403 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
echo '<div class="wrap">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
echo '<h2>' . __( 'Upgrade Network' ) . '</h2>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
$action = isset($_GET['action']) ? $_GET['action'] : 'show';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
switch ( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	case "upgrade":
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		$n = ( isset($_GET['n']) ) ? intval($_GET['n']) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		if ( $n < 5 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
			global $wp_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			update_site_option( 'wpmu_upgrade_site', $wp_db_version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
		$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		if ( empty( $blogs ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
			echo '<p>' . __( 'All done!' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		echo "<ul>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
		foreach ( (array) $blogs as $details ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
			switch_to_blog( $details['blog_id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
			$siteurl = site_url();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
			$upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
			restore_current_blog();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
			echo "<li>$siteurl</li>";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
			$response = wp_remote_get( $upgrade_url, array( 'timeout' => 120, 'httpversion' => '1.1' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
			if ( is_wp_error( $response ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
				wp_die( sprintf(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
					/* translators: 1: site url, 2: server error message */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
					__( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: %2$s' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
					$siteurl,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
					'<em>' . $response->get_error_message() . '</em>'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
				) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
			 * Fires after the Multisite DB upgrade for each site is complete.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
			 * @since MU
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
			 * @param array|WP_Error $response The upgrade response array or WP_Error on failure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
			do_action( 'after_mu_upgrade', $response );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
			 * Fires after each site has been upgraded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
			 * @since MU
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
			 * @param int $blog_id The id of the blog.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
			do_action( 'wpmu_upgrade_site', $details[ 'blog_id' ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		echo "</ul>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
		<script type="text/javascript">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		<!--
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
		function nextpage() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
			location.href = "upgrade.php?action=upgrade&n=<?php echo ($n + 5) ?>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
		setTimeout( "nextpage()", 250 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		//-->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
		</script><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	case 'show':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
		if ( get_site_option( 'wpmu_upgrade_site' ) != $GLOBALS['wp_db_version'] ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		<h3><?php _e( 'Database Upgrade Required' ); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   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>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		<p><?php _e( 'The database upgrade process may take a little while, so please be patient.' ); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		<p><a class="button" href="upgrade.php?action=upgrade"><?php _e( 'Upgrade Network' ); ?></a></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
		 * Fires before the footer on the network upgrade screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
		 * @since MU
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		do_action( 'wpmu_upgrade_page' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>