Reputation: 306
I am writing a plugin that will redirect the user after logout. If the user provides a link then redirect the user to that place else use the default URL. Here is the code I use.
echo esc_url(wp_logout_url( ud_logout_redirect() ));
Here is the ud_logout_redirect() function.
function ud_logout_redirect() {
$redirect_link = '';
$logoutOption = isset( ud_redirection_options()['logout_link_redirect'] ) ? ud_redirection_options()['logout_link_redirect'] : null;
if ( ! $logoutOption == null ) {
$redirect_link = apply_filters( 'filter_ud_logout_redirect', $logoutOption);
}
return $redirect_link;
}
If the user doesn't provide a link the example.com
will be default but the wp_logout_url()
doesn't redirect the user. But it redirects the user to wp-login.php
Thanks in advance
Upvotes: 0
Views: 679
Reputation: 309
If you want to redirect another site, you have to add that domain in allowed_redirect_hosts
filter. Try this:
add_filter( 'allowed_redirect_hosts', 'ud_logout_redirect' );
function ud_logout_redirect( $allowed ) {
$allowed[] = 'multisiteparent.com';
return $allowed;
}
<a href="<?php echo wp_logout_url( 'http://multisiteparent.com' ); ?>">Logout</a>
To know more check this: https://developer.wordpress.org/reference/functions/wp_logout_url/
Upvotes: 1