home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-admin / network / site-settings.php < prev    next >
Encoding:
PHP Script  |  2017-07-17  |  5.3 KB  |  158 lines

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