Retrieve First Name, then show custom name if the first name is not settle

Question

I’m creating a code that retrieves the user Avatar and First Name/username using Shortcodes, but I noticed that if the user has no name settle, it will display a blank space. How can I set a custom name to show up when the user has no name settle? Something like this “Hi >Mister Anderson<, is that actually your name? Please configure your name in your account.”

THE CODE

Display Avatar, this part is not really necessary in this question, but I’m going to leave it here as a contribution, just in case someone else is interested in the code:

// show user avatar if logged in
function colaborator_avatar($atts)
{
    if (is_user_logged_in() && !is_feed()) {
        return get_avatar(get_the_author_meta( 'user_email' ));
    }
}
add_shortcode('colaborator_avatar', 'colaborator_avatar');

Display first name (this is the part related to my question):

// show first name if logged in
function colaborator_nome($atts)
{
    if (is_user_logged_in() && !is_feed()) {
    return get_user_meta( $new_user->ID, 'first_name', true );

    }
}
add_shortcode('colaborator_nome', 'colaborator_nome');

Or display Username (also here in case someone needs the code):

function colaborator_nome($atts) {     
    if (is_user_logged_in() && !is_feed()) {    
        $current_user = wp_get_current_user();
        echo $current_user->user_login;
    } 
} 

add_shortcode('colaborator_nome', 'colaborator_nome'); 
0
, , , , 21321312 3 years 2020-07-06T20:10:42-05:00 0 Answers 72 views 0

Leave an answer

Browse
Browse