Skip to:
Content
Pages
Categories
Search
Top
Bottom

put some conditions and redirection upon login


  • shaisimchi
    Participant

    @shaisimchi

    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

Viewing 13 replies - 1 through 13 (of 13 total)

  • shaisimchi
    Participant

    @shaisimchi

    bumping – anyone?


    Brajesh Singh
    Participant

    @sbrajesh

    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.


    shaisimchi
    Participant

    @shaisimchi

    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?


    techguy
    Participant

    @crashutah

    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.


    shaisimchi
    Participant

    @shaisimchi

    Cheers – I will give that a shot.


    techguy
    Participant

    @crashutah

    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.


    shaisimchi
    Participant

    @shaisimchi

    @techguy
    one other question – can you give me examples of where you actually used this action?


    shaisimchi
    Participant

    @shaisimchi

    ok – i think i got the idea – i will try later today and will let you know.
    Thanks!


    shaisimchi
    Participant

    @shaisimchi

    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?


    shaisimchi
    Participant

    @shaisimchi

    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?


    shaisimchi
    Participant

    @shaisimchi

    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


    shaisimchi
    Participant

    @shaisimchi

    @techguy or anyone else – any idea here?


    techguy
    Participant

    @crashutah

    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.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘put some conditions and redirection upon login’ is closed to new replies.
Skip to toolbar