Browser Sign In WordPress Plugin


Warning: This post is no longer current, for the most up to date information, see MDN or the Identity Wiki.

Hi all,
A quick update to say that I am releasing the WordPress Plugin to support Browser Sign In. The repository for the code can be found on GitHub. The clone link is git://github.com/stomlinson/browser_sign_in_wordpress.git.

As an example of how to implement the Sessions API, I am including the initial version of the code.

<?php
/*Plugin Name: Browser Sign In
Plugin URI: http://www.shanetomlinson.com
Description: Supports the Sessions API produced my Mozilla Labs.
Version: 0.0.1
Author: Shane Tomlinson
Author URI: http://www.shanetomlinson.com
License: MPL 1.1, GPL 2.0, LGPL 2.1
*/

function set_sessions() {
    echo "
        <script type='text/javascript'>
          var doc = window.document;
          // Do not blow up non-supporting browsers.
          if(navigator.id && doc.addEventListener) {\n ";

    if(is_user_logged_in()) {
        global $userdata;
        get_currentuserinfo();
        echo "
            navigator.id.sessions = [ { email: '" . $userdata->user_login . "'} ];

            // The user is logged in, we only really need to listen for the
            // logout event
            doc.addEventListener('logout', function() {
                navigator.id.sessions = undefined;
                doc.location.href = '" . wp_logout_url() . "';
            }, false);\n";
    } else {
        echo "
            // The user is not logged in, we only have to listen for the login
            // event from the browser.
            navigator.id.sessions = [];
            doc.addEventListener('login', function() {
                doc.location.href = '" . wp_login_url() . "';
            }, false);\n";
    }

        echo "
          }
        </script>";
}

add_action('wp_head', 'set_sessions');
add_action('admin_head', 'set_sessions');

?>

The plugin can be found on the WordPress Plugins listing site under Browser Sign In.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Google Buzz Post to Reddit Post to Slashdot Post to StumbleUpon Post to Technorati

Comments are closed.