// Get the current user's ID $user_id = get_current_user_id(); // Use the $user_id in database queries or user-specific operations $user_data = get_user_by( 'id', $user_id ); echo 'Welcome ' . $user_data->user_login . '!';
// Get the ID of the user with username 'johnDoe' $user_id = username_exists( 'johnDoe' ); if ( $user_id ) { // Use the $user_id to perform user-specific operations $user_data = get_user_by( 'id', $user_id ); echo 'Welcome ' . $user_data->user_login . '!'; } else { // Handle error if user does not exist echo 'User does not exist!'; }In this example, the `username_exists()` function is used to check if the user with the username 'johnDoe' exists in the database. If the user exists, the `get_user_by()` function is used to fetch user data and display a welcome message. If the user does not exist, an error message is displayed. Package/Library: WordPress core file.