• Is there a way to get the current WordPress logged in user if I wanted to build a stand-alone PHP page outside of WordPress.. I tried this code, but it doesn’t work:

    <?php
    require_once('/var/www/html/myblog/wp-includes/pluggable.php');
    
    global $current_user;
    get_currentuserinfo();
    
          echo 'Username: ' . $current_user->user_login . "\n";
          echo 'User email: ' . $current_user->user_email . "\n";
          echo 'User level: ' . $current_user->user_level . "\n";
          echo 'User first name: ' . $current_user->user_firstname . "\n";
          echo 'User last name: ' . $current_user->user_lastname . "\n";
          echo 'User display name: ' . $current_user->display_name . "\n";
          echo 'User ID: ' . $current_user->ID . "\n";
    ?>

    Thanks in advance!
    MS

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Check with this plugin:

    http://ww.wp.xz.cn/extend/plugins/wassup/

    Thanks,

    Shane G.

    Thread Starter mschwade

    (@mschwade)

    Hi Shane,

    It’s a plugin though incorporated in WordPress.. I want to be able to run a simple PHP file outside of WP that tells me what current user is logged in.

    Thanks,
    MS

    Thread Starter mschwade

    (@mschwade)

    Anybody able to help me with this?

    Thanks

    I just had to fix this code on my site because it used to check $current_user->user_level but that member seems to have disappeared. Here’s the code I use now:

    // Authenticate a wordpress user
    
    define('WP_USE_THEMES', false);
    require('../wp-blog-header.php');
    
    global $current_user;
    get_currentuserinfo();
    
    if ($current_user->ID == 0)
    {
    	echo "You must be logged in to access this page. Click <b>Register</b> or <b>Log in</b> in the menu on the right side.";
        exit;
    }
    else
    {
    	// User is logged in
    }
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Current Logged in WP user’ is closed to new replies.