Skip to:
Content
Pages
Categories
Search
Top
Bottom

here’s a trick to redirect user back to topic after login


  • _ck_
    Participant

    @_ck_

    I had not seen this posted before and I just (finally) figured it out so I thought I’d share.

    If you’d like to give the user a friendly redirect back to the topic (or forum) they were at just before they logged in (instead of the front page) simply open the login-form.php template in your theme and add this BEFORE the final </form>

    <input type="hidden" name="re" value="<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"].'?'.$_SERVER["QUERY_STRING"]; ?>" />
    <input type="hidden" name="_wp_http_referer" value="<?php echo bb_get_option( 'uri' ) ?>" />

    Should work on anything except maybe IIS.

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

  • HowToGeek
    Member

    @howtogeek

    Very nice… that was on my todo list to figure out.

    You rule. As usual.


    _ck_
    Participant

    @_ck_

    I should note that mdawaffe has pointed out to me that apparently bbPress would do this previously if the user has referer’s enabled in their browser. But since most “personal firewalls” block referers by default, you can’t count on that behavior and this change will make it always work instead.

    0.8.4 will supposedly have this new ability by default…


    HowToGeek
    Member

    @howtogeek

    For my site, I’m using the bbpress login as the site-wide login… so when I put a login link on the wordpress side of the site the user would be redirected to the forum every time after login… kinda annoying.

    With this new knowledge I should be able to fix it so they are redirected back, even to a non-bbpress page.


    Andy Warburton
    Member

    @hellweaver666

    Works a charm – thanks _ck_


    robinson_c
    Member

    @robinson_c

    Thank you so much. :) It worked !

    :P


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    A few things. First, this won’t work in bbPress 2. It’s already done for you, and the function names are different. Also, it’s a bad idea to trust any global value to be output directly to the screen, as any plugin can manipulate them directly. You’ll want to wrap that output in an esc_url() call. Lastly, this post is almost 4 years old; bumping it with a simple ‘thanks’ type reeks of being spam.

    Closing this so it doesn’t get bumped again, and anyone that finds this should take heed using that code in bbPress or WordPress going forward, as there are more elegant solutions.

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

The topic ‘here’s a trick to redirect user back to topic after login’ is closed to new replies.