Function
Filter the site URL.
tml_filter_site_url( string $url, string $path, string $scheme )
Parameters
-
$urlstring - The URL.
-
$pathstring - The path.
-
$schemestring - The URL scheme.
Return
string
The filtered URL.
Source
function tml_filter_site_url( $url, $path, $scheme ) {
global $pagenow;
// Bail if currently visiting wp-login.php
if ( 'wp-login.php' === $pagenow ) {
return $url;
}
// Bail if currently customizing
if ( is_customize_preview() ) {
return $url;
}
// Parse the URL
$parsed_url = wp_parse_url( $url );
// Determine the path
$path = '';
if ( ! empty( $parsed_url['path'] ) ) {
$path = basename( trim( $parsed_url['path'], '/' ) );
}
// Parse the query
$query = array();
if ( ! empty( $parsed_url['query'] ) ) {
parse_str( $parsed_url['query'], $query );
// Encode the query args
$query = tml_array_map_recursive( 'rawurlencode', $query );
}
/**
* Bail if the URL is an interim-login URL
*
* @see https://core.trac.wordpress.org/ticket/31821
*/
if ( isset( $query['interim-login'] ) ) {
return $url;
}
// Determine the action
switch ( $path ) {
case 'wp-login.php':
// Determine the action
$action = isset( $query['action'] ) ? $query['action'] : 'login';
// Fix some alias actions
if ( 'retrievepassword' === $action ) {
$action = 'lostpassword';
} elseif ( 'rp' === $action ) {
$action = 'resetpass';
}
// Unset the action
unset( $query['action'] );
break;
case 'wp-signup.php':
$action = 'signup';
break;
case 'wp-activate.php':
$action = 'activate';
break;
default:
return $url;
}
// Bail if not a TML action
if ( ! tml_action_exists( $action ) ) {
return $url;
}
// Get the URL
$is_network = ( 'network_site_url' === current_filter() );
$url = tml_get_action_url( $action, $scheme, $is_network );
// Add the query
$url = add_query_arg( $query, $url );
return $url;
}
Uses
See also
Changelog
| Version | Description |
|---|---|
| 7.0 | Introduced. |