author | ymh <ymh.work@gmail.com> |
Wed, 16 Oct 2019 11:23:38 +0200 | |
changeset 14 | 00ac8f60d73f |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Edit Site Info Administration Screen |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Multisite |
|
7 |
* @since 3.1.0 |
|
8 |
*/ |
|
9 |
||
10 |
/** Load WordPress Administration Bootstrap */ |
|
11 |
require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
12 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
if ( ! current_user_can( 'manage_sites' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
wp_die( __( 'Sorry, you are not allowed to edit this site.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
} |
0 | 16 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
get_current_screen()->add_help_tab( get_site_screen_help_tab_args() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() ); |
0 | 19 |
|
20 |
$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; |
|
21 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
if ( ! $id ) { |
9 | 23 |
wp_die( __( 'Invalid site ID.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
} |
0 | 25 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
$details = get_site( $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
if ( ! $details ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
wp_die( __( 'The requested site does not exist.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
} |
0 | 30 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
if ( ! can_edit_network( $details->site_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
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
|
33 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
$parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME ); |
9 | 36 |
$is_main_site = is_main_site( $id ); |
0 | 37 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) { |
0 | 39 |
check_admin_referer( 'edit-site' ); |
40 |
||
41 |
switch_to_blog( $id ); |
|
42 |
||
5 | 43 |
// Rewrite rules can't be flushed during switch to blog. |
0 | 44 |
delete_option( 'rewrite_rules' ); |
45 |
||
9 | 46 |
$blog_data = wp_unslash( $_POST['blog'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
$blog_data['scheme'] = $parsed_scheme; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
if ( $is_main_site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
// On the network's main site, don't allow the domain or path to change. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
$blog_data['domain'] = $details->domain; |
9 | 52 |
$blog_data['path'] = $details->path; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
// For any other site, the scheme, domain, and path can all be changed. We first |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
// need to ensure a scheme has been provided, otherwise fallback to the existing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
$new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
if ( ! $new_url_scheme ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
$blog_data['url'] = esc_url( $parsed_scheme . '://' . $blog_data['url'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
$update_parsed_url = parse_url( $blog_data['url'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
// If a path is not provided, use the default of `/`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
if ( ! isset( $update_parsed_url['path'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
$update_parsed_url['path'] = '/'; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
$blog_data['scheme'] = $update_parsed_url['scheme']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
$blog_data['domain'] = $update_parsed_url['host']; |
9 | 70 |
$blog_data['path'] = $update_parsed_url['path']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
|
9 | 73 |
$existing_details = get_site( $id ); |
0 | 74 |
$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' ); |
75 |
foreach ( $blog_data_checkboxes as $c ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) { |
0 | 77 |
$blog_data[ $c ] = $existing_details->$c; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
} else { |
0 | 79 |
$blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0; |
5 | 80 |
} |
81 |
} |
|
82 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
update_blog_details( $id, $blog_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
// Maybe update home and siteurl options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
$new_details = get_site( $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
|
9 | 88 |
$old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
$old_home_parsed = parse_url( $old_home_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
$new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
update_option( 'home', $new_home_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
|
9 | 96 |
$old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
$old_site_parsed = parse_url( $old_site_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
$new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
update_option( 'siteurl', $new_site_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
|
0 | 104 |
restore_current_blog(); |
9 | 105 |
wp_redirect( |
106 |
add_query_arg( |
|
107 |
array( |
|
108 |
'update' => 'updated', |
|
109 |
'id' => $id, |
|
110 |
), |
|
111 |
'site-info.php' |
|
112 |
) |
|
113 |
); |
|
0 | 114 |
exit; |
115 |
} |
|
116 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
if ( isset( $_GET['update'] ) ) { |
0 | 118 |
$messages = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
if ( 'updated' == $_GET['update'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
$messages[] = __( 'Site info updated.' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
} |
0 | 122 |
} |
123 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
/* translators: %s: site name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
$title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) ); |
0 | 126 |
|
9 | 127 |
$parent_file = 'sites.php'; |
0 | 128 |
$submenu_file = 'sites.php'; |
129 |
||
130 |
require( ABSPATH . 'wp-admin/admin-header.php' ); |
|
131 |
||
132 |
?> |
|
133 |
||
134 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
<h1 id="edit-site"><?php echo $title; ?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
<p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p> |
0 | 137 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
|
9 | 139 |
network_edit_site_nav( |
140 |
array( |
|
141 |
'blog_id' => $id, |
|
142 |
'selected' => 'site-info', |
|
143 |
) |
|
144 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
if ( ! empty( $messages ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
foreach ( $messages as $msg ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
} |
0 | 150 |
} |
151 |
?> |
|
152 |
<form method="post" action="site-info.php?action=update-site"> |
|
153 |
<?php wp_nonce_field( 'edit-site' ); ?> |
|
9 | 154 |
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> |
155 |
<table class="form-table" role="presentation"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
// The main site of the network should not be updated on this page. |
9 | 158 |
if ( $is_main_site ) : |
159 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
<tr class="form-field"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
<th scope="row"><?php _e( 'Site Address (URL)' ); ?></th> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
<td><?php echo esc_url( $parsed_scheme . '://' . $details->domain . $details->path ); ?></td> |
0 | 163 |
</tr> |
9 | 164 |
<?php |
165 |
// For any other site, the scheme, domain, and path can all be changed. |
|
166 |
else : |
|
167 |
?> |
|
0 | 168 |
<tr class="form-field form-required"> |
9 | 169 |
<th scope="row"><label for="url"><?php _e( 'Site Address (URL)' ); ?></label></th> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
<td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td> |
0 | 171 |
</tr> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
|
0 | 174 |
<tr class="form-field"> |
9 | 175 |
<th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ); ?></label></th> |
176 |
<td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ); ?>" /></td> |
|
0 | 177 |
</tr> |
178 |
<tr class="form-field"> |
|
5 | 179 |
<th scope="row"><label for="blog_last_updated"><?php _e( 'Last Updated' ); ?></label></th> |
9 | 180 |
<td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ); ?>" /></td> |
0 | 181 |
</tr> |
182 |
<?php |
|
183 |
$attribute_fields = array( 'public' => __( 'Public' ) ); |
|
184 |
if ( ! $is_main_site ) { |
|
185 |
$attribute_fields['archived'] = __( 'Archived' ); |
|
186 |
$attribute_fields['spam'] = _x( 'Spam', 'site' ); |
|
187 |
$attribute_fields['deleted'] = __( 'Deleted' ); |
|
188 |
} |
|
189 |
$attribute_fields['mature'] = __( 'Mature' ); |
|
190 |
?> |
|
191 |
<tr> |
|
192 |
<th scope="row"><?php _e( 'Attributes' ); ?></th> |
|
193 |
<td> |
|
5 | 194 |
<fieldset> |
9 | 195 |
<legend class="screen-reader-text"><?php _e( 'Set site attributes' ); ?></legend> |
0 | 196 |
<?php foreach ( $attribute_fields as $field_key => $field_label ) : ?> |
9 | 197 |
<label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( $details->$field_key, array( 0, 1 ) ) ); ?> /> |
0 | 198 |
<?php echo $field_label; ?></label><br/> |
199 |
<?php endforeach; ?> |
|
5 | 200 |
<fieldset> |
0 | 201 |
</td> |
202 |
</tr> |
|
203 |
</table> |
|
204 |
<?php submit_button(); ?> |
|
205 |
</form> |
|
206 |
||
207 |
</div> |
|
208 |
<?php |
|
209 |
require( ABSPATH . 'wp-admin/admin-footer.php' ); |