Skip to content

Using only the user's WordPress cookie and a MySql connection (ie: not wp-load.php), check to see if a user is logged in to your WordPress install.

Notifications You must be signed in to change notification settings

benwills/getWpUserByCookie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

getWpUserByCookie()

Using only the user's WordPress cookie and a MySql connection (ie: not wp-load.php), check to see if a user is logged in to your WordPress install.

Background

I wrote this because I like WordPress as a CMS, some of the plugins available for it, and its basic access control. Using WordPress allows me to focus my time on writing applications, rather than the support structure around those applications.

You would normally authenticate to WordPress, from outside of WordPress, by including wp-load.php. The problem is, I don't like how slow it is, and I'm sure there's a ton of stuff in there I simply don't need. All I need is what's returned by this function, which was designed to authenticate as quickly as possible.

Performance

As a performance comparison, on my machine, it took about 0.03 seconds to authenticate via including wp-config.php. getWpUserByCookie() takes about 0.0012 seconds. I can now authenticate from 33 times per second, to 833 times per second.

$user = getWpUserByCookie();
@returns array (
  [id]    => 123
  [name]  => logged_in_username
  [email] => [email protected]
  [caps]  => Array (
      [administrator] => 1
    )
)

About

Using only the user's WordPress cookie and a MySql connection (ie: not wp-load.php), check to see if a user is logged in to your WordPress install.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages