Changeset 47759 for trunk/src/wp-includes/canonical.php
- Timestamp:
- 05/04/2020 09:03:11 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/canonical.php
r47727 r47759 49 49 // If we're not in wp-admin and the post has been published and preview nonce 50 50 // is non-existent or invalid then no need for preview in query. 51 if ( is_preview() && get_query_var( 'p' ) && 'publish' == get_post_status( get_query_var( 'p' ) ) ) {51 if ( is_preview() && get_query_var( 'p' ) && 'publish' === get_post_status( get_query_var( 'p' ) ) ) { 52 52 if ( ! isset( $_GET['preview_id'] ) 53 53 || ! isset( $_GET['preview_nonce'] ) 54 || ! wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . (int) $_GET['preview_id'] ) ) { 54 || ! wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . (int) $_GET['preview_id'] ) 55 ) { 55 56 $wp_query->is_preview = false; 56 57 } 57 58 } 58 59 59 if ( is_trackback() || is_search() || is_admin() || is_preview() || is_robots() || is_favicon() || ( $is_IIS && ! iis7_supports_permalinks() ) ) { 60 if ( is_admin() || is_search() || is_preview() || is_trackback() 61 || is_robots() || is_favicon() 62 || ( $is_IIS && ! iis7_supports_permalinks() ) 63 ) { 60 64 return; 61 65 } … … 96 100 } 97 101 98 $id = get_query_var( 'p' ); 99 100 if ( is_feed() && $id ) { 101 $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) ); 102 $post_id = get_query_var( 'p' ); 103 104 if ( is_feed() && $post_id ) { 105 $redirect_url = get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) ); 106 102 107 if ( $redirect_url ) { 103 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed' ), $redirect_url ); 104 $redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH ); 105 } 106 } 107 108 if ( is_singular() && 1 > $wp_query->post_count && $id ) { 109 110 $vars = $wpdb->get_results( $wpdb->prepare( "SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id ) ); 108 $redirect['query'] = _remove_qs_args_if_not_in_url( 109 $redirect['query'], 110 array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed' ), 111 $redirect_url 112 ); 113 114 $redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH ); 115 } 116 } 117 118 if ( is_singular() && $wp_query->post_count < 1 && $post_id ) { 119 120 $vars = $wpdb->get_results( $wpdb->prepare( "SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $post_id ) ); 111 121 112 122 if ( ! empty( $vars[0] ) ) { 113 123 $vars = $vars[0]; 114 if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) { 115 $id = $vars->post_parent; 116 } 117 118 $redirect_url = get_permalink( $id ); 124 125 if ( 'revision' === $vars->post_type && $vars->post_parent > 0 ) { 126 $post_id = $vars->post_parent; 127 } 128 129 $redirect_url = get_permalink( $post_id ); 130 119 131 if ( $redirect_url ) { 120 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); 132 $redirect['query'] = _remove_qs_args_if_not_in_url( 133 $redirect['query'], 134 array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), 135 $redirect_url 136 ); 121 137 } 122 138 } … … 127 143 128 144 // Redirect ?page_id, ?p=, ?attachment_id= to their respective URLs. 129 $id = max( get_query_var( 'p' ), get_query_var( 'page_id' ), get_query_var( 'attachment_id' ) ); 130 $redirect_post = $id ? get_post( $id ) : false; 145 $post_id = max( get_query_var( 'p' ), get_query_var( 'page_id' ), get_query_var( 'attachment_id' ) ); 146 147 $redirect_post = $post_id ? get_post( $post_id ) : false; 148 131 149 if ( $redirect_post ) { 132 150 $post_type_obj = get_post_type_object( $redirect_post->post_type ); 133 if ( $post_type_obj->public && 'auto-draft' != $redirect_post->post_status ) { 134 $redirect_url = get_permalink( $redirect_post ); 135 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); 136 } 137 } 138 139 if ( get_query_var( 'day' ) && get_query_var( 'monthnum' ) && get_query_var( 'year' ) ) { 140 $year = get_query_var( 'year' ); 141 $month = get_query_var( 'monthnum' ); 142 $day = get_query_var( 'day' ); 143 $date = sprintf( '%04d-%02d-%02d', $year, $month, $day ); 151 152 if ( $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) { 153 $redirect_url = get_permalink( $redirect_post ); 154 155 $redirect['query'] = _remove_qs_args_if_not_in_url( 156 $redirect['query'], 157 array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), 158 $redirect_url 159 ); 160 } 161 } 162 163 $year = get_query_var( 'year' ); 164 $month = get_query_var( 'monthnum' ); 165 $day = get_query_var( 'day' ); 166 167 if ( $year && $month && $day ) { 168 $date = sprintf( '%04d-%02d-%02d', $year, $month, $day ); 169 144 170 if ( ! wp_checkdate( $month, $day, $year, $date ) ) { 145 $redirect_url = get_month_link( $year, $month ); 146 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum', 'day' ), $redirect_url ); 147 } 148 } elseif ( get_query_var( 'monthnum' ) && get_query_var( 'year' ) && 12 < get_query_var( 'monthnum' ) ) { 149 $redirect_url = get_year_link( get_query_var( 'year' ) ); 150 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url ); 171 $redirect_url = get_month_link( $year, $month ); 172 173 $redirect['query'] = _remove_qs_args_if_not_in_url( 174 $redirect['query'], 175 array( 'year', 'monthnum', 'day' ), 176 $redirect_url 177 ); 178 } 179 } elseif ( $year && $month && $month > 12 ) { 180 $redirect_url = get_year_link( $year ); 181 182 $redirect['query'] = _remove_qs_args_if_not_in_url( 183 $redirect['query'], 184 array( 'year', 'monthnum' ), 185 $redirect_url 186 ); 151 187 } 152 188 153 189 if ( ! $redirect_url ) { 154 190 $redirect_url = redirect_guess_404_permalink(); 191 155 192 if ( $redirect_url ) { 156 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); 157 } 158 } 159 193 $redirect['query'] = _remove_qs_args_if_not_in_url( 194 $redirect['query'], 195 array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), 196 $redirect_url 197 ); 198 } 199 } 200 201 // Strip off non-existing page links from single posts or pages. 160 202 if ( get_query_var( 'page' ) && $wp_query->post ) { 161 203 $redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' ); 162 204 $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); 163 $redirect_url = get_permalink( $wp_query->post->ID ); 205 206 $redirect_url = get_permalink( $wp_query->post->ID ); 164 207 } 165 208 } elseif ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) { 209 166 210 // Rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101. 167 if ( is_attachment() && 168 ! array_diff( array_keys( $wp->query_vars ), array( 'attachment', 'attachment_id' ) ) && 169 ! $redirect_url ) { 211 if ( is_attachment() 212 && ! array_diff( array_keys( $wp->query_vars ), array( 'attachment', 'attachment_id' ) ) 213 && ! $redirect_url 214 ) { 170 215 if ( ! empty( $_GET['attachment_id'] ) ) { 171 216 $redirect_url = get_attachment_link( get_query_var( 'attachment_id' ) ); 217 172 218 if ( $redirect_url ) { 173 219 $redirect['query'] = remove_query_arg( 'attachment_id', $redirect['query'] ); … … 178 224 } elseif ( is_single() && ! empty( $_GET['p'] ) && ! $redirect_url ) { 179 225 $redirect_url = get_permalink( get_query_var( 'p' ) ); 226 180 227 if ( $redirect_url ) { 181 228 $redirect['query'] = remove_query_arg( array( 'p', 'post_type' ), $redirect['query'] ); … … 183 230 } elseif ( is_single() && ! empty( $_GET['name'] ) && ! $redirect_url ) { 184 231 $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); 232 185 233 if ( $redirect_url ) { 186 234 $redirect['query'] = remove_query_arg( 'name', $redirect['query'] ); … … 188 236 } elseif ( is_page() && ! empty( $_GET['page_id'] ) && ! $redirect_url ) { 189 237 $redirect_url = get_permalink( get_query_var( 'page_id' ) ); 238 190 239 if ( $redirect_url ) { 191 240 $redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] ); 192 241 } 193 } elseif ( is_page() && ! is_feed() && 'page' == get_option( 'show_on_front' ) && get_queried_object_id() == get_option( 'page_on_front' ) && ! $redirect_url ) { 242 } elseif ( is_page() && ! is_feed() && ! $redirect_url 243 && 'page' === get_option( 'show_on_front' ) && get_queried_object_id() === (int) get_option( 'page_on_front' ) 244 ) { 194 245 $redirect_url = home_url( '/' ); 195 } elseif ( is_home() && ! empty( $_GET['page_id'] ) && 'page' == get_option( 'show_on_front' ) && get_query_var( 'page_id' ) == get_option( 'page_for_posts' ) && ! $redirect_url ) { 246 } elseif ( is_home() && ! empty( $_GET['page_id'] ) && ! $redirect_url 247 && 'page' === get_option( 'show_on_front' ) && get_query_var( 'page_id' ) === (int) get_option( 'page_for_posts' ) 248 ) { 196 249 $redirect_url = get_permalink( get_option( 'page_for_posts' ) ); 250 197 251 if ( $redirect_url ) { 198 252 $redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] ); … … 200 254 } elseif ( ! empty( $_GET['m'] ) && ( is_year() || is_month() || is_day() ) ) { 201 255 $m = get_query_var( 'm' ); 256 202 257 switch ( strlen( $m ) ) { 203 258 case 4: // Yearly. … … 211 266 break; 212 267 } 268 213 269 if ( $redirect_url ) { 214 270 $redirect['query'] = remove_query_arg( 'm', $redirect['query'] ); 215 271 } 216 272 // Now moving on to non ?m=X year/month/day links. 217 } elseif ( is_day() && get_query_var( 'year' ) && get_query_var( 'monthnum' ) && ! empty( $_GET['day'] ) ) { 218 $redirect_url = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) ); 219 if ( $redirect_url ) { 220 $redirect['query'] = remove_query_arg( array( 'year', 'monthnum', 'day' ), $redirect['query'] ); 221 } 222 } elseif ( is_month() && get_query_var( 'year' ) && ! empty( $_GET['monthnum'] ) ) { 223 $redirect_url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ); 224 if ( $redirect_url ) { 225 $redirect['query'] = remove_query_arg( array( 'year', 'monthnum' ), $redirect['query'] ); 226 } 227 } elseif ( is_year() && ! empty( $_GET['year'] ) ) { 228 $redirect_url = get_year_link( get_query_var( 'year' ) ); 229 if ( $redirect_url ) { 230 $redirect['query'] = remove_query_arg( 'year', $redirect['query'] ); 273 } elseif ( is_date() ) { 274 $year = get_query_var( 'year' ); 275 $month = get_query_var( 'monthnum' ); 276 $day = get_query_var( 'day' ); 277 278 if ( is_day() && $year && $month && ! empty( $_GET['day'] ) ) { 279 $redirect_url = get_day_link( $year, $month, $day ); 280 281 if ( $redirect_url ) { 282 $redirect['query'] = remove_query_arg( array( 'year', 'monthnum', 'day' ), $redirect['query'] ); 283 } 284 } elseif ( is_month() && $year && ! empty( $_GET['monthnum'] ) ) { 285 $redirect_url = get_month_link( $year, $month ); 286 287 if ( $redirect_url ) { 288 $redirect['query'] = remove_query_arg( array( 'year', 'monthnum' ), $redirect['query'] ); 289 } 290 } elseif ( is_year() && ! empty( $_GET['year'] ) ) { 291 $redirect_url = get_year_link( $year ); 292 293 if ( $redirect_url ) { 294 $redirect['query'] = remove_query_arg( 'year', $redirect['query'] ); 295 } 231 296 } 232 297 } elseif ( is_author() && ! empty( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { 233 298 $author = get_userdata( get_query_var( 'author' ) ); 234 if ( ( false !== $author ) && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) ) { 299 300 if ( false !== $author 301 && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) 302 ) { 235 303 $redirect_url = get_author_posts_url( $author->ID, $author->user_nicename ); 304 236 305 if ( $redirect_url ) { 237 306 $redirect['query'] = remove_query_arg( 'author', $redirect['query'] ); … … 239 308 } 240 309 } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (tags/categories). 241 242 310 $term_count = 0; 311 243 312 foreach ( $wp_query->tax_query->queried_terms as $tax_query ) { 244 313 $term_count += count( $tax_query['terms'] ); … … 246 315 247 316 $obj = $wp_query->get_queried_object(); 317 248 318 if ( $term_count <= 1 && ! empty( $obj->term_id ) ) { 249 319 $tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy ); 320 250 321 if ( $tax_url && ! is_wp_error( $tax_url ) ) { 251 322 if ( ! empty( $redirect['query'] ) ) { 252 323 // Strip taxonomy query vars off the URL. 253 324 $qv_remove = array( 'term', 'taxonomy' ); 325 254 326 if ( is_category() ) { 255 327 $qv_remove[] = 'category_name'; … … 275 347 // Create the destination URL for this taxonomy. 276 348 $tax_url = parse_url( $tax_url ); 349 277 350 if ( ! empty( $tax_url['query'] ) ) { 278 351 // Taxonomy accessible via ?taxonomy=...&term=... or any custom query var. … … 295 368 } 296 369 } elseif ( is_single() && strpos( $wp_rewrite->permalink_structure, '%category%' ) !== false ) { 297 $cat = get_query_var( 'category_name' ); 298 if ( $cat ) { 299 $category = get_category_by_path( $cat ); 300 if ( ( ! $category || is_wp_error( $category ) ) || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() ) ) { 370 $category_name = get_query_var( 'category_name' ); 371 372 if ( $category_name ) { 373 $category = get_category_by_path( $category_name ); 374 375 if ( ! $category || is_wp_error( $category ) 376 || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() ) 377 ) { 301 378 $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); 302 379 } … … 304 381 } 305 382 306 383 // Post paging. 307 384 if ( is_singular() && get_query_var( 'page' ) ) { 385 $page = get_query_var( 'page' ); 386 308 387 if ( ! $redirect_url ) { 309 388 $redirect_url = get_permalink( get_queried_object_id() ); 310 389 } 311 390 312 $page = get_query_var( 'page' );313 391 if ( $page > 1 ) { 392 $redirect_url = trailingslashit( $redirect_url ); 393 314 394 if ( is_front_page() ) { 315 $redirect_url = trailingslashit( $redirect_url ) .user_trailingslashit( "$wp_rewrite->pagination_base/$page", 'paged' );395 $redirect_url .= user_trailingslashit( "$wp_rewrite->pagination_base/$page", 'paged' ); 316 396 } else { 317 $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( $page, 'single_paged' ); 318 } 319 } 320 $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); 321 } 322 323 // Paging and feeds. 397 $redirect_url .= user_trailingslashit( $page, 'single_paged' ); 398 } 399 } 400 401 $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); 402 } 403 404 // Paging and feeds. 324 405 if ( get_query_var( 'paged' ) || is_feed() || get_query_var( 'cpage' ) ) { 325 while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] ) ) { 326 // Strip off paging and feed. 327 $redirect['path'] = preg_replace( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path'] ); // Strip off any existing paging. 328 $redirect['path'] = preg_replace( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path'] ); // Strip off feed endings. 329 $redirect['path'] = preg_replace( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path'] ); // Strip off any existing comment paging. 330 } 331 332 $addl_path = ''; 333 if ( is_feed() && in_array( get_query_var( 'feed' ), $wp_rewrite->feeds, true ) ) { 406 $paged = get_query_var( 'paged' ); 407 $feed = get_query_var( 'feed' ); 408 $cpage = get_query_var( 'cpage' ); 409 410 while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) 411 || preg_match( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+)?$#', $redirect['path'] ) 412 || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] ) 413 ) { 414 // Strip off any existing paging. 415 $redirect['path'] = preg_replace( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path'] ); 416 // Strip off feed endings. 417 $redirect['path'] = preg_replace( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path'] ); 418 // Strip off any existing comment paging. 419 $redirect['path'] = preg_replace( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path'] ); 420 } 421 422 $addl_path = ''; 423 $default_feed = get_default_feed(); 424 425 if ( is_feed() && in_array( $feed, $wp_rewrite->feeds, true ) ) { 334 426 $addl_path = ! empty( $addl_path ) ? trailingslashit( $addl_path ) : ''; 427 335 428 if ( ! is_singular() && get_query_var( 'withcomments' ) ) { 336 429 $addl_path .= 'comments/'; 337 430 } 338 if ( ( 'rss' == get_default_feed() && 'feed' == get_query_var( 'feed' ) ) || 'rss' == get_query_var( 'feed' ) ) { 339 $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == 'rss2' ) ? '' : 'rss2' ), 'feed' ); 431 432 if ( ( 'rss' === $default_feed && 'feed' === $feed ) || 'rss' === $feed ) { 433 $format = ( 'rss2' === $default_feed ) ? '' : 'rss2'; 340 434 } else { 341 $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == get_query_var( 'feed' ) || 'feed' == get_query_var( 'feed' ) ) ? '' : get_query_var( 'feed' ) ), 'feed' ); 342 } 435 $format = ( $default_feed === $feed || 'feed' === $feed ) ? '' : $feed; 436 } 437 438 $addl_path .= user_trailingslashit( 'feed/' . $format, 'feed' ); 439 343 440 $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); 344 } elseif ( is_feed() && 'old' == get_query_var( 'feed' )) {441 } elseif ( is_feed() && 'old' === $feed ) { 345 442 $old_feed_files = array( 346 443 'wp-atom.php' => 'atom', 347 444 'wp-commentsrss2.php' => 'comments_rss2', 348 'wp-feed.php' => get_default_feed(),445 'wp-feed.php' => $default_feed, 349 446 'wp-rdf.php' => 'rdf', 350 447 'wp-rss.php' => 'rss2', 351 448 'wp-rss2.php' => 'rss2', 352 449 ); 450 353 451 if ( isset( $old_feed_files[ basename( $redirect['path'] ) ] ) ) { 354 452 $redirect_url = get_feed_link( $old_feed_files[ basename( $redirect['path'] ) ] ); 453 355 454 wp_redirect( $redirect_url, 301 ); 356 455 die(); … … 358 457 } 359 458 360 if ( get_query_var( 'paged' ) > 0 ) { 361 $paged = get_query_var( 'paged' ); 459 if ( $paged > 0 ) { 362 460 $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); 461 363 462 if ( ! is_feed() ) { 364 if ( $paged > 1 && ! is_single() ) { 365 $addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' ) . user_trailingslashit( "$wp_rewrite->pagination_base/$paged", 'paged' ); 366 } elseif ( ! is_single() ) { 463 if ( ! is_single() ) { 367 464 $addl_path = ! empty( $addl_path ) ? trailingslashit( $addl_path ) : ''; 465 466 if ( $paged > 1 ) { 467 $addl_path .= user_trailingslashit( "$wp_rewrite->pagination_base/$paged", 'paged' ); 468 } 368 469 } 369 470 } elseif ( $paged > 1 ) { … … 372 473 } 373 474 374 if ( get_option( 'page_comments' ) && ( 375 ( 'newest' == get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 0 ) || 376 ( 'newest' != get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 1 ) 377 ) ) { 378 $addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var( 'cpage' ), 'commentpaged' ); 475 $default_comments_page = get_option( 'default_comments_page' ); 476 477 if ( get_option( 'page_comments' ) 478 && ( 'newest' === $default_comments_page && $cpage > 0 479 || 'newest' !== $default_comments_page && $cpage > 1 ) 480 ) { 481 $addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' ); 482 $addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' ); 483 379 484 $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); 380 485 } 381 486 382 $redirect['path'] = user_trailingslashit( preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path'] ) ); // Strip off trailing /index.php/. 383 if ( ! empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos( $redirect['path'], '/' . $wp_rewrite->index . '/' ) === false ) { 487 // Strip off trailing /index.php/. 488 $redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path'] ); 489 $redirect['path'] = user_trailingslashit( $redirect['path'] ); 490 491 if ( ! empty( $addl_path ) 492 && $wp_rewrite->using_index_permalinks() 493 && strpos( $redirect['path'], '/' . $wp_rewrite->index . '/' ) === false 494 ) { 384 495 $redirect['path'] = trailingslashit( $redirect['path'] ) . $wp_rewrite->index . '/'; 385 496 } 497 386 498 if ( ! empty( $addl_path ) ) { 387 499 $redirect['path'] = trailingslashit( $redirect['path'] ) . $addl_path; 388 500 } 501 389 502 $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; 390 503 } 391 504 392 if ( 'wp-register.php' == basename( $redirect['path'] ) ) {505 if ( 'wp-register.php' === basename( $redirect['path'] ) ) { 393 506 if ( is_multisite() ) { 394 507 /** This filter is documented in wp-login.php */ … … 403 516 } 404 517 518 $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); 519 405 520 // Tack on any additional query vars. 406 $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );407 521 if ( $redirect_url && ! empty( $redirect['query'] ) ) { 408 522 parse_str( $redirect['query'], $_parsed_query ); … … 421 535 rawurlencode_deep( array_values( $_parsed_query ) ) 422 536 ); 423 $redirect_url = add_query_arg( $_parsed_query, $redirect_url ); 537 538 $redirect_url = add_query_arg( $_parsed_query, $redirect_url ); 424 539 } 425 540 … … 430 545 // www.example.com vs. example.com 431 546 $user_home = parse_url( home_url() ); 547 432 548 if ( ! empty( $user_home['host'] ) ) { 433 549 $redirect['host'] = $user_home['host']; 434 550 } 551 435 552 if ( empty( $user_home['path'] ) ) { 436 553 $user_home['path'] = '/'; … … 503 620 504 621 // Trailing slashes. 505 if ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() && ! is_404() && ( ! is_front_page() || ( is_front_page() && ( get_query_var( 'paged' ) > 1 ) ) ) ) { 622 if ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() 623 && ! is_404() && ( ! is_front_page() || is_front_page() && get_query_var( 'paged' ) > 1 ) 624 ) { 506 625 $user_ts_type = ''; 626 507 627 if ( get_query_var( 'paged' ) > 0 ) { 508 628 $user_ts_type = 'paged'; … … 516 636 } 517 637 } 638 518 639 $redirect['path'] = user_trailingslashit( $redirect['path'], $user_ts_type ); 519 640 } elseif ( is_front_page() ) { … … 527 648 528 649 // Always trailing slash the Front Page URL. 529 if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) {650 if ( trailingslashit( $redirect['path'] ) === trailingslashit( $user_home['path'] ) ) { 530 651 $redirect['path'] = trailingslashit( $redirect['path'] ); 531 652 } 653 654 $original_host_low = strtolower( $original['host'] ); 655 $redirect_host_low = strtolower( $redirect['host'] ); 532 656 533 657 // Ignore differences in host capitalization, as this can lead to infinite redirects. 534 658 // Only redirect no-www <=> yes-www. 535 if ( strtolower( $original['host'] ) == strtolower( $redirect['host'] ) || 536 ( strtolower( $original['host'] ) != 'www.' . strtolower( $redirect['host'] ) && 'www.' . strtolower( $original['host'] ) != strtolower( $redirect['host'] ) ) ) { 659 if ( $original_host_low === $redirect_host_low 660 || ( 'www.' . $original_host_low !== $redirect_host_low 661 && 'www.' . $redirect_host_low !== $original_host_low ) 662 ) { 537 663 $redirect['host'] = $original['host']; 538 664 } … … 560 686 if ( $compare_original !== $compare_redirect ) { 561 687 $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; 688 562 689 if ( ! empty( $redirect['port'] ) ) { 563 690 $redirect_url .= ':' . $redirect['port']; 564 691 } 692 565 693 $redirect_url .= $redirect['path']; 694 566 695 if ( ! empty( $redirect['query'] ) ) { 567 696 $redirect_url .= '?' . $redirect['query']; … … 569 698 } 570 699 571 if ( ! $redirect_url || $redirect_url == $requested_url ) {700 if ( ! $redirect_url || $redirect_url === $requested_url ) { 572 701 return; 573 702 } … … 589 718 } 590 719 } 720 591 721 $requested_url = preg_replace_callback( '|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url ); 592 722 } … … 605 735 606 736 // Yes, again -- in case the filter aborted the request. 607 if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) {737 if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) === strip_fragment_from_url( $requested_url ) ) { 608 738 return; 609 739 } … … 638 768 function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) { 639 769 $parsed_url = parse_url( $url ); 770 640 771 if ( ! empty( $parsed_url['query'] ) ) { 641 772 parse_str( $parsed_url['query'], $parsed_query ); 773 642 774 foreach ( $args_to_check as $qv ) { 643 775 if ( ! isset( $parsed_query[ $qv ] ) ) { … … 648 780 $query_string = remove_query_arg( $args_to_check, $query_string ); 649 781 } 782 650 783 return $query_string; 651 784 } … … 661 794 function strip_fragment_from_url( $url ) { 662 795 $parsed_url = parse_url( $url ); 796 663 797 if ( ! empty( $parsed_url['host'] ) ) { 664 798 // This mirrors code in redirect_canonical(). It does not handle every case. … … 712 846 } 713 847 848 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared 714 849 $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" ); 850 715 851 if ( ! $post_id ) { 716 852 return false; 717 853 } 854 718 855 if ( get_query_var( 'feed' ) ) { 719 856 return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) ); 720 } elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' )) {857 } elseif ( get_query_var( 'page' ) > 1 ) { 721 858 return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); 722 859 } else { … … 740 877 function wp_redirect_admin_locations() { 741 878 global $wp_rewrite; 879 742 880 if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) { 743 881 return; … … 751 889 site_url( 'admin', 'relative' ), 752 890 ); 891 753 892 if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins, true ) ) { 754 893 wp_redirect( admin_url() ); … … 761 900 site_url( 'login', 'relative' ), 762 901 ); 902 763 903 if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins, true ) ) { 764 904 wp_redirect( wp_login_url() );
Note: See TracChangeset
for help on using the changeset viewer.