3

I have a new php page and I'm using wordpress for my website.

From within my new php file I've included wp_load..

include ('wp-load.php');

which I believe is required in order to retrieve current user details.

I've then tried to echo the current loginname:

$current_user->user_login

but it's coming out empty and I know it's not..

UPDATE:

This is what I'm trying...

include ('wp-load.php');
global $current_user;
$current_user = wp_get_current_user();
$myuserlogin = $current_user->user_login;

echo $myuserlogin;

This is not returning anything...

I'm I missing anything?

RESULT:

This is the var_dump result:

[object Object]1object(WP_User)#79 (10) { ["data"]=> NULL ["ID"]=> int(0) ["id"]=> int(0) ["caps"]=> array(0) { } ["cap_key"]=> NULL ["roles"]=> array(0) { } ["allcaps"]=> array(0) { } ["first_name"]=> string(0) "" ["last_name"]=> string(0) "" ["filter"]=> NULL }

1

1 Answer 1

7
<?php
  include ('wp-load.php');
  global $current_user;
  $current_user = wp_get_current_user();
  var_dump($current_user);
?>
Sign up to request clarification or add additional context in comments.

4 Comments

The vardump is returning NULL and empty strings so the include is not getting the current user details for some reason or I'm missing something?
If you not logged in its returning empty strings. Otherwise they filled. Ive cehck it on my WP 3.2.1
Was your file in the theme root or server root?
server root. try to replace include with require

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.