Web Development. Client Satisfaction. Web Consultancy. Professional. UX. Fast. Responsive Design. Dynamic. Interactive. Innovative. Ecommerce. Wordpress plugins. Prestashop modules. You name it.

How To Make Programmatically WordPress Login PHP

How To Make Programmatically WordPress Login PHP

In this tutorial we will try to programmatically login user using PHP. This functionality is usefull when you create a custom registration form and after registration you auto login the user in his account. Or if you want to register user account for an easy login.

Programmatically Wordpress Login PHP

In order to successfully autologin the user in his account, the only thing you need to do this, is his user id. After you get the user id everything is straightforward. 

clean_user_cache($user_id);
wp_clear_auth_cookie();
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id, true, false);
    
$user = get_user_by('id', $user_id);
update_user_caches($user);

The above code is all you need to programmatically login any user in wordpress. Let me know if you need any help with this implementation.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
*/?>