Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've tried to do automatic login to wordpress after registering with password when using WP-Members plugin.

I don't have a blog so I decided to write it here, so it may be helpful for someone. I'm not really good in programming wordpress plugins. And it took me some time to find it.

Of course that works if you add custom field (option_name = password) in the plugin's settings.

In file wp-members.register.php in function *wpmem_registration( $toggle )* I've replaced this line:

return "success"; exit();

with that code from function *wpmem_login()* in file wp-members-core.php :

    /** assemble login credentials */
    $creds = array();
    $creds['user_login']    = $username;
    $creds['user_password'] = $password;
    $creds['remember']      = true;


    /** wp_signon the user and get the $user object */
    $user = wp_signon( $creds, false );

    /** if no error, user is a valid signon. continue */
    if( ! is_wp_error( $user ) ) {

        /** set the auth cookie */
        wp_set_auth_cookie( $user->ID, true );


        /** determine where to put the user after login */
        $redirect_to = $_SERVER['PHP_SELF'];
        if( isset( $_POST['redirect_to'] ) ) {
            $redirect_to = $_POST['redirect_to'];
        }


        /** apply wpmem_login_redirect filter */
        $redirect_to = apply_filters( 'wpmem_login_redirect', $redirect_to );



        /** and do the redirect */
        wp_redirect( $redirect_to );

        /** wp_redirect requires us to exit() */
        exit();

    } else {

        return "loginfailed";
    }

Is this safe? Could it be done in some better way?

share|improve this question
    
I think it would be better to post the second part as an answer and wait for feedback there. Now it is a code review - something our site is not really made for. –  toscho Oct 12 '12 at 2:35

1 Answer 1

I'm not sure I follow you correctly, but you shouldn't be editing core plugin files, instead you should make use of the available hooks and filters provided by WP-Members and for example either create your own plugin or more simply use your functions.php file to modify its behavior.

add_action( 'wpmem_register_redirect', 'my_reg_redirect' );

function my_reg_redirect()
{
    // NOTE: this is an action hook that uses wp_redirect
    // wp_redirect must end with exit();

    wp_redirect( 'http://mydomain.com/my-page/' );

    exit();
}

Also taken from this link,

Suppose that you do not want users to have instant access to the site upon a successful registration, but rather, you want to manually validate that you have legitimate user. In these types of cases, WP-Members™ allows you to moderate registrations, requiring that the user be “activated” by an administrator prior to having access.

It appears to be an option within the plugin itself to either moderate or not moderate registrations, the latter of the two will auto-login a user on successful registration while the former, if turned on, will require that the user activate their account via e-mail or that an admin approve their account.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.