WordPress & PHP – get_currentuserinfo();

I have searched to the end of the internet and can’t seem to find anything that helps me with my issue. I have a wordpress site (inherited) and I simply want to be able to obtain a user’s information when they’re logged in. From the documentation I see to use get_currentuserinfo() but when I try to use it I get nothing.

The file resides in a folder in my main html directory. Here are the contents:

Read More
<?php 
include_once("../wp-includes/pluggable.php"); 
  global $current_user;
  get_currentuserinfo();
  echo $current_user->user_login;


?>

I’m literally losing my mind over this. Is there something else I need to include at the top? Do I have to create the page within wordpress?

Related posts

Leave a Reply

2 comments

  1. you must include wp-load.php to use wordpress function in php file outside wordpress

    require_once("/path/to/wordpress/wp-load.php");
      global $current_user;
      get_currentuserinfo();
      echo $current_user->user_login;
    
  2. <?php
    $current_user = wp_get_current_user();
    /**
     * @example Safe usage: $current_user = wp_get_current_user();
     * if ( !($current_user instanceof WP_User) )
     *     return;
     */
    echo 'Username: ' . $current_user->user_login . '<br />';
    echo 'User email: ' . $current_user->user_email . '<br />';
    echo 'User first name: ' . $current_user->user_firstname . '<br />';
    echo 'User last name: ' . $current_user->user_lastname . '<br />';
    echo 'User display name: ' . $current_user->display_name . '<br />';
    echo 'User ID: ' . $current_user->ID . '<br />';
    ?>