Register in WordPress with Twitter account (plugin)

by
on April 18, 2012
(2 minute read)

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.

WP-Twitter-Login

Who is this plugin for?

Simple Cloud Hosting Built for Developers

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

Download the plugin from GitHub:

wp-twitter-login

License

This plugin is licensed under a MIT license. Feel free to use it in any commercial way.

Installation

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 twitterlogin.php

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).

Things I’m buying on Amazon this week

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;

Looking for cool gift ideas? TrendLiker.com lists hundreds of nice items and lets you know when they go on sale on Amazon.

Did you enjoy this article?

Grab me a coffee ☕

No comments yet

Follow me for cool new products and interesting findings on graphic design, web development, marketing, startups, life and humor.


/*Twitter*/ !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs"); /*Facebook (function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=28624667607";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));*/ /*Google+*/ window.___gcfg = {lang: 'en-GB'};(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;po.src = 'https://apis.google.com/js/plusone.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);})();
Airbnb 25€ discount