Codex tools: Log in / create account
Contents |
Retrieves the information pertaining to the currently logged in user, and places it in the global variable $userdata. Properties map directly to the wp_users table in the database (see Database Description).
Also places the individual attributes into the following separate global variables:
<?php get_currentuserinfo(); ?>
The call to get_currentuserinfo() places the current user's info into $userdata, where it can be retrieved using member variables.
<?php global $userdata;
get_currentuserinfo();
echo('Username: ' . $userdata->user_login . "\n");
echo('User level: ' . $userdata->user_level . "\n");
echo('User ID: ' . $userdata->ID . "\n");
?>
User level: 10
Much of the user data is placed in separate global variables, which can be accessed directly.
<?php global $display_name , $user_email;
get_currentuserinfo();
echo($display_name . "'s email address is: " . $user_email);
?>
This function does not accept any parameters.
To determine if there is a user currently logged in, do this:
<?php global $user_ID;
get_currentuserinfo();
if ('' == $user_ID) {
//no user logged in
}
?>
Here is another IF STATEMENT Example. It was used in the sidebar, in reference to the "My Fav" plugin at http://www.kriesi.at/archives/wordpress-plugin-my-favorite-posts
<?php if ( $user_ID ) { ?>
<!-- enter info that logged in users will see -->
<!-- in this case im running a bit of php to a plugin -->
<?php mfp_display(); ?>
<?php } else { ?>
<!-- here is a paragraph that is shown to anyone not logged in -->
<p>By <a href="<?php bloginfo('url'); ?>/wp-register.php">registering</a>, you can save your favorite posts for future reference.</p>
<?php } ?>
This article is marked as in need of editing. You can help Codex by editing it.