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.

This question already has an answer here:

I have my own activation mail for new users that are added via a plugin in the wp backend by an admin. The user is also added as an author to a post and I want him to activate the post (which will publish it) when he gets the email and clicks the link. Currently, the user receives an email with an activation link, but then has to log in and is not redirected to the activation screen. Is it possibly to authenticate the user by receiving the activation key and post id via the URL? The key is stored in his post as a custom field. I basically want this process to log him in automatically and allow him to access hist post from a front end page.

share|improve this question

marked as duplicate by toscho Dec 6 '13 at 11:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

To login a user progrmaticly you can use:

    //Login the user
$creds = array();
$creds['user_login'] = $login;
$creds['user_password'] = $password;
if ( !empty( $remember ) ){ 
    $creds['remember'] = true;
}
$user = wp_signon( $creds, true );

but as you can see you will need to have the password present , so you can just add to your actovation url &pw=pasword and call it using $_GET['pw'].

share|improve this answer
    
Since they are new user's it should be possible to just use wp_generate_password(). –  wyrfel Feb 24 '11 at 20:15
4  
thats probably a better idea. I managed to get this working without the users password using wp_set_auth_cookie which only requires the user ID. –  Innate Feb 25 '11 at 6:57
    
Re: innate's comment on wp_set_auth_cookie see this post: wordpress.stackexchange.com/a/53505/7772 –  Nick Budden Sep 10 '12 at 8:39

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