현재 로그인 한 유저의 정보를 불러오는 방법이다.
원문 글 – WordPress Codex Function Reference/wp get current user
예제
$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>';
결과
Username: wallel
User email: [email protected]
User first name: 태영
User last name: 김
User display name: wallel
User ID: 1
관련 함수
get_current_user_id(), get_currentuserinfo(), wp_set_current_user(), current_user_can(), current_user_can_for_blog()