WordPress Login is a WordPress plugin that will allow users to register into a WordPress website with a Twitter account in one single click. The plugin will create an account in the WordPress wp_users table.
Who is this plugin for?
This plugin has been specially coded for intermediate to senior WordPress developers that want to develop a new web application using WordPress. The plugin can be configured easily and it has been coded to be very scalable. Users with no knowledge of PHP may find other solutions more helpful since this plugin doesn’t have any GUI. The main purpose of this plugin is to allow people to develop an app taking advantage of the high-converting one-click Twitter sign-up process and saving time in programming a User Authentication system.
How it works?
When a user accesses the URL
?tw=login in a WordPress website he is redirected to Twitter using Matt Harris’ OAuth library. Once authenticated, a new WordPress user is created picking all the information from the Twitter username. The WordPress username has a prefix (
tw- by default) and his Twitter ID (the public username is not used here since it can be changed). The password is his Twitter ID with a custom salt. Extra information is stored in his user profile (nickname, full name, website, bio, etc.) as well as in custom user fields (oauth_token, oauth_token_secret, language, followers and friends count, profile image, etc.).
A caveat in WordPress is that it requires a valid and unique email address per user. Since Twitter does not provide you with the user’s email address, the plugin registers the user with an email address like [email protected]
By default the plugin will not allow users to access WP-Admin which makes this plugin perfect for someone who will provide a service to registered users without ever showing the WordPress inner pages to them. You can enable access to WP-Admin changing a variable from true to false although you should disallow users from changing their password or they will not be able to log back in.
Download the plugin from GitHub:
This plugin is licensed under a MIT license. Feel free to use it in any commercial way.
1. Download the plugin and upload it to your plugins folder as you would do with any other WordPress plugin
2. Create a new app at Twitter here
3. Copy the Consumer Key and Consumer Secret and paste them in
4. Change the
$salt variable to something long and complicated
5. Optionally, you can change the username prefix to something else to increase security
Retrieving user information
To see if a user is logged in through Twitter run
is_user_logged_in() and then check if the username matches the Twitter prefix (
tw- by default).
To retrieve the current user’s data do something like this:
global $current_user; get_currentuserinfo(); echo 'Hello ' . $current_user->nickname; echo 'User token: ' . $current_user->oauth_token; echo '<img src="' . $current_user->profile_image_url . '" alt="" />';
To retrieve data from someone else do something like this:
$user_info = get_userdata($user_id); echo 'Username: ' . $user_info->nickname;