A bit crude but...
function returning_redirect($a) {
remove_action('auth_cookie_valid', 'returning_redirect');
if (is_user_logged_in()) {
if (parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) !== parse_url(site_url(), PHP_URL_HOST)) {
wp_redirect(site_url('page'));
exit;
}
}
add_action('auth_cookie_valid', 'returning_redirect');
}
add_action('auth_cookie_valid', 'returning_redirect');
You are checking the HTTP_REQUEST
header for a match against the server host name.
Caveats:
- That will not work on a server with multiple sub-directory installs
like
http://site.com/wordpress
and http://site.com/wordpress2
because that will only check the site.com
part. If that is your
circumstance you will need something more complicated.
$_SERVER['HTTP_REFERER']
is easily spoofed, but if there are no
security issues that should be no problem.
- I expect that this is is going to be an annoying feature of your
site.