Find out if a user is logged into wordpress from i

2019-02-27 10:31发布

I am looking for a function to check if a user is logged into wordpress via their id.

i am aware of this function.

if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
    echo 'Welcome, visitor!';
} 

but i was wondering if their is a function that does it via id so it would be like the following below.

if ( is_user_logged_in(1) ) {
    echo 'this user is logged in';
}

cant find one anywhere.

1条回答
Bombasti
2楼-- · 2019-02-27 11:24

you can go around it like:

if ( is_user_logged_in() ) {
     $current_user = wp_get_current_user();
     if ( 1 == $current_user->ID ) {
      // do staff.
     } else {
       // do staff.
     }
 }
查看更多
登录 后发表回答