Hooks::filter_redirect_canonical( mixed $redirect_url = null, string|int $original_url = null )
Filters the redirect_canonical to prevent any redirects on embed URLs.
Contents
Parameters
- $redirect_url
-
(mixed) (Optional) URL which we will redirect to.
Default value: null
- $original_url
-
(string|int) (Optional) The original URL if this method runs on the
redirect_canonicalfilter, else the redirect status (e.g.301) if this method runs in the context of thewp_redirectfilter.Default value: null
Return
(string) A redirection URL, or false to prevent redirection.
Source
File: src/Tribe/Views/V2/Hooks.php
public function filter_redirect_canonical( $redirect_url = null, $original_url = null ) {
if ( trailingslashit( $original_url ) === trailingslashit( $redirect_url ) ) {
return $redirect_url;
}
$context = tribe_context();
$view = $context->get( 'view_request', null );
if ( 'embed' === $view ) {
// Do not redirect embedded Views.
return false;
}
if ( empty( $view ) || 'single-event' === $view ) {
// Let the redirection go on.
return $redirect_url;
}
$parsed = \Tribe__Events__Rewrite::instance()->parse_request( $redirect_url );
if (
empty( $parsed['tribe_redirected'] )
&& $view !== Arr::get( (array) $parsed, 'eventDisplay' )
) {
/*
* If we're here we know we should be looking at a View URL.
* If the proposed URL does not resolve to a View, do not redirect.
*/
return false;
}
return $redirect_url;
}
Changelog
| Version | Description |
|---|---|
| 4.9.13 | Introduced. |