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