Canonical: introduce strip_fragment_from_url()
and use when comparing URLs in redirect_canonical()
.
Props tellyworth. Fixes #19918. git-svn-id: https://develop.svn.wordpress.org/trunk@35770 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
db281bf80e
commit
12f4c30551
@ -489,7 +489,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
|
||||
$redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url );
|
||||
|
||||
// yes, again -- in case the filter aborted the request
|
||||
if ( ! $redirect_url || $redirect_url == $requested_url ) {
|
||||
if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -534,6 +534,31 @@ function _remove_qs_args_if_not_in_url( $query_string, Array $args_to_check, $ur
|
||||
return $query_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the #fragment from a URL, if one is present.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $url The URL to strip.
|
||||
* @return string The altered URL.
|
||||
*/
|
||||
function strip_fragment_from_url( $url ) {
|
||||
$parsed_url = @parse_url( $url );
|
||||
if ( ! empty( $parsed_url['host'] ) ) {
|
||||
// This mirrors code in redirect_canonical(). It does not handle every case.
|
||||
$url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
|
||||
if ( ! empty( $parsed_url['port'] ) ) {
|
||||
$url .= ':' . $parsed_url['port'];
|
||||
}
|
||||
$url .= $parsed_url['path'];
|
||||
if ( ! empty( $parsed_url['query'] ) ) {
|
||||
$url .= '?' . $parsed_url['query'];
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to guess the correct URL based on query vars
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user