• Hi,
    I have this in my code
    $current_user = wp_get_current_user();
    $temp_var = var_dump($current_user);

    Tresult on the screen is:
    object(WP_User)#338 (8) { [“data”]=> object(stdClass)#355 (10) { [“ID”]=> string(2) “50” [“user_login”]=> string(10) “testuser20”

    which is good.

    However, how do I access the “ID” and “user_login” from what the dump shows me on the screen?

Viewing 1 replies (of 1 total)
  • Hello Billy

    You can simply use below code and with that you can use all the user related info.

    <?php
    $current_user = wp_get_current_user();
    /**
    * @example Safe usage:
    * $current_user = wp_get_current_user();
    * if ( ! $current_user->exists() ) {
    * return;
    * }
    */
    echo ‘Username: ‘ . $current_user->user_login . ‘<br />’;
    echo ‘User email: ‘ . $current_user->user_email . ‘<br />’;
    echo ‘User first name: ‘ . $current_user->user_firstname . ‘<br />’;
    echo ‘User last name: ‘ . $current_user->user_lastname . ‘<br />’;
    echo ‘User display name: ‘ . $current_user->display_name . ‘<br />’;
    echo ‘User ID: ‘ . $current_user->ID . ‘<br />’;
    ?>

    Hope this helps.

    Thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘accessing WP_User object’ is closed to new replies.