author | ymh <ymh.work@gmail.com> |
Tue, 15 Oct 2019 15:48:13 +0200 | |
changeset 13 | d255fe9cd479 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Edit Site Settings 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 |
||
9 | 13 |
if ( ! current_user_can( 'manage_sites' ) ) { |
7
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.' ) ); |
9 | 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 |
||
9 | 22 |
if ( ! $id ) { |
23 |
wp_die( __( 'Invalid site ID.' ) ); |
|
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 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
|
9 | 31 |
if ( ! can_edit_network( $details->site_id ) ) { |
7
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 ); |
9 | 33 |
} |
0 | 34 |
|
35 |
$is_main_site = is_main_site( $id ); |
|
36 |
||
9 | 37 |
if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] && is_array( $_POST['option'] ) ) { |
0 | 38 |
check_admin_referer( 'edit-site' ); |
39 |
||
40 |
switch_to_blog( $id ); |
|
41 |
||
42 |
$skip_options = array( 'allowedthemes' ); // Don't update these options since they are handled elsewhere in the form. |
|
43 |
foreach ( (array) $_POST['option'] as $key => $val ) { |
|
44 |
$key = wp_unslash( $key ); |
|
45 |
$val = wp_unslash( $val ); |
|
9 | 46 |
if ( $key === 0 || is_array( $val ) || in_array( $key, $skip_options ) ) { |
0 | 47 |
continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options |
9 | 48 |
} |
0 | 49 |
update_option( $key, $val ); |
50 |
} |
|
51 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
* Fires after the site options are updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* @since 4.4.0 Added `$id` parameter. |
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 |
* @param int $id The ID of the site being updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
do_action( 'wpmu_update_blog_options', $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
|
0 | 62 |
restore_current_blog(); |
9 | 63 |
wp_redirect( |
64 |
add_query_arg( |
|
65 |
array( |
|
66 |
'update' => 'updated', |
|
67 |
'id' => $id, |
|
68 |
), |
|
69 |
'site-settings.php' |
|
70 |
) |
|
71 |
); |
|
0 | 72 |
exit; |
73 |
} |
|
74 |
||
9 | 75 |
if ( isset( $_GET['update'] ) ) { |
0 | 76 |
$messages = array(); |
9 | 77 |
if ( 'updated' == $_GET['update'] ) { |
78 |
$messages[] = __( 'Site options updated.' ); |
|
79 |
} |
|
0 | 80 |
} |
81 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
/* translators: %s: site name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
$title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) ); |
0 | 84 |
|
9 | 85 |
$parent_file = 'sites.php'; |
0 | 86 |
$submenu_file = 'sites.php'; |
87 |
||
88 |
require( ABSPATH . 'wp-admin/admin-header.php' ); |
|
89 |
||
90 |
?> |
|
91 |
||
92 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
<h1 id="edit-site"><?php echo $title; ?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
<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> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
|
0 | 96 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
|
9 | 98 |
network_edit_site_nav( |
99 |
array( |
|
100 |
'blog_id' => $id, |
|
101 |
'selected' => 'site-settings', |
|
102 |
) |
|
103 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
|
0 | 105 |
if ( ! empty( $messages ) ) { |
9 | 106 |
foreach ( $messages as $msg ) { |
5 | 107 |
echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>'; |
9 | 108 |
} |
109 |
} |
|
110 |
?> |
|
0 | 111 |
<form method="post" action="site-settings.php?action=update-site"> |
112 |
<?php wp_nonce_field( 'edit-site' ); ?> |
|
9 | 113 |
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" /> |
114 |
<table class="form-table" role="presentation"> |
|
0 | 115 |
<?php |
116 |
$blog_prefix = $wpdb->get_blog_prefix( $id ); |
|
9 | 117 |
$sql = "SELECT * FROM {$blog_prefix}options |
5 | 118 |
WHERE option_name NOT LIKE %s |
119 |
AND option_name NOT LIKE %s"; |
|
9 | 120 |
$query = $wpdb->prepare( |
121 |
$sql, |
|
5 | 122 |
$wpdb->esc_like( '_' ) . '%', |
123 |
'%' . $wpdb->esc_like( 'user_roles' ) |
|
124 |
); |
|
9 | 125 |
$options = $wpdb->get_results( $query ); |
0 | 126 |
foreach ( $options as $option ) { |
9 | 127 |
if ( $option->option_name == 'default_role' ) { |
0 | 128 |
$editblog_default_role = $option->option_value; |
9 | 129 |
} |
0 | 130 |
$disabled = false; |
9 | 131 |
$class = 'all-options'; |
0 | 132 |
if ( is_serialized( $option->option_value ) ) { |
133 |
if ( is_serialized_string( $option->option_value ) ) { |
|
134 |
$option->option_value = esc_html( maybe_unserialize( $option->option_value ) ); |
|
135 |
} else { |
|
136 |
$option->option_value = 'SERIALIZED DATA'; |
|
9 | 137 |
$disabled = true; |
138 |
$class = 'all-options disabled'; |
|
0 | 139 |
} |
140 |
} |
|
141 |
if ( strpos( $option->option_value, "\n" ) !== false ) { |
|
9 | 142 |
?> |
0 | 143 |
<tr class="form-field"> |
9 | 144 |
<th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>"><?php echo ucwords( str_replace( '_', ' ', $option->option_name ) ); ?></label></th> |
145 |
<td><textarea class="<?php echo $class; ?>" rows="5" cols="40" name="option[<?php echo esc_attr( $option->option_name ); ?>]" id="<?php echo esc_attr( $option->option_name ); ?>"<?php disabled( $disabled ); ?>><?php echo esc_textarea( $option->option_value ); ?></textarea></td> |
|
0 | 146 |
</tr> |
9 | 147 |
<?php |
0 | 148 |
} else { |
9 | 149 |
?> |
0 | 150 |
<tr class="form-field"> |
9 | 151 |
<th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>"><?php echo esc_html( ucwords( str_replace( '_', ' ', $option->option_name ) ) ); ?></label></th> |
0 | 152 |
<?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ) ) ) { ?> |
9 | 153 |
<td><code><?php echo esc_html( $option->option_value ); ?></code></td> |
0 | 154 |
<?php } else { ?> |
9 | 155 |
<td><input class="<?php echo $class; ?>" name="option[<?php echo esc_attr( $option->option_name ); ?>]" type="text" id="<?php echo esc_attr( $option->option_name ); ?>" value="<?php echo esc_attr( $option->option_value ); ?>" size="40" <?php disabled( $disabled ); ?> /></td> |
0 | 156 |
<?php } ?> |
157 |
</tr> |
|
9 | 158 |
<?php |
0 | 159 |
} |
160 |
} // End foreach |
|
5 | 161 |
/** |
162 |
* Fires at the end of the Edit Site form, before the submit button. |
|
163 |
* |
|
164 |
* @since 3.0.0 |
|
165 |
* |
|
166 |
* @param int $id Site ID. |
|
167 |
*/ |
|
0 | 168 |
do_action( 'wpmueditblogaction', $id ); |
169 |
?> |
|
170 |
</table> |
|
171 |
<?php submit_button(); ?> |
|
172 |
</form> |
|
173 |
||
174 |
</div> |
|
175 |
<?php |
|
176 |
require( ABSPATH . 'wp-admin/admin-footer.php' ); |