site-info.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-info.php' ) );
  82. exit;
  83. }
  84. if ( isset( $_GET['update'] ) ) {
  85. $messages = array();
  86. if ( 'updated' == $_GET['update'] ) {
  87. $messages[] = __( 'Site info updated.' );
  88. }
  89. }
  90. /* translators: %s: site name */
  91. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  92. $parent_file = 'sites.php';
  93. $submenu_file = 'sites.php';
  94. require( ABSPATH . 'wp-admin/admin-header.php' );
  95. ?>
  96. <div class="wrap">
  97. <h1 id="edit-site"><?php echo $title; ?></h1>
  98. <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>
  99. <?php
  100. network_edit_site_nav( array(
  101. 'blog_id' => $id,
  102. 'selected' => 'site-info'
  103. ) );
  104. if ( ! empty( $messages ) ) {
  105. foreach ( $messages as $msg ) {
  106. echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  107. }
  108. }
  109. ?>
  110. <form method="post" action="site-info.php?action=update-site">
  111. <?php wp_nonce_field( 'edit-site' ); ?>
  112. <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
  113. <table class="form-table">
  114. <?php
  115. // The main site of the network should not be updated on this page.
  116. if ( $is_main_site ) : ?>
  117. <tr class="form-field">
  118. <th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
  119. <td><?php echo esc_url( $parsed_scheme . '://' . $details->domain . $details->path ); ?></td>
  120. </tr>
  121. <?php
  122. // For any other site, the scheme, domain, and path can all be changed.
  123. else : ?>
  124. <tr class="form-field form-required">
  125. <th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
  126. <td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
  127. </tr>
  128. <?php endif; ?>
  129. <tr class="form-field">
  130. <th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
  131. <td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" /></td>
  132. </tr>
  133. <tr class="form-field">
  134. <th scope="row"><label for="blog_last_updated"><?php _e( 'Last Updated' ); ?></label></th>
  135. <td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ) ?>" /></td>
  136. </tr>
  137. <?php
  138. $attribute_fields = array( 'public' => __( 'Public' ) );
  139. if ( ! $is_main_site ) {
  140. $attribute_fields['archived'] = __( 'Archived' );
  141. $attribute_fields['spam'] = _x( 'Spam', 'site' );
  142. $attribute_fields['deleted'] = __( 'Deleted' );
  143. }
  144. $attribute_fields['mature'] = __( 'Mature' );
  145. ?>
  146. <tr>
  147. <th scope="row"><?php _e( 'Attributes' ); ?></th>
  148. <td>
  149. <fieldset>
  150. <legend class="screen-reader-text"><?php _e( 'Set site attributes' ) ?></legend>
  151. <?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
  152. <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 ) ) ); ?> />
  153. <?php echo $field_label; ?></label><br/>
  154. <?php endforeach; ?>
  155. <fieldset>
  156. </td>
  157. </tr>
  158. </table>
  159. <?php submit_button(); ?>
  160. </form>
  161. </div>
  162. <?php
  163. require( ABSPATH . 'wp-admin/admin-footer.php' );