site-settings.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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( 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. $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 ( $key === 0 || is_array( $val ) || in_array( $key, $skip_options ) ) {
  36. continue; // Avoids "0 is a protected WP option and may not be modified" error when edit 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. /* translators: %s: Site title. */
  68. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  69. $parent_file = 'sites.php';
  70. $submenu_file = 'sites.php';
  71. require( ABSPATH . 'wp-admin/admin-header.php' );
  72. ?>
  73. <div class="wrap">
  74. <h1 id="edit-site"><?php echo $title; ?></h1>
  75. <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>
  76. <?php
  77. network_edit_site_nav(
  78. array(
  79. 'blog_id' => $id,
  80. 'selected' => 'site-settings',
  81. )
  82. );
  83. if ( ! empty( $messages ) ) {
  84. foreach ( $messages as $msg ) {
  85. echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  86. }
  87. }
  88. ?>
  89. <form method="post" action="site-settings.php?action=update-site">
  90. <?php wp_nonce_field( 'edit-site' ); ?>
  91. <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
  92. <table class="form-table" role="presentation">
  93. <?php
  94. $blog_prefix = $wpdb->get_blog_prefix( $id );
  95. $sql = "SELECT * FROM {$blog_prefix}options
  96. WHERE option_name NOT LIKE %s
  97. AND option_name NOT LIKE %s";
  98. $query = $wpdb->prepare(
  99. $sql,
  100. $wpdb->esc_like( '_' ) . '%',
  101. '%' . $wpdb->esc_like( 'user_roles' )
  102. );
  103. $options = $wpdb->get_results( $query );
  104. foreach ( $options as $option ) {
  105. if ( $option->option_name == 'default_role' ) {
  106. $editblog_default_role = $option->option_value;
  107. }
  108. $disabled = false;
  109. $class = 'all-options';
  110. if ( is_serialized( $option->option_value ) ) {
  111. if ( is_serialized_string( $option->option_value ) ) {
  112. $option->option_value = esc_html( maybe_unserialize( $option->option_value ) );
  113. } else {
  114. $option->option_value = 'SERIALIZED DATA';
  115. $disabled = true;
  116. $class = 'all-options disabled';
  117. }
  118. }
  119. if ( strpos( $option->option_value, "\n" ) !== false ) {
  120. ?>
  121. <tr class="form-field">
  122. <th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>"><?php echo ucwords( str_replace( '_', ' ', $option->option_name ) ); ?></label></th>
  123. <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>
  124. </tr>
  125. <?php
  126. } else {
  127. ?>
  128. <tr class="form-field">
  129. <th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>"><?php echo esc_html( ucwords( str_replace( '_', ' ', $option->option_name ) ) ); ?></label></th>
  130. <?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ) ) ) { ?>
  131. <td><code><?php echo esc_html( $option->option_value ); ?></code></td>
  132. <?php } else { ?>
  133. <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>
  134. <?php } ?>
  135. </tr>
  136. <?php
  137. }
  138. } // End foreach
  139. /**
  140. * Fires at the end of the Edit Site form, before the submit button.
  141. *
  142. * @since 3.0.0
  143. *
  144. * @param int $id Site ID.
  145. */
  146. do_action( 'wpmueditblogaction', $id );
  147. ?>
  148. </table>
  149. <?php submit_button(); ?>
  150. </form>
  151. </div>
  152. <?php
  153. require( ABSPATH . 'wp-admin/admin-footer.php' );