Rewrite: Redirect attachment URLs when their slug changes.

Using the same logic that we use to redirect posts when their slug changes, we can provide the same functionality for attachments. Attachment pages are posts, too.

Props swissspdy.

Fixes #34043.



git-svn-id: https://develop.svn.wordpress.org/trunk@34685 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2015-09-29 04:57:02 +00:00
parent 0ab0525691
commit 070b65dcfc
4 changed files with 48 additions and 15 deletions

View File

@@ -4736,12 +4736,15 @@ function wp_old_slug_redirect() {
global $wpdb;
// Guess the current post_type based on the query vars.
if ( get_query_var('post_type') )
$post_type = get_query_var('post_type');
elseif ( !empty($wp_query->query_vars['pagename']) )
if ( get_query_var( 'post_type' ) ) {
$post_type = get_query_var( 'post_type' );
} elseif ( get_query_var( 'attachment' ) ) {
$post_type = 'attachment';
} elseif ( ! empty( $wp_query->query_vars['pagename'] ) ) {
$post_type = 'page';
else
} else {
$post_type = 'post';
}
if ( is_array( $post_type ) ) {
if ( count( $post_type ) > 1 )