site-info.php 6.9 KB

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