wp/wp-admin/network/site-info.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    18 get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
    18 get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
    19 
    19 
    20 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    20 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    21 
    21 
    22 if ( ! $id ) {
    22 if ( ! $id ) {
    23 	wp_die( __('Invalid site ID.') );
    23 	wp_die( __( 'Invalid site ID.' ) );
    24 }
    24 }
    25 
    25 
    26 $details = get_site( $id );
    26 $details = get_site( $id );
    27 if ( ! $details ) {
    27 if ( ! $details ) {
    28 	wp_die( __( 'The requested site does not exist.' ) );
    28 	wp_die( __( 'The requested site does not exist.' ) );
    31 if ( ! can_edit_network( $details->site_id ) ) {
    31 if ( ! can_edit_network( $details->site_id ) ) {
    32 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    32 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    33 }
    33 }
    34 
    34 
    35 $parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME );
    35 $parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME );
    36 $is_main_site = is_main_site( $id );
    36 $is_main_site  = is_main_site( $id );
    37 
    37 
    38 if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
    38 if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
    39 	check_admin_referer( 'edit-site' );
    39 	check_admin_referer( 'edit-site' );
    40 
    40 
    41 	switch_to_blog( $id );
    41 	switch_to_blog( $id );
    42 
    42 
    43 	// Rewrite rules can't be flushed during switch to blog.
    43 	// Rewrite rules can't be flushed during switch to blog.
    44 	delete_option( 'rewrite_rules' );
    44 	delete_option( 'rewrite_rules' );
    45 
    45 
    46 	$blog_data = wp_unslash( $_POST['blog'] );
    46 	$blog_data           = wp_unslash( $_POST['blog'] );
    47 	$blog_data['scheme'] = $parsed_scheme;
    47 	$blog_data['scheme'] = $parsed_scheme;
    48 
    48 
    49 	if ( $is_main_site ) {
    49 	if ( $is_main_site ) {
    50 		// On the network's main site, don't allow the domain or path to change.
    50 		// On the network's main site, don't allow the domain or path to change.
    51 		$blog_data['domain'] = $details->domain;
    51 		$blog_data['domain'] = $details->domain;
    52 		$blog_data['path'] = $details->path;
    52 		$blog_data['path']   = $details->path;
    53 	} else {
    53 	} else {
    54 		// For any other site, the scheme, domain, and path can all be changed. We first
    54 		// For any other site, the scheme, domain, and path can all be changed. We first
    55 		// need to ensure a scheme has been provided, otherwise fallback to the existing.
    55 		// need to ensure a scheme has been provided, otherwise fallback to the existing.
    56 		$new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME );
    56 		$new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME );
    57 
    57 
    65 			$update_parsed_url['path'] = '/';
    65 			$update_parsed_url['path'] = '/';
    66 		}
    66 		}
    67 
    67 
    68 		$blog_data['scheme'] = $update_parsed_url['scheme'];
    68 		$blog_data['scheme'] = $update_parsed_url['scheme'];
    69 		$blog_data['domain'] = $update_parsed_url['host'];
    69 		$blog_data['domain'] = $update_parsed_url['host'];
    70 		$blog_data['path'] = $update_parsed_url['path'];
    70 		$blog_data['path']   = $update_parsed_url['path'];
    71 	}
    71 	}
    72 
    72 
    73 	$existing_details = get_site( $id );
    73 	$existing_details     = get_site( $id );
    74 	$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
    74 	$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
    75 	foreach ( $blog_data_checkboxes as $c ) {
    75 	foreach ( $blog_data_checkboxes as $c ) {
    76 		if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) {
    76 		if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) {
    77 			$blog_data[ $c ] = $existing_details->$c;
    77 			$blog_data[ $c ] = $existing_details->$c;
    78 		} else {
    78 		} else {
    83 	update_blog_details( $id, $blog_data );
    83 	update_blog_details( $id, $blog_data );
    84 
    84 
    85 	// Maybe update home and siteurl options.
    85 	// Maybe update home and siteurl options.
    86 	$new_details = get_site( $id );
    86 	$new_details = get_site( $id );
    87 
    87 
    88 	$old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) );
    88 	$old_home_url    = trailingslashit( esc_url( get_option( 'home' ) ) );
    89 	$old_home_parsed = parse_url( $old_home_url );
    89 	$old_home_parsed = parse_url( $old_home_url );
    90 
    90 
    91 	if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
    91 	if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
    92 		$new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    92 		$new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    93 		update_option( 'home', $new_home_url );
    93 		update_option( 'home', $new_home_url );
    94 	}
    94 	}
    95 
    95 
    96 	$old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
    96 	$old_site_url    = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
    97 	$old_site_parsed = parse_url( $old_site_url );
    97 	$old_site_parsed = parse_url( $old_site_url );
    98 
    98 
    99 	if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
    99 	if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
   100 		$new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
   100 		$new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
   101 		update_option( 'siteurl', $new_site_url );
   101 		update_option( 'siteurl', $new_site_url );
   102 	}
   102 	}
   103 
   103 
   104 	restore_current_blog();
   104 	restore_current_blog();
   105 	wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-info.php' ) );
   105 	wp_redirect(
       
   106 		add_query_arg(
       
   107 			array(
       
   108 				'update' => 'updated',
       
   109 				'id'     => $id,
       
   110 			),
       
   111 			'site-info.php'
       
   112 		)
       
   113 	);
   106 	exit;
   114 	exit;
   107 }
   115 }
   108 
   116 
   109 if ( isset( $_GET['update'] ) ) {
   117 if ( isset( $_GET['update'] ) ) {
   110 	$messages = array();
   118 	$messages = array();
   114 }
   122 }
   115 
   123 
   116 /* translators: %s: site name */
   124 /* translators: %s: site name */
   117 $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
   125 $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
   118 
   126 
   119 $parent_file = 'sites.php';
   127 $parent_file  = 'sites.php';
   120 $submenu_file = 'sites.php';
   128 $submenu_file = 'sites.php';
   121 
   129 
   122 require( ABSPATH . 'wp-admin/admin-header.php' );
   130 require( ABSPATH . 'wp-admin/admin-header.php' );
   123 
   131 
   124 ?>
   132 ?>
   126 <div class="wrap">
   134 <div class="wrap">
   127 <h1 id="edit-site"><?php echo $title; ?></h1>
   135 <h1 id="edit-site"><?php echo $title; ?></h1>
   128 <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>
   136 <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>
   129 <?php
   137 <?php
   130 
   138 
   131 network_edit_site_nav( array(
   139 network_edit_site_nav(
   132 	'blog_id'  => $id,
   140 	array(
   133 	'selected' => 'site-info'
   141 		'blog_id'  => $id,
   134 ) );
   142 		'selected' => 'site-info',
       
   143 	)
       
   144 );
   135 
   145 
   136 if ( ! empty( $messages ) ) {
   146 if ( ! empty( $messages ) ) {
   137 	foreach ( $messages as $msg ) {
   147 	foreach ( $messages as $msg ) {
   138 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
   148 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
   139 	}
   149 	}
   140 }
   150 }
   141 ?>
   151 ?>
   142 <form method="post" action="site-info.php?action=update-site">
   152 <form method="post" action="site-info.php?action=update-site">
   143 	<?php wp_nonce_field( 'edit-site' ); ?>
   153 	<?php wp_nonce_field( 'edit-site' ); ?>
   144 	<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
   154 	<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
   145 	<table class="form-table">
   155 	<table class="form-table" role="presentation">
   146 		<?php
   156 		<?php
   147 		// The main site of the network should not be updated on this page.
   157 		// The main site of the network should not be updated on this page.
   148 		if ( $is_main_site ) : ?>
   158 		if ( $is_main_site ) :
       
   159 			?>
   149 		<tr class="form-field">
   160 		<tr class="form-field">
   150 			<th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
   161 			<th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
   151 			<td><?php echo esc_url( $parsed_scheme . '://' . $details->domain . $details->path ); ?></td>
   162 			<td><?php echo esc_url( $parsed_scheme . '://' . $details->domain . $details->path ); ?></td>
   152 		</tr>
   163 		</tr>
   153 		<?php
   164 			<?php
   154 		// For any other site, the scheme, domain, and path can all be changed.
   165 			// For any other site, the scheme, domain, and path can all be changed.
   155 		else : ?>
   166 		else :
       
   167 			?>
   156 		<tr class="form-field form-required">
   168 		<tr class="form-field form-required">
   157 			<th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
   169 			<th scope="row"><label for="url"><?php _e( 'Site Address (URL)' ); ?></label></th>
   158 			<td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
   170 			<td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
   159 		</tr>
   171 		</tr>
   160 		<?php endif; ?>
   172 		<?php endif; ?>
   161 
   173 
   162 		<tr class="form-field">
   174 		<tr class="form-field">
   163 			<th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
   175 			<th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ); ?></label></th>
   164 			<td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" /></td>
   176 			<td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ); ?>" /></td>
   165 		</tr>
   177 		</tr>
   166 		<tr class="form-field">
   178 		<tr class="form-field">
   167 			<th scope="row"><label for="blog_last_updated"><?php _e( 'Last Updated' ); ?></label></th>
   179 			<th scope="row"><label for="blog_last_updated"><?php _e( 'Last Updated' ); ?></label></th>
   168 			<td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ) ?>" /></td>
   180 			<td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ); ?>" /></td>
   169 		</tr>
   181 		</tr>
   170 		<?php
   182 		<?php
   171 		$attribute_fields = array( 'public' => __( 'Public' ) );
   183 		$attribute_fields = array( 'public' => __( 'Public' ) );
   172 		if ( ! $is_main_site ) {
   184 		if ( ! $is_main_site ) {
   173 			$attribute_fields['archived'] = __( 'Archived' );
   185 			$attribute_fields['archived'] = __( 'Archived' );
   178 		?>
   190 		?>
   179 		<tr>
   191 		<tr>
   180 			<th scope="row"><?php _e( 'Attributes' ); ?></th>
   192 			<th scope="row"><?php _e( 'Attributes' ); ?></th>
   181 			<td>
   193 			<td>
   182 			<fieldset>
   194 			<fieldset>
   183 			<legend class="screen-reader-text"><?php _e( 'Set site attributes' ) ?></legend>
   195 			<legend class="screen-reader-text"><?php _e( 'Set site attributes' ); ?></legend>
   184 			<?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
   196 			<?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
   185 				<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 ) ) ); ?> />
   197 				<label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( $details->$field_key, array( 0, 1 ) ) ); ?> />
   186 				<?php echo $field_label; ?></label><br/>
   198 				<?php echo $field_label; ?></label><br/>
   187 			<?php endforeach; ?>
   199 			<?php endforeach; ?>
   188 			<fieldset>
   200 			<fieldset>
   189 			</td>
   201 			</td>
   190 		</tr>
   202 		</tr>