Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress get current user data from new php page

Tags:

php

wordpress

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 }

like image 905
Satch3000 Avatar asked May 10 '26 16:05

Satch3000


1 Answers

<?php
  include ('wp-load.php');
  global $current_user;
  $current_user = wp_get_current_user();
  var_dump($current_user);
?>
like image 99
0leg Avatar answered May 13 '26 05:05

0leg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!