나는 제 3 자 시스템과 통합 조각을 작성하고Wordpress 라이프 사이클 중 어떤 시점에서 wp_get_current_user를 사용할 수 있습니까?
사용자가 로그인 나는 여러 가지 후크 시도했습니다 때 특정 값을 확인해야 해요 :.이 wp_init, wp_login 및 wp_loaded하지만 wp_get_current_user는 항상 null를 돌려줍니다. 사용자가 현재 로그인이있는 경우
나는 제 3 자 시스템과 통합 조각을 작성하고Wordpress 라이프 사이클 중 어떤 시점에서 wp_get_current_user를 사용할 수 있습니까?
사용자가 로그인 나는 여러 가지 후크 시도했습니다 때 특정 값을 확인해야 해요 :.이 wp_init, wp_login 및 wp_loaded하지만 wp_get_current_user는 항상 null를 돌려줍니다. 사용자가 현재 로그인이있는 경우
예컨대이 : 확인하려면 다음을 수행하십시오
<?php
wp_get_current_user();
if (0 == $current_user->ID) {
// Not logged in.
} else {
// Logged in.
}
?>
기본 사용 wp_get_current_user를 호출() WP_User 개체를 반환합니다. 이 페이지에
<?php
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 level: ' . $current_user->user_level . '<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 />';
?>
더 http://codex.wordpress.org/Function_Reference/wp_get_current_user
나는 http://codex.wordpress.org/Function_Reference/get_user_by를 사용하여이 작업을 수행 할 수 있었다.
function CheckWordPressLogin($User) {
//$User contains login user name.
$CurrentUser = get_user_by('login', $User); //$CurrentUser is a WP_User object.
}
add_action('wp_login', 'CheckWordPressLogin');