wp/wp-admin/network/site-info.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    64 		if ( ! isset( $update_parsed_url['path'] ) ) {
    64 		if ( ! isset( $update_parsed_url['path'] ) ) {
    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 
       
    70 		// Make sure to not lose the port if it was provided.
    69 		$blog_data['domain'] = $update_parsed_url['host'];
    71 		$blog_data['domain'] = $update_parsed_url['host'];
    70 		$blog_data['path']   = $update_parsed_url['path'];
    72 		if ( isset( $update_parsed_url['port'] ) ) {
       
    73 			$blog_data['domain'] .= ':' . $update_parsed_url['port'];
       
    74 		}
       
    75 
       
    76 		$blog_data['path'] = $update_parsed_url['path'];
    71 	}
    77 	}
    72 
    78 
    73 	$existing_details     = get_site( $id );
    79 	$existing_details     = get_site( $id );
    74 	$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
    80 	$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
    75 
    81 
    86 	// Maybe update home and siteurl options.
    92 	// Maybe update home and siteurl options.
    87 	$new_details = get_site( $id );
    93 	$new_details = get_site( $id );
    88 
    94 
    89 	$old_home_url    = trailingslashit( esc_url( get_option( 'home' ) ) );
    95 	$old_home_url    = trailingslashit( esc_url( get_option( 'home' ) ) );
    90 	$old_home_parsed = parse_url( $old_home_url );
    96 	$old_home_parsed = parse_url( $old_home_url );
    91 
    97 	$old_home_host   = $old_home_parsed['host'] . ( isset( $old_home_parsed['port'] ) ? ':' . $old_home_parsed['port'] : '' );
    92 	if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
    98 
    93 		$new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    99 	if ( $old_home_host === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
       
   100 		$new_home_url = untrailingslashit( sanitize_url( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    94 		update_option( 'home', $new_home_url );
   101 		update_option( 'home', $new_home_url );
    95 	}
   102 	}
    96 
   103 
    97 	$old_site_url    = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
   104 	$old_site_url    = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
    98 	$old_site_parsed = parse_url( $old_site_url );
   105 	$old_site_parsed = parse_url( $old_site_url );
    99 
   106 	$old_site_host   = $old_site_parsed['host'] . ( isset( $old_site_parsed['port'] ) ? ':' . $old_site_parsed['port'] : '' );
   100 	if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
   107 
   101 		$new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
   108 	if ( $old_site_host === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
       
   109 		$new_site_url = untrailingslashit( sanitize_url( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
   102 		update_option( 'siteurl', $new_site_url );
   110 		update_option( 'siteurl', $new_site_url );
   103 	}
   111 	}
   104 
   112 
   105 	restore_current_blog();
   113 	restore_current_blog();
   106 	wp_redirect(
   114 	wp_redirect(
   144 		'selected' => 'site-info',
   152 		'selected' => 'site-info',
   145 	)
   153 	)
   146 );
   154 );
   147 
   155 
   148 if ( ! empty( $messages ) ) {
   156 if ( ! empty( $messages ) ) {
       
   157 	$notice_args = array(
       
   158 		'type'        => 'success',
       
   159 		'dismissible' => true,
       
   160 		'id'          => 'message',
       
   161 	);
       
   162 
   149 	foreach ( $messages as $msg ) {
   163 	foreach ( $messages as $msg ) {
   150 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
   164 		wp_admin_notice( $msg, $notice_args );
   151 	}
   165 	}
   152 }
   166 }
   153 ?>
   167 ?>
   154 <form method="post" action="site-info.php?action=update-site">
   168 <form method="post" action="site-info.php?action=update-site">
   155 	<?php wp_nonce_field( 'edit-site' ); ?>
   169 	<?php wp_nonce_field( 'edit-site' ); ?>
   192 		?>
   206 		?>
   193 		<tr>
   207 		<tr>
   194 			<th scope="row"><?php _e( 'Attributes' ); ?></th>
   208 			<th scope="row"><?php _e( 'Attributes' ); ?></th>
   195 			<td>
   209 			<td>
   196 			<fieldset>
   210 			<fieldset>
   197 			<legend class="screen-reader-text"><?php _e( 'Set site attributes' ); ?></legend>
   211 			<legend class="screen-reader-text">
       
   212 				<?php
       
   213 				/* translators: Hidden accessibility text. */
       
   214 				_e( 'Set site attributes' );
       
   215 				?>
       
   216 			</legend>
   198 			<?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
   217 			<?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
   199 				<label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( (int) $details->$field_key, array( 0, 1 ), true ) ); ?> />
   218 				<label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( (int) $details->$field_key, array( 0, 1 ), true ) ); ?> />
   200 				<?php echo $field_label; ?></label><br/>
   219 				<?php echo $field_label; ?></label><br />
   201 			<?php endforeach; ?>
   220 			<?php endforeach; ?>
   202 			<fieldset>
   221 			<fieldset>
   203 			</td>
   222 			</td>
   204 		</tr>
   223 		</tr>
   205 	</table>
   224 	</table>