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?