• Using theme my login plugin i have put passowrd at during the registration. I want that after a user registers he automatically login and he should be redirected to profile page.

Viewing 15 replies - 16 through 30 (of 43 total)
  • <?php
    function tml_new_user_registered( $user_id ) {
        wp_set_auth_cookie( $user_id, false, is_ssl() );
        wp_redirect( wp_get_referer() );
        exit;
    }
    add_action( 'tml_new_user_registered', 'tml_new_user_registered' );
    ?>

    Hmm.. this doesn’t work. Instead of logging the user in and redirecting to the referrer, it brings the user to the Log In page after registering. Then when the user logs in with the new credentials, it redirects them to the registration page again– in a seemingly infinite loop.

    If I were registering a user by directing them to: /login/?action=register.. would it be possible to redirect a user after registration by passing a variable to the registration page? i.e. /login/?action=register?referrer=/path/to/referrer/page ?

    Thank’s for your help

    You will need to post _wp_original_http_referer with the registration form.

    You can use wp_original_referer_field().

    Alright, got it working. Here’s how, for anyone interested:

    File theme-my-login-custom.php in the /plugins/ directory (not in /plugins/theme-my-login), with the following code:

    <?php
    function tml_new_user_registered( $user_id ) {
        wp_set_auth_cookie( $user_id, false, is_ssl() );
        wp_redirect( wp_get_referer() );
        exit;
    }
    add_action( 'tml_new_user_registered', 'tml_new_user_registered' );
    ?>

    In the theme’s functions.php:

    function show_first_name_field(){
    ?>
    <input type="hidden" value="' . wp_specialchars(stripslashes($_SERVER['REQUEST_URI'])) . '" name="_wp_original_http_referer"/>
    <?php
    }

    After registering, a user is now automatically logged in and redirected back to the page they clicked “register” from.

    Thanks for your help, Jeff

    A simpler method:

    <?php
    function tml_new_user_registered( $user_id ) {
    	wp_set_auth_cookie( $user_id, false, is_ssl() );
    	wp_redirect( wp_get_referer() );
    	exit;
    }
    add_action( 'tml_new_user_registered', 'tml_new_user_registered' );
    
    function tml_register_form() {
    	wp_original_referer_field( true, 'previous' );
    }
    add_action( 'register_form', 'tml_register_form' );
    ?>

    Hi
    Theme My Login is what i was looking for, brilliant plugin, i am testing the code you provide above but some reason i can’t get it to work properly,
    i am using the tml widget and after hitting the submit button for new register the new user get redirected all right to the refered page but the widget form doesn’t change, it keeps the register form on the refered page instead of the welcome user logged in form. Any ideas about this issue?

    your help is greatly appreciated.

    sorry that i can’t provide my url as i am working on my local server.

    anyone?

    If you refresh it, does it display properly?

    Hello Jeff

    nope, thank you for repling, the weird thing is i get a welcome message so register is successful but the form still doesn’t change and you can see i got two repeated links after the submit button.

    now my site is live:
    http://www.lagofutbol.com

    xavi

    I see now. This is because the referer is passing the action query argument. Try this:

    <?php
    function tml_new_user_registered( $user_id ) {
    	wp_set_auth_cookie( $user_id, false, is_ssl() );
    	$referer = remove_query_arg( array( 'action', 'instance' ), wp_get_referer() );
    	wp_redirect( $referer );
    	exit;
    }
    add_action( 'tml_new_user_registered', 'tml_new_user_registered' );
    
    function tml_register_form() {
    	wp_original_referer_field( true, 'previous' );
    }
    add_action( 'register_form', 'tml_register_form' );
    ?>

    Jeff

    you are a genious, it works perfect, thank you very much. In my next blog i will include tml again and will spread the word about your work.

    thank you again
    xavi

    sorry just one last question, could you please give an example of how to set user notification email, i mean by using the variable %user_pass%. i am not a coder. thank you

    I’m not sure what you mean…

    well, i enabled custom e-mails module as well as custom passwords module, i am trying to config the settings for user and admin notification, as well as password recovery and reset, but i don’t get the email for new users and new users don’t get the notification email either.

    my settings for User Notification are:

    From Name
    %blogname%

    From E-mail: info@lagofutbol.com –this is my blog’s email

    Message:
    email: %user_email%
    Usuario: %user_login%
    Password: %user_pass%
    %siteurl%

    my settings for Admin Notification are:
    To: -i leaved it blank–

    From Name: Futbol Lago
    From E-mail: -i leaved it blank–

    Message:
    Usuario: %user_login%
    E-mail: %user_email%

    i also leave unchecked the box ‘Disable Admin Notification’

    note: i am not using the moderation module, however i tested it and got a new user notification email saying: access not granted to my site.

    i wonder if it has to do with the ‘auto login after register feauture’ i just implemented earlier.

    xavi

Viewing 15 replies - 16 through 30 (of 43 total)
  • The topic ‘Auto login after register and redirect to profile page’ is closed to new replies.