site-settings.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * Edit Site Settings 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. $is_main_site = is_main_site( $id );
  28. if ( isset( $_REQUEST['action'] ) && 'update-site' === $_REQUEST['action'] && is_array( $_POST['option'] ) ) {
  29. check_admin_referer( 'edit-site' );
  30. switch_to_blog( $id );
  31. $skip_options = array( 'allowedthemes' ); // Don't update these options since they are handled elsewhere in the form.
  32. foreach ( (array) $_POST['option'] as $key => $val ) {
  33. $key = wp_unslash( $key );
  34. $val = wp_unslash( $val );
  35. if ( 0 === $key || is_array( $val ) || in_array( $key, $skip_options, true ) ) {
  36. continue; // Avoids "0 is a protected WP option and may not be modified" error when editing blog options.
  37. }
  38. update_option( $key, $val );
  39. }
  40. /**
  41. * Fires after the site options are updated.
  42. *
  43. * @since 3.0.0
  44. * @since 4.4.0 Added `$id` parameter.
  45. *
  46. * @param int $id The ID of the site being updated.
  47. */
  48. do_action( 'wpmu_update_blog_options', $id );
  49. restore_current_blog();
  50. wp_redirect(
  51. add_query_arg(
  52. array(
  53. 'update' => 'updated',
  54. 'id' => $id,
  55. ),
  56. 'site-settings.php'
  57. )
  58. );
  59. exit;
  60. }
  61. if ( isset( $_GET['update'] ) ) {
  62. $messages = array();
  63. if ( 'updated' === $_GET['update'] ) {
  64. $messages[] = __( 'Site options updated.' );
  65. }
  66. }
  67. // Used in the HTML title tag.
  68. /* translators: %s: Site title. */
  69. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  70. $parent_file = 'sites.php';
  71. $submenu_file = 'sites.php';
  72. require_once ABSPATH . 'wp-admin/admin-header.php';
  73. ?>
  74. <div class="wrap">
  75. <h1 id="edit-site"><?php echo $title; ?></h1>
  76. <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>
  77. <?php
  78. network_edit_site_nav(
  79. array(
  80. 'blog_id' => $id,
  81. 'selected' => 'site-settings',
  82. )
  83. );
  84. if ( ! empty( $messages ) ) {
  85. foreach ( $messages as $msg ) {
  86. echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  87. }
  88. }
  89. ?>
  90. <form method="post" action="site-settings.php?action=update-site">
  91. <?php wp_nonce_field( 'edit-site' ); ?>
  92. <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
  93. <table class="form-table" role="presentation">
  94. <?php
  95. $blog_prefix = $wpdb->get_blog_prefix( $id );
  96. $sql = "SELECT * FROM {$blog_prefix}options
  97. WHERE option_name NOT LIKE %s
  98. AND option_name NOT LIKE %s";
  99. $query = $wpdb->prepare(
  100. $sql,
  101. $wpdb->esc_like( '_' ) . '%',
  102. '%' . $wpdb->esc_like( 'user_roles' )
  103. );
  104. $options = $wpdb->get_results( $query );
  105. foreach ( $options as $option ) {
  106. if ( 'default_role' === $option->option_name ) {
  107. $editblog_default_role = $option->option_value;
  108. }
  109. $disabled = false;
  110. $class = 'all-options';
  111. if ( is_serialized( $option->option_value ) ) {
  112. if ( is_serialized_string( $option->option_value ) ) {
  113. $option->option_value = esc_html( maybe_unserialize( $option->option_value ) );
  114. } else {
  115. $option->option_value = 'SERIALIZED DATA';
  116. $disabled = true;
  117. $class = 'all-options disabled';
  118. }
  119. }
  120. if ( strpos( $option->option_value, "\n" ) !== false ) {
  121. ?>
  122. <tr class="form-field">
  123. <th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>"><?php echo ucwords( str_replace( '_', ' ', $option->option_name ) ); ?></label></th>
  124. <td><textarea class="<?php echo $class; ?>" rows="5" cols="40" name="option[<?php echo esc_attr( $option->option_name ); ?>]" id="<?php echo esc_attr( $option->option_name ); ?>"<?php disabled( $disabled ); ?>><?php echo esc_textarea( $option->option_value ); ?></textarea></td>
  125. </tr>
  126. <?php
  127. } else {
  128. ?>
  129. <tr class="form-field">
  130. <th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>"><?php echo esc_html( ucwords( str_replace( '_', ' ', $option->option_name ) ) ); ?></label></th>
  131. <?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ), true ) ) { ?>
  132. <td><code><?php echo esc_html( $option->option_value ); ?></code></td>
  133. <?php } else { ?>
  134. <td><input class="<?php echo $class; ?>" name="option[<?php echo esc_attr( $option->option_name ); ?>]" type="text" id="<?php echo esc_attr( $option->option_name ); ?>" value="<?php echo esc_attr( $option->option_value ); ?>" size="40" <?php disabled( $disabled ); ?> /></td>
  135. <?php } ?>
  136. </tr>
  137. <?php
  138. }
  139. } // End foreach.
  140. /**
  141. * Fires at the end of the Edit Site form, before the submit button.
  142. *
  143. * @since 3.0.0
  144. *
  145. * @param int $id Site ID.
  146. */
  147. do_action( 'wpmueditblogaction', $id );
  148. ?>
  149. </table>
  150. <?php submit_button(); ?>
  151. </form>
  152. </div>
  153. <?php
  154. require_once ABSPATH . 'wp-admin/admin-footer.php';