Make WordPress Core

Changeset 35770


Ignore:
Timestamp:
12/04/2015 11:10:09 PM (9 years ago)
Author:
wonderboymusic
Message:

Canonical: introduce strip_fragment_from_url() and use when comparing URLs in redirect_canonical().

Props tellyworth.
Fixes #19918.

File:
1 edited

Legend:

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

    r35480 r35770  
    490490
    491491    // yes, again -- in case the filter aborted the request
    492     if ( ! $redirect_url || $redirect_url == $requested_url ) {
     492    if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) {
    493493        return;
    494494    }
     
    536536
    537537/**
     538 * Strips the #fragment from a URL, if one is present.
     539 *
     540 * @since 4.4.0
     541 *
     542 * @param string $url The URL to strip.
     543 * @return string The altered URL.
     544 */
     545function strip_fragment_from_url( $url ) {
     546    $parsed_url = @parse_url( $url );
     547    if ( ! empty( $parsed_url['host'] ) ) {
     548        // This mirrors code in redirect_canonical(). It does not handle every case.
     549        $url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
     550        if ( ! empty( $parsed_url['port'] ) ) {
     551            $url .= ':' . $parsed_url['port'];
     552        }
     553        $url .= $parsed_url['path'];
     554        if ( ! empty( $parsed_url['query'] ) ) {
     555            $url .= '?' . $parsed_url['query'];
     556        }
     557    }
     558
     559    return $url;
     560}
     561
     562/**
    538563 * Attempts to guess the correct URL based on query vars
    539564 *
Note: See TracChangeset for help on using the changeset viewer.