author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
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 |
||
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>' . |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Updates_Screen">Documentation on Upgrade Network</a>') . '</p>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' |
0 | 31 |
); |
32 |
||
33 |
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
34 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
if ( ! current_user_can( 'upgrade_network' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
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
|
37 |
} |
0 | 38 |
|
39 |
echo '<div class="wrap">'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
echo '<h1>' . __( 'Upgrade Network' ) . '</h1>'; |
0 | 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 ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
* @global string $wp_db_version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
*/ |
0 | 52 |
global $wp_db_version; |
53 |
update_site_option( 'wpmu_upgrade_site', $wp_db_version ); |
|
54 |
} |
|
55 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
$site_ids = get_sites( array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
'spam' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
'deleted' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
'archived' => 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
'network_id' => get_current_network_id(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
'number' => 5, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
'offset' => $n, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
'fields' => 'ids', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
'order' => 'DESC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
'orderby' => 'id', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
if ( empty( $site_ids ) ) { |
0 | 68 |
echo '<p>' . __( 'All done!' ) . '</p>'; |
69 |
break; |
|
70 |
} |
|
71 |
echo "<ul>"; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
foreach ( (array) $site_ids as $site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
switch_to_blog( $site_id ); |
0 | 74 |
$siteurl = site_url(); |
75 |
$upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' ); |
|
76 |
restore_current_blog(); |
|
5 | 77 |
|
0 | 78 |
echo "<li>$siteurl</li>"; |
5 | 79 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
$response = wp_remote_get( $upgrade_url, array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
'timeout' => 120, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
'httpversion' => '1.1', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
'sslverify' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
) ); |
5 | 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 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* @since MU (3.0.0) |
5 | 98 |
* |
99 |
* @param array|WP_Error $response The upgrade response array or WP_Error on failure. |
|
100 |
*/ |
|
0 | 101 |
do_action( 'after_mu_upgrade', $response ); |
5 | 102 |
/** |
103 |
* Fires after each site has been upgraded. |
|
104 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
* @since MU (3.0.0) |
5 | 106 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
* @param int $site_id The Site ID. |
5 | 108 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
do_action( 'wpmu_upgrade_site', $site_id ); |
0 | 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> |
|
5 | 113 |
<script type="text/javascript"> |
0 | 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 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
<h2><?php _e( 'Database Update Required' ); ?></h2> |
0 | 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 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
<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
|
131 |
<p><a class="button button-primary" href="upgrade.php?action=upgrade"><?php _e( 'Upgrade Network' ); ?></a></p> |
0 | 132 |
<?php |
5 | 133 |
/** |
134 |
* Fires before the footer on the network upgrade screen. |
|
135 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* @since MU (3.0.0) |
5 | 137 |
*/ |
0 | 138 |
do_action( 'wpmu_upgrade_page' ); |
139 |
break; |
|
140 |
} |
|
141 |
?> |
|
142 |
</div> |
|
143 |
||
144 |
<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?> |