site-info.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 __DIR__ . '/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'] ) ? (int) $_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( (int) $existing_details->$c, array( 0, 1 ), true ) ) {
  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( sanitize_url( $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( sanitize_url( $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. // Used in the HTML title tag.
  99. /* translators: %s: Site title. */
  100. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  101. $parent_file = 'sites.php';
  102. $submenu_file = 'sites.php';
  103. require_once ABSPATH . 'wp-admin/admin-header.php';
  104. ?>
  105. <div class="wrap">
  106. <h1 id="edit-site"><?php echo $title; ?></h1>
  107. <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>
  108. <?php
  109. network_edit_site_nav(
  110. array(
  111. 'blog_id' => $id,
  112. 'selected' => 'site-info',
  113. )
  114. );
  115. if ( ! empty( $messages ) ) {
  116. foreach ( $messages as $msg ) {
  117. echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  118. }
  119. }
  120. ?>
  121. <form method="post" action="site-info.php?action=update-site">
  122. <?php wp_nonce_field( 'edit-site' ); ?>
  123. <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
  124. <table class="form-table" role="presentation">
  125. <?php
  126. // The main site of the network should not be updated on this page.
  127. if ( $is_main_site ) :
  128. ?>
  129. <tr class="form-field">
  130. <th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
  131. <td><?php echo esc_url( $parsed_scheme . '://' . $details->domain . $details->path ); ?></td>
  132. </tr>
  133. <?php
  134. // For any other site, the scheme, domain, and path can all be changed.
  135. else :
  136. ?>
  137. <tr class="form-field form-required">
  138. <th scope="row"><label for="url"><?php _e( 'Site Address (URL)' ); ?></label></th>
  139. <td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
  140. </tr>
  141. <?php endif; ?>
  142. <tr class="form-field">
  143. <th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ); ?></label></th>
  144. <td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ); ?>" /></td>
  145. </tr>
  146. <tr class="form-field">
  147. <th scope="row"><label for="blog_last_updated"><?php _e( 'Last Updated' ); ?></label></th>
  148. <td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ); ?>" /></td>
  149. </tr>
  150. <?php
  151. $attribute_fields = array( 'public' => _x( 'Public', 'site' ) );
  152. if ( ! $is_main_site ) {
  153. $attribute_fields['archived'] = __( 'Archived' );
  154. $attribute_fields['spam'] = _x( 'Spam', 'site' );
  155. $attribute_fields['deleted'] = __( 'Deleted' );
  156. }
  157. $attribute_fields['mature'] = __( 'Mature' );
  158. ?>
  159. <tr>
  160. <th scope="row"><?php _e( 'Attributes' ); ?></th>
  161. <td>
  162. <fieldset>
  163. <legend class="screen-reader-text"><?php _e( 'Set site attributes' ); ?></legend>
  164. <?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
  165. <label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( (int) $details->$field_key, array( 0, 1 ), true ) ); ?> />
  166. <?php echo $field_label; ?></label><br />
  167. <?php endforeach; ?>
  168. <fieldset>
  169. </td>
  170. </tr>
  171. </table>
  172. <?php
  173. /**
  174. * Fires at the end of the site info form in network admin.
  175. *
  176. * @since 5.6.0
  177. *
  178. * @param int $id The site ID.
  179. */
  180. do_action( 'network_site_info_form', $id );
  181. submit_button();
  182. ?>
  183. </form>
  184. </div>
  185. <?php
  186. require_once ABSPATH . 'wp-admin/admin-footer.php';