put some conditions and redirection upon login
-
Hi,
Where is the best place to put some conditions so I can redirect people to certain pages before they land on my home page?
Thanks,
Shai
-
bumping – anyone?
Either .htaccess or if that is uncomfortable, you can use some code and checkout for referrer at any of the wordpress actions like “wp” or “init” or anything else. Check for the original referrer and then redirect if the origin is not your site.
What i want to do is something else:
for example as soon as someone logs in i want to run a query in the db to check for specific values.
if the value is X continue to home page
if the value is Y continue to a different page.where would be the best place to set this code?
There’s a few plugins that do this if you search for redirect login (or something like that).
Otherwise, you could do your own with some code like this:
function bp_redirect_to_page()
{
$redirect_url_cc = ‘URL to redirect to’;
bp_core_redirect($redirect_url_cc);}
/*Add an action to redirect user after login*/
add_action(“wp_login”,”bp_redirect_to_page”,100,0);You can add a lot more functionality to that too. I’m also playing with this redirect at registration. Very nice little function.
Cheers – I will give that a shot.
You can even pass in variables like the userid. A simple if then statement will accomplish the various redirects. That’s what I’ve done also.
@techguy
one other question – can you give me examples of where you actually used this action?ok – i think i got the idea – i will try later today and will let you know.
Thanks!Hi – doesnt seem to work for me or im doing something wrong:
here is kind of what i am doing:function bp_redirect_to_page()
{
$redirect_url_1 = ‘URL x’;
$redirect_url_2 = ‘URL y’;get some DB values from wp_bp_xprofile_data
if condition==x
bp_core_redirect($redirect_url_1);
else
bp_core_redirect($redirect_url_2);
}
/*Add an action to redirect user after login*/
add_action(“wp_login”,”bp_redirect_to_page”,100,0);this doesnt seem to change anything.
any other tips or why this is not working?i even tried sticking one of the redirects at the beginning of the function but it still takes me to the same (home) page.
how do I make sure this function is actually running during login?
also where should i put it? i put it under bp-custom.php = should it be in a different file?ok – i was able to get this to work but encountering another issue.
my redirect url is built as follows: $user_domain = $bp->loggedin_user->domain . “profile/edit”;
for some reason the redirection is made to the home page url with the addition of “profile/edit” not actually putting the user domain infront of it in the string and then i get page not found.
any idea why its not giving me the user domain?Thanks,
Shai
@techguy or anyone else – any idea here?
I forgot, you could just change the filter login_redirect(). Although, you can’t do the same processing with that one as you can with the one I show above.
Have you tried dumping the $bp variable to see that $bp->loggedin_user->domain is available at that point in time?
You can also do the following to see if the URL that you’re storing in $user_domain is being created correctly:
echo ‘URL for Redirect: ‘ . $user_domain;
die;Run the script and this will display that variable and then stop anything else from running so you can see that variable.
- The topic ‘put some conditions and redirection upon login’ is closed to new replies.