From c2e1bab509dbc07a55c58ffee225c227c3b5185a Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 17 Sep 2015 21:32:24 +0000 Subject: [PATCH] Canonical: redirect URLs that match an attachment masked on the wrong URL to the attachment link for the matched attachment. Props solarissmoke. Fixes #19918. Built from https://develop.svn.wordpress.org/trunk@34272 git-svn-id: http://core.svn.wordpress.org/trunk@34236 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 12 +++++++++--- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 4c981f9a38..0818124973 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -150,9 +150,15 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 - if ( is_attachment() && !empty($_GET['attachment_id']) && ! $redirect_url ) { - if ( $redirect_url = get_attachment_link(get_query_var('attachment_id')) ) - $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']); + if ( is_attachment() && ! $redirect_url ) { + if ( ! empty( $_GET['attachment_id'] ) ) { + $redirect_url = get_attachment_link( get_query_var( 'attachment_id' ) ); + if ( $redirect_url ) { + $redirect['query'] = remove_query_arg( 'attachment_id', $redirect['query'] ); + } + } else { + $redirect_url = get_attachment_link(); + } } elseif ( is_single() && !empty($_GET['p']) && ! $redirect_url ) { if ( $redirect_url = get_permalink(get_query_var('p')) ) $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); diff --git a/wp-includes/version.php b/wp-includes/version.php index 7573c6503c..89d8f5ff12 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34271'; +$wp_version = '4.4-alpha-34272'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.