site-settings.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
  14. get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
  15. $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  16. if ( ! $id )
  17. wp_die( __('Invalid site ID.') );
  18. $details = get_site( $id );
  19. if ( ! $details ) {
  20. wp_die( __( 'The requested site does not exist.' ) );
  21. }
  22. if ( !can_edit_network( $details->site_id ) )
  23. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  24. $is_main_site = is_main_site( $id );
  25. if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] && is_array( $_POST['option'] ) ) {
  26. check_admin_referer( 'edit-site' );
  27. switch_to_blog( $id );
  28. $skip_options = array( 'allowedthemes' ); // Don't update these options since they are handled elsewhere in the form.
  29. foreach ( (array) $_POST['option'] as $key => $val ) {
  30. $key = wp_unslash( $key );
  31. $val = wp_unslash( $val );
  32. if ( $key === 0 || is_array( $val ) || in_array($key, $skip_options) )
  33. continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options
  34. update_option( $key, $val );
  35. }
  36. /**
  37. * Fires after the site options are updated.
  38. *
  39. * @since 3.0.0
  40. * @since 4.4.0 Added `$id` parameter.
  41. *
  42. * @param int $id The ID of the site being updated.
  43. */
  44. do_action( 'wpmu_update_blog_options', $id );
  45. restore_current_blog();
  46. wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-settings.php') );
  47. exit;
  48. }
  49. if ( isset($_GET['update']) ) {
  50. $messages = array();
  51. if ( 'updated' == $_GET['update'] )
  52. $messages[] = __('Site options updated.');
  53. }
  54. /* translators: %s: site name */
  55. $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
  56. $parent_file = 'sites.php';
  57. $submenu_file = 'sites.php';
  58. require( ABSPATH . 'wp-admin/admin-header.php' );
  59. ?>
  60. <div class="wrap">
  61. <h1 id="edit-site"><?php echo $title; ?></h1>
  62. <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>
  63. <?php
  64. network_edit_site_nav( array(
  65. 'blog_id' => $id,
  66. 'selected' => 'site-settings'
  67. ) );
  68. if ( ! empty( $messages ) ) {
  69. foreach ( $messages as $msg )
  70. echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
  71. } ?>
  72. <form method="post" action="site-settings.php?action=update-site">
  73. <?php wp_nonce_field( 'edit-site' ); ?>
  74. <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
  75. <table class="form-table">
  76. <?php
  77. $blog_prefix = $wpdb->get_blog_prefix( $id );
  78. $sql = "SELECT * FROM {$blog_prefix}options
  79. WHERE option_name NOT LIKE %s
  80. AND option_name NOT LIKE %s";
  81. $query = $wpdb->prepare( $sql,
  82. $wpdb->esc_like( '_' ) . '%',
  83. '%' . $wpdb->esc_like( 'user_roles' )
  84. );
  85. $options = $wpdb->get_results( $query );
  86. foreach ( $options as $option ) {
  87. if ( $option->option_name == 'default_role' )
  88. $editblog_default_role = $option->option_value;
  89. $disabled = false;
  90. $class = 'all-options';
  91. if ( is_serialized( $option->option_value ) ) {
  92. if ( is_serialized_string( $option->option_value ) ) {
  93. $option->option_value = esc_html( maybe_unserialize( $option->option_value ) );
  94. } else {
  95. $option->option_value = 'SERIALIZED DATA';
  96. $disabled = true;
  97. $class = 'all-options disabled';
  98. }
  99. }
  100. if ( strpos( $option->option_value, "\n" ) !== false ) {
  101. ?>
  102. <tr class="form-field">
  103. <th scope="row"><label for="<?php echo esc_attr( $option->option_name ) ?>"><?php echo ucwords( str_replace( "_", " ", $option->option_name ) ) ?></label></th>
  104. <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>
  105. </tr>
  106. <?php
  107. } else {
  108. ?>
  109. <tr class="form-field">
  110. <th scope="row"><label for="<?php echo esc_attr( $option->option_name ) ?>"><?php echo esc_html( ucwords( str_replace( "_", " ", $option->option_name ) ) ); ?></label></th>
  111. <?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ) ) ) { ?>
  112. <td><code><?php echo esc_html( $option->option_value ) ?></code></td>
  113. <?php } else { ?>
  114. <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>
  115. <?php } ?>
  116. </tr>
  117. <?php
  118. }
  119. } // End foreach
  120. /**
  121. * Fires at the end of the Edit Site form, before the submit button.
  122. *
  123. * @since 3.0.0
  124. *
  125. * @param int $id Site ID.
  126. */
  127. do_action( 'wpmueditblogaction', $id );
  128. ?>
  129. </table>
  130. <?php submit_button(); ?>
  131. </form>
  132. </div>
  133. <?php
  134. require( ABSPATH . 'wp-admin/admin-footer.php' );