Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created a page in wordpress and i tried to access the current logged in user via wp_get_current_user() and am getting error "function undefined". please how do I make this function available in my page.

share|improve this question
    
is this a php page you created? –  Bainternet Jul 13 '11 at 6:49
    
Yes it is a php page –  joe Jul 13 '11 at 19:38
    
try adding require('/the/path/to/your/wp-blog-header.php'); at the top of your PHP page –  Bainternet Jul 13 '11 at 19:49
    
thanks Bainternet but I have added the require and am getting the error "cannot coonect to database" this is the code below: –  joe Jul 14 '11 at 5:32
    
<?php require('/wordpress/wp-blog-header.php'); $current_user = wp_get_current_user(); $current_user->set_role(rocky2); ?> –  joe Jul 14 '11 at 5:32

1 Answer 1

You can use following..

global $current_user;
get_currentuserinfo();

Than you can access everything as

$current_user->user_login,$current_user->user_email...

Here is explanation...
http://codex.wordpress.org/Function_Reference/get_currentuserinfo

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.