Monday, May 16, 2016

Wordpress get current logged in user information

In WordPress we can get the logged in user information such as firstname, lastname, displayname and ID in the following way.

<?php
$current_logged_user = wp_get_current_user();
?>


Now you have all the user information in the $current_logged_user variable. You can access the information in the following way.

<?php
echo 'Username: ' . $current_logged_user->user_login . '<br />';
    echo 'User email: ' . $current_logged_user->user_email . '<br />';
    echo 'User first name: ' . $current_logged_user->user_firstname . '<br />';
    echo 'User last name: ' . $current_logged_user->user_lastname . '<br />';
    echo 'User display name: ' . $current_logged_user->display_name . '<br />';
    echo 'User ID: ' . $current_logged_user->ID . '<br />';
?>

No comments:

Post a Comment

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...