Need to access $user_ID

I need to access the $user_ID in a non-WP php script. How can I set the value of $user_ID to a session variable or a cookie when a user logs in?

  • Andrew

    Well, you could save the id to a cookie by tossing a plugin in mu-plugins.

    Something like:

    add_action('init', 'user_id_cookie');
    function user_id_cookie() {
        global $user_ID;
        if ( !empty( $user_ID ) ) {
            $expire = time() + 3600; // 1 hour
            setcookie('wp_uid', $user_ID, $expire);

    Now I just slapped that together with no testing, etc. So give it a once over before using it.

    You'll probably want to use something that sets the cookie on login and clears it on logout though.