I would like to get User information after Login or Signup in Wordpress, I have tried several means but the is_user_logged_in()
doesn't seem to work.
It always prints out "Welcome, Visior", even when the user logs in successfully.
The is_user_logged_in()
only works inside the Wordpress theme scripts itself, but doesn't work when I use it in add add_action.
Is there any other way to check if user has loggedin, so I can easily get users information?
function get_user_information(){
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
global $current_user;
get_currentuserinfo();
$email = $current_user->user_email;
} else {
echo 'Welcome, visitor!';
}
}
add_action( 'wp_login', 'get_user_information' );
You can try this
function get_user_information() {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
echo ( 'Welcome, registered user!'. esc_html( $current_user->user_email ) );
} else {
echo( 'Welcome, visitor!' );
}
}
add_action( 'loop_start', 'get_user_information' );
Please try this:
echo ( 'Welcome, registered user!'. esc_html( $current_user->user_email ) );
$user_phone = get_user_meta( $current_user->ID,'user_phone');
You are getting $user_phone as array then write like: echo $user_phone[0];
Otherwise write like: echo $user_phone;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.