i am trying to get the User_ID outside of wordpress. I have a rating plugin and it needs the current user id, to cast votes. However it seems that something is going wrong. This is the part of the code i am using in my functions.php file:
function get_userid(){
$user = get_current_user_id( );
//i can correctly echo the user_id here
return $user;
}
function add_thumbsup(){
include './thumbsup/init.php';
echo ThumbsUp::javascript();
}
add_action('wp_head', 'add_thumbsup');
Within init.php i have a callback function to get_userid(). So far so good.
Within the Plugin i have a block to check for the user_id:
public static function get_user_id()
{
// Cache
static $user_id = FALSE;
// This code only needs to be executed once per request
if ($user_id !== FALSE)
return $user_id;
// The callback config is left empty
if ( ! ThumbsUp::config('user_id_callback'))
return $user_id = NULL;
// Load the user id
$user_id = (int) call_user_func(ThumbsUp::config('user_id_callback'));
//returns value from get_userid()
//echo $user_id => 33
// Set user id to NULL if not found
return ($user_id) ? $user_id : $user_id = NULL;
}
It shows my correct user_id of 33 when echoed. However, when vote up/down is pressed, the function returns NULL.
Can it be a Ajax/Javascript related problem? Or how can i fix this?
ajaxurl
?