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() */

    } else {

        return "loginfailed";

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

  • 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.
    – fuxia
    Oct 12, 2012 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://example.com/my-page/' );


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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