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