If Is User by ID

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.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.