Find out if a user is logged into wordpress from id

核能气质少年 提交于 2019-12-02 03:06:50

问题


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:


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.
     }
 }


来源:https://stackoverflow.com/questions/8559759/find-out-if-a-user-is-logged-into-wordpress-from-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!