| | 377 | /* |
| | 378 | * Enhancement: Support redirecting query vars like ?pagename=blog, |
| | 379 | * ?author_name=admin, and ?post_format=image to their canonical permalink forms. |
| | 380 | */ |
| | 381 | |
| | 382 | if ( isset( $_GET['pagename'] ) && ! empty( $_GET['pagename'] ) ) { |
| | 383 | $page = get_page_by_path( sanitize_title( $_GET['pagename'] ) ); |
| | 384 | if ( $page && ! is_wp_error( $page ) ) { |
| | 385 | $redirect_url = get_permalink( $page->ID ); |
| | 386 | if ( $redirect_url && $redirect_url !== $requested_url ) { |
| | 387 | wp_redirect( $redirect_url, 301 ); |
| | 388 | exit; |
| | 389 | } |
| | 390 | } |
| | 391 | } |
| | 392 | |
| | 393 | if ( isset( $_GET['author_name'] ) && ! empty( $_GET['author_name'] ) ) { |
| | 394 | $user = get_user_by( 'slug', sanitize_title( $_GET['author_name'] ) ); |
| | 395 | if ( $user && ! is_wp_error( $user ) ) { |
| | 396 | $redirect_url = get_author_posts_url( $user->ID ); |
| | 397 | if ( $redirect_url && $redirect_url !== $requested_url ) { |
| | 398 | wp_redirect( $redirect_url, 301 ); |
| | 399 | exit; |
| | 400 | } |
| | 401 | } |
| | 402 | } |
| | 403 | |
| | 404 | if ( isset( $_GET['post_format'] ) && ! empty( $_GET['post_format'] ) ) { |
| | 405 | $term = get_term_by( 'slug', sanitize_title( $_GET['post_format'] ), 'post_format' ); |
| | 406 | if ( $term && ! is_wp_error( $term ) ) { |
| | 407 | $redirect_url = get_term_link( $term ); |
| | 408 | if ( $redirect_url && $redirect_url !== $requested_url ) { |
| | 409 | wp_redirect( $redirect_url, 301 ); |
| | 410 | exit; |
| | 411 | } |
| | 412 | } |
| | 413 | } |
| | 414 | |