Skip to content

Instantly share code, notes, and snippets.

View matberry's full-sized avatar

Matthieu Berry matberry

View GitHub Profile
@matberry
matberry / wp_get_current_user.php
Last active February 9, 2018 09:50
WordPress : Check if user is logged in, get his info
<?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 />';