I would have expected the path to include wp_content/plugins/ in it somewhere. Is this not a plugin? If it’s not integrated into the wordpress code, then you can’t call a WP function like get_currentuserinfo().
Thread Starter
sirux
(@sirux)
Hi All, Please find the code below. I have login on the my WP site. But on executing the code below, I am getting everything as blank. Can you please advise what’s wrong.
<?php
require(‘wp-config.php’);
global $userdata;
get_currentuserinfo();
echo(‘Username: ‘ . $userdata->user_login . “\n”);
echo(‘User level: ‘ . $userdata->user_level . “\n”);
echo(‘User ID: ‘ . $userdata->ID . “\n”);
?>
Output:
Username: User level: User ID:
Don’t include wp-config.php like that. The correct file to include is wp-blog-header.php.
Also, get_currentuserinfo sets the $current_user variable, not $userdata. If you want to set the $userdata variable, you need to call setup_userdata().
Thread Starter
sirux
(@sirux)
Hi,
I am quite new here. Can someone please give me a working code. Also I noticed that I can’t post on my blog.
I can login but one clicking to post comments, i need to login again and this keeps looping. Seems that it is not keeping my login name. Can anyone please help here?
Thanks
try this :
<?php global $userdata;
get_currentuserinfo();
echo(‘<b>Hi, ‘ . ‘<i>’ . $userdata->user_login . ‘</i></b>!’);
?>