• Hello friends,
    i’m facing a problem in creating a plugin from get_currentuserinfo(); function. I want when the users logs in than the code should display his/her name. Here is my code which i used

    function $user_identity() {
    global $current_user;
    get_currentuserinfo();
    $user_identity = $current_user->display_name;

    echo ‘Username: ‘ . $current_user->user_login . “\n”;
    echo ‘User email: ‘ . $current_user->user_email . “\n”;
    echo ‘User first name: ‘ . $current_user->user_firstname . “\n”;
    echo ‘User last name: ‘ . $current_user->user_lastname . “\n”;
    echo ‘User display name: ‘ . $current_user->display_name . “\n”;
    echo ‘User ID: ‘ . $current_user->ID . “\n”;
    }

    And i want to call it in my header like if( is_user_logged_in()) {
    echo “Hello, $user_idenity”; }
    else {
    echo “Hello, Visitor”;
    };

    Can you please help in doing so.

Viewing 2 replies - 1 through 2 (of 2 total)
  • In WordPress plugin development.. you will want to become very familiar with the Hooks and Filters Plugin API.

    If you want to use the function as you have it above… you would need to hook to something like the WordPress init() function:

    add_action('init', 'user_identity');
    function user_identity() {
        .....  // your code here
    }

    Then, you could call your function from another file using user_identity().

    However, it sounds like you are getting ready to edit your header.php file ??

    Perhaps a better idea is to use a child theme.

    Thread Starter Abhishek Prakash

    (@abhishek626)

    Thanks Josh. I’ll try and than i’ll tell you about the result.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘I want to create a plugin from wordpress get_currentuserinfo(); function.’ is closed to new replies.