I've been asked to implement a custom redirection in WordPress. It seemed quite simple at first but I have no idea how to get it right. So much that I can't even get started with it. This is how it should go:
- The user logs in, and the database gets queried using the
wp_login
hook - If a certain condition is met, the user gets logged out using
wp_logout()
from the wp_login hook - This is where the problem comes in, the user should get redirected to a page dedicated to them, without breaking the normal logout function
So if the user logs out normally, they get redirected to the default page, however if the condition is met they get redirected to another page and still get logged out.
I've tried the wp_logout
and wp_clear_auth_cookie
hooks, but to no avail.
I can't really show you any code, as I did not manage to come up with anything concrete.
edit:
....
//in the login hook
if($condition)
wp_logout();
...
add_action("wp_login","login_hook",10,2);
//below the login hook
function logout(){
if($condition){
wp_redirect(home_url("/redirectTo"));
exit;
}
}
add_action("wp_logout","logout");
if($condition) { header("Location: /page"); }
to thewp_logout
hook. The action to hook off is on line 603 ofpluggable.php
according to the codex link. add_action( $hook, $function_to_add, $priority, $accepted_args );$function_to_add
will be the one working out the condition to generate theheader
parameter? Thinking out loud!