Calling get_currentuserinfo() from an external PHP file
-
I’m writing a shoutbox script for my blog (none of the available plugins provide the functionality/versatility i need), and I’ve run into a problem that has stumped me.
I have javascript code that uses AJAX to get message data from ‘shoutbox.php’ using POST.$.ajax({ type: "POST", url: "https://MYURL/chat/shoutbox.php", data: "action=update", complete: function(data){ loading.fadeOut(); messageList.html(data.responseText); messageList.fadeIn(2000); } });
I include wp-load.php at the top of my shoutbox.php file so that I can use wordpress functions in it. For instance, shoutbox.php contains this line:
$user_info = get_userdata($row['user']); echo $user_info->display_name
Which works perfectly to display the users name. I cannot, however, use the get_currentuserinfo() method. The following code
require('../nizz/wp-load.php'); global $current_user, $user_level; get_currentuserinfo(); echo $user_level."a"; echo $current_user->user_level."b";
only prints “ab”.
How can I use the get_currentuserinfo() function to get the user level in this external file? Is there another method to get user level from this file?
I’d appreciate any help, thank you.
- The topic ‘Calling get_currentuserinfo() from an external PHP file’ is closed to new replies.