]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/network/site-info.php
WordPress 4.6.3
[autoinstalls/wordpress.git] / wp-admin / network / site-info.php
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
13 if ( ! is_multisite() ) {
14         wp_die( __( 'Multisite support is not enabled.' ) );
15 }
16
17 if ( ! current_user_can( 'manage_sites' ) ) {
18         wp_die( __( 'Sorry, you are not allowed to edit this site.' ) );
19 }
20
21 get_current_screen()->add_help_tab( array(
22         'id'      => 'overview',
23         'title'   => __( 'Overview' ),
24         'content' =>
25                 '<p>' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' .
26                 '<p>' . __( '<strong>Info</strong> &mdash; The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '</p>' .
27                 '<p>' . __( '<strong>Users</strong> &mdash; This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '</p>' .
28                 '<p>' . sprintf( __( '<strong>Themes</strong> &mdash; This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' .
29                 '<p>' . __( '<strong>Settings</strong> &mdash; This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '</p>'
30 ) );
31
32 get_current_screen()->set_help_sidebar(
33         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
34         '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>' ) . '</p>' .
35         '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>' ) . '</p>'
36 );
37
38 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
39
40 if ( ! $id ) {
41         wp_die( __('Invalid site ID.') );
42 }
43
44 $details = get_blog_details( $id );
45 if ( ! $details ) {
46         wp_die( __( 'The requested site does not exist.' ) );
47 }
48
49 if ( ! can_edit_network( $details->site_id ) ) {
50         wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
51 }
52
53 $parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME );
54 $is_main_site = is_main_site( $id );
55
56 if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
57         check_admin_referer( 'edit-site' );
58
59         switch_to_blog( $id );
60
61         // Rewrite rules can't be flushed during switch to blog.
62         delete_option( 'rewrite_rules' );
63
64         $blog_data = wp_unslash( $_POST['blog'] );
65         $blog_data['scheme'] = $parsed_scheme;
66
67         if ( $is_main_site ) {
68                 // On the network's main site, don't allow the domain or path to change.
69                 $blog_data['domain'] = $details->domain;
70                 $blog_data['path'] = $details->path;
71         } else {
72                 // For any other site, the scheme, domain, and path can all be changed. We first
73                 // need to ensure a scheme has been provided, otherwise fallback to the existing.
74                 $new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME );
75
76                 if ( ! $new_url_scheme ) {
77                         $blog_data['url'] = esc_url( $parsed_scheme . '://' . $blog_data['url'] );
78                 }
79                 $update_parsed_url = parse_url( $blog_data['url'] );
80
81                 // If a path is not provided, use the default of `/`.
82                 if ( ! isset( $update_parsed_url['path'] ) ) {
83                         $update_parsed_url['path'] = '/';
84                 }
85
86                 $blog_data['scheme'] = $update_parsed_url['scheme'];
87                 $blog_data['domain'] = $update_parsed_url['host'];
88                 $blog_data['path'] = $update_parsed_url['path'];
89         }
90
91         $existing_details = get_blog_details( $id, false );
92         $blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
93         foreach ( $blog_data_checkboxes as $c ) {
94                 if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) {
95                         $blog_data[ $c ] = $existing_details->$c;
96                 } else {
97                         $blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0;
98                 }
99         }
100
101         update_blog_details( $id, $blog_data );
102
103         // Maybe update home and siteurl options.
104         $new_details = get_blog_details( $id, false );
105
106         $old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) );
107         $old_home_parsed = parse_url( $old_home_url );
108
109         if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
110                 $new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
111                 update_option( 'home', $new_home_url );
112         }
113
114         $old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
115         $old_site_parsed = parse_url( $old_site_url );
116
117         if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
118                 $new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
119                 update_option( 'siteurl', $new_site_url );
120         }
121
122         restore_current_blog();
123         wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-info.php' ) );
124         exit;
125 }
126
127 if ( isset( $_GET['update'] ) ) {
128         $messages = array();
129         if ( 'updated' == $_GET['update'] ) {
130                 $messages[] = __( 'Site info updated.' );
131         }
132 }
133
134 $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
135
136 $parent_file = 'sites.php';
137 $submenu_file = 'sites.php';
138
139 require( ABSPATH . 'wp-admin/admin-header.php' );
140
141 ?>
142
143 <div class="wrap">
144 <h1 id="edit-site"><?php echo $title; ?></h1>
145 <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>
146 <?php
147
148 network_edit_site_nav( array(
149         'blog_id'  => $id,
150         'selected' => 'site-info'
151 ) );
152
153 if ( ! empty( $messages ) ) {
154         foreach ( $messages as $msg ) {
155                 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
156         }
157 }
158 ?>
159 <form method="post" action="site-info.php?action=update-site">
160         <?php wp_nonce_field( 'edit-site' ); ?>
161         <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
162         <table class="form-table">
163                 <?php
164                 // The main site of the network should not be updated on this page.
165                 if ( $is_main_site ) : ?>
166                 <tr class="form-field">
167                         <th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
168                         <td><?php echo esc_url( $details->domain . $details->path ); ?></td>
169                 </tr>
170                 <?php
171                 // For any other site, the scheme, domain, and path can all be changed.
172                 else : ?>
173                 <tr class="form-field form-required">
174                         <th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
175                         <td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
176                 </tr>
177                 <?php endif; ?>
178
179                 <tr class="form-field">
180                         <th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
181                         <td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" /></td>
182                 </tr>
183                 <tr class="form-field">
184                         <th scope="row"><label for="blog_last_updated"><?php _e( 'Last Updated' ); ?></label></th>
185                         <td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ) ?>" /></td>
186                 </tr>
187                 <?php
188                 $attribute_fields = array( 'public' => __( 'Public' ) );
189                 if ( ! $is_main_site ) {
190                         $attribute_fields['archived'] = __( 'Archived' );
191                         $attribute_fields['spam']     = _x( 'Spam', 'site' );
192                         $attribute_fields['deleted']  = __( 'Deleted' );
193                 }
194                 $attribute_fields['mature'] = __( 'Mature' );
195                 ?>
196                 <tr>
197                         <th scope="row"><?php _e( 'Attributes' ); ?></th>
198                         <td>
199                         <fieldset>
200                         <legend class="screen-reader-text"><?php _e( 'Set site attributes' ) ?></legend>
201                         <?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
202                                 <label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); disabled( ! in_array( $details->$field_key, array( 0, 1 ) ) ); ?> />
203                                 <?php echo $field_label; ?></label><br/>
204                         <?php endforeach; ?>
205                         <fieldset>
206                         </td>
207                 </tr>
208         </table>
209         <?php submit_button(); ?>
210 </form>
211
212 </div>
213 <?php
214 require( ABSPATH . 'wp-admin/admin-footer.php' );