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