author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 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 |
||
9 | 15 |
$title = __( 'Upgrade Network' ); |
0 | 16 |
$parent_file = 'upgrade.php'; |
17 |
||
9 | 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’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 |
); |
|
0 | 28 |
|
29 |
get_current_screen()->set_help_sidebar( |
|
9 | 30 |
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
31 |
'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Updates_Screen">Documentation on Upgrade Network</a>' ) . '</p>' . |
|
32 |
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
|
0 | 33 |
); |
34 |
||
35 |
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
36 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
if ( ! current_user_can( 'upgrade_network' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
} |
0 | 40 |
|
41 |
echo '<div class="wrap">'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
echo '<h1>' . __( 'Upgrade Network' ) . '</h1>'; |
0 | 43 |
|
9 | 44 |
$action = isset( $_GET['action'] ) ? $_GET['action'] : 'show'; |
0 | 45 |
|
46 |
switch ( $action ) { |
|
9 | 47 |
case 'upgrade': |
48 |
$n = ( isset( $_GET['n'] ) ) ? intval( $_GET['n'] ) : 0; |
|
0 | 49 |
|
50 |
if ( $n < 5 ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
* @global string $wp_db_version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
*/ |
0 | 54 |
global $wp_db_version; |
55 |
update_site_option( 'wpmu_upgrade_site', $wp_db_version ); |
|
56 |
} |
|
57 |
||
9 | 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 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
if ( empty( $site_ids ) ) { |
0 | 73 |
echo '<p>' . __( 'All done!' ) . '</p>'; |
74 |
break; |
|
75 |
} |
|
9 | 76 |
echo '<ul>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
foreach ( (array) $site_ids as $site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
switch_to_blog( $site_id ); |
9 | 79 |
$siteurl = site_url(); |
0 | 80 |
$upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' ); |
81 |
restore_current_blog(); |
|
5 | 82 |
|
0 | 83 |
echo "<li>$siteurl</li>"; |
5 | 84 |
|
9 | 85 |
$response = wp_remote_get( |
86 |
$upgrade_url, |
|
87 |
array( |
|
88 |
'timeout' => 120, |
|
89 |
'httpversion' => '1.1', |
|
90 |
'sslverify' => false, |
|
91 |
) |
|
92 |
); |
|
5 | 93 |
if ( is_wp_error( $response ) ) { |
9 | 94 |
wp_die( |
95 |
sprintf( |
|
96 |
/* translators: 1: site url, 2: server error message */ |
|
97 |
__( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: %2$s' ), |
|
98 |
$siteurl, |
|
99 |
'<em>' . $response->get_error_message() . '</em>' |
|
100 |
) |
|
101 |
); |
|
5 | 102 |
} |
103 |
||
104 |
/** |
|
105 |
* Fires after the Multisite DB upgrade for each site is complete. |
|
106 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
* @since MU (3.0.0) |
5 | 108 |
* |
109 |
* @param array|WP_Error $response The upgrade response array or WP_Error on failure. |
|
110 |
*/ |
|
0 | 111 |
do_action( 'after_mu_upgrade', $response ); |
5 | 112 |
/** |
113 |
* Fires after each site has been upgraded. |
|
114 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
* @since MU (3.0.0) |
5 | 116 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
* @param int $site_id The Site ID. |
5 | 118 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
do_action( 'wpmu_upgrade_site', $site_id ); |
0 | 120 |
} |
9 | 121 |
echo '</ul>'; |
122 |
?><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> |
|
5 | 123 |
<script type="text/javascript"> |
0 | 124 |
<!-- |
125 |
function nextpage() { |
|
9 | 126 |
location.href = "upgrade.php?action=upgrade&n=<?php echo ( $n + 5 ); ?>"; |
0 | 127 |
} |
128 |
setTimeout( "nextpage()", 250 ); |
|
129 |
//--> |
|
9 | 130 |
</script> |
131 |
<?php |
|
132 |
break; |
|
0 | 133 |
case 'show': |
134 |
default: |
|
135 |
if ( get_site_option( 'wpmu_upgrade_site' ) != $GLOBALS['wp_db_version'] ) : |
|
9 | 136 |
?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
<h2><?php _e( 'Database Update Required' ); ?></h2> |
0 | 138 |
<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> |
139 |
<?php endif; ?> |
|
140 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
<p><?php _e( 'The database update process may take a little while, so please be patient.' ); ?></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
<p><a class="button button-primary" href="upgrade.php?action=upgrade"><?php _e( 'Upgrade Network' ); ?></a></p> |
0 | 143 |
<?php |
5 | 144 |
/** |
145 |
* Fires before the footer on the network upgrade screen. |
|
146 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
* @since MU (3.0.0) |
5 | 148 |
*/ |
0 | 149 |
do_action( 'wpmu_upgrade_page' ); |
9 | 150 |
break; |
0 | 151 |
} |
152 |
?> |
|
153 |
</div> |
|
154 |
||
155 |
<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?> |