Hey Sascha! What’s the error that you’re seeing? We use the normal login logic so login redirection should work as-is.
When I use the standard wordpress redirection filter:
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function my_login_redirect( $redirect_to, $request, $user ) {
//$request = $_SERVER['REQUEST_URI'];
$redirect_to = $request;
return $redirect_to;
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
I get the following error in Clef:
Error retrieving Clef access token: Invalid OAuth Code.
This is what the filter get’s passed as information from Clef:
`http://landwire.dev:8888/wp-login.php?clef=true&code=7c8a09bba*** –> http://landwire.dev:8888/wp-admin/
Redirect To http://landwire.dev:8888/wp-admin/
Request /wp-login.php?clef=true&code=7c8a09bba***
User Object {:WP_User: Object}`
So obviously it does not have the correct Request page. No idea if there is a filter I can run after Clef has done it’s authorisation and redirect then.
Thanks,
Sascha
Have you tried using the referrer instead of the REQUEST_URI?
Not sure what you mean. But if you look in the above code, I tried $request pure (as supplied by the filter and after I have set it to $request = $_SERVER[‘REQUEST_URI’];
Both failed to redirect or even log in.
These are the content of the variables:
Redirect To http://landwire.dev:8888/wp-admin/
original request
Request URI /wp-login.php?clef=true&code=5fff8d005769a2ba318d77e04a61d4db
User Object
As you see the original $request is empty and the Request URI has the clef stuff in it, which it obviously needs/uses to authorize login. Crucial question is, is there a login/logout redirect filter in Clef, once it has done it’s authorization? Or is there a way to get to the Request URI before Clef modifies this to wp-login.php?clef=true&……?
When I use the empty $request as the return value, I just get a blank screen…
Best to setup a redirect filter yourself, then you can troubleshoot it easier and see what I mean.
S
What about something like:
function my_login_redirect( $redirect_to, $request, $user ) {
//$request = $_SERVER['REQUEST_URI'];
return wp_get_referer();
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
Hi Jesse,
great, that works like a treat!
Same goes for logout redirect. Just used the wp_get_referer() there too and works fine.
Thank you. I did not know wp_get_referer() yet.
S
No problem — I’m here to help!