WordPress.org

Make WordPress Core

Changeset 34272


Ignore:
Timestamp:
09/17/2015 09:31:21 PM (4 years ago)
Author:
wonderboymusic
Message:

Canonical: redirect URLs that match an attachment masked on the wrong URL to the attachment link for the matched attachment.

Props solarissmoke.
Fixes #19918.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r34213 r34272  
    151151    } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
    152152        // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
    153         if ( is_attachment() && !empty($_GET['attachment_id']) && ! $redirect_url ) {
    154             if ( $redirect_url = get_attachment_link(get_query_var('attachment_id')) )
    155                 $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']);
     153        if ( is_attachment() && ! $redirect_url ) {
     154            if ( ! empty( $_GET['attachment_id'] ) ) {
     155                $redirect_url = get_attachment_link( get_query_var( 'attachment_id' ) );
     156                if ( $redirect_url ) {
     157                    $redirect['query'] = remove_query_arg( 'attachment_id', $redirect['query'] );
     158                }
     159            } else {
     160                $redirect_url = get_attachment_link();
     161            }
    156162        } elseif ( is_single() && !empty($_GET['p']) && ! $redirect_url ) {
    157163            if ( $redirect_url = get_permalink(get_query_var('p')) )
Note: See TracChangeset for help on using the changeset viewer.