June 07, 2016
Found this demonstrative function in the wp_get_current_user(); WordPress documentation, as a way to test if a user is logged in:
<?php $current_user = wp_get_current_user(); if ( 0 == $current_user->ID ) { // Not logged in. } else { // Logged in. } ?>
By modifying it slightly, you can check for an existing user by ID:
<?php $current_user = wp_get_current_user(); if ( 7 == $current_user->ID ) { // User ID 7 logged in. } else { // Not Logged in. } ?>
I use this when making template changes to live websites, as a way of cloaking the content areas that I’m adjusting until they are completed and ready to publish.