• hi guys, I am working on an AJAX instant messenger plug in for my WP. However I want the plug in to work on my VBulletin forum as well since the user names are bridged to wordpress I am able to use the same username across WP and Vbulletin. However there is a slight problem, for this plug in to work outside of WP i include wp-config.php which loads wp-settings.php which in turns loads a ton of useless (for this plug in) things such as themes, other plug ins and filters. This causes a conflict with Vbulletin causing weird filtered output.

    All I really need is to get at $current_user from outside of WP Blog bypassing everything else that is redundant.

    is this possible?

    thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mastershake

    (@mastershake)

    anyone?

    You’ll probably need to work with the cookie and database manually.

    The cookie wordpress sets is named wordpress_md5(site_url). In it you will find:

    username|expiration|validation_code

    Username is just the user’s username. Expiration is the time in seconds since the UNIX epoch, you can see if it’s expired in PHP with if(time() > expiration). Validation code is an hmac-hashed string. You can validate it with this function:

    function wp_validate_auth_cookie($cookie) {
    	$secret = YOUR_WORDPRESS_SECRET_KEY;
    	$salt = YOUR_WORDPRESS_SALT;
    
    	@list($username, $expiration, $hmac) = explode('|', $cookie);
    	if(!$username || !$expiration || !$hmac) return false;
    
    	if ( $expiration < time() )
    		return false;
    
    	$key = $username . $expiration . $secret . $salt;
    	$hash = hash_hmac('md5', $username . $expiration, $key);
    
    	if ( $hmac != $hash )
    		return false;
    
    	return true;
    }

    I wrote a plugin for Vanilla to work with WordPress yesterday, :D.

    The secret key and salt should be defined in wp-config.php.

    You can try this:

    require_once('../../../wp-config.php');
    require_once('../../../wp-includes/wp-db.php');
    require_once('../../../wp-includes/pluggable.php');
    
    echo wp_get_current_user()->ID;

    Just make sure the path is OK, so that you are able to require the files successfully. ??

    mwangisk

    (@mwangisk)

    e-sense:
    Thanks a million.

    – After i wasted a whole day

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to get Current User ID outside of WP Blog.’ is closed to new replies.