Programmatically create and login user into WordPress

Is there a way to programmatically login user into WordPress? Well, of course yes. This is, in fact, very easy. WordPress does it every time you login! Even more, we may login without using any password. WordPress basically checks password hash and if it is correct, then log user in. We may just skip password hash comparing and jump straight into login.

I wrote some small plugin recently to join foreign Application with WordPress installation. User has to login into application and WP login layer has to be invisible. Here is how I did it:

You may also want to know if user is already in our database. Very simple thing:

As you see, nothing easier!

Be the first to comment

Leave a Reply

Your email address will not be published.