• Hi all,

    I am trying to capture the username once login by
    <?php global $userdata;
    get_currentuserinfo();

    echo(‘Username: ‘ . $userdata->user_login . “\n”);
    echo(‘User level: ‘ . $userdata->user_level . “\n”);
    echo(‘User ID: ‘ . $userdata->ID . “\n”);
    ?>

    But on exceuting, i am getting Fatal error: Call to undefined function: get_currentuserinfo() in /home/eworl2/public_html/irland/getloginir.php on line 10

    What am i doing wrong ir what am i missing?
    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I would have expected the path to include wp_content/plugins/ in it somewhere. Is this not a plugin? If it’s not integrated into the wordpress code, then you can’t call a WP function like get_currentuserinfo().

    Thread Starter sirux

    (@sirux)

    Hi All, Please find the code below. I have login on the my WP site. But on executing the code below, I am getting everything as blank. Can you please advise what’s wrong.

    <?php

    require(‘wp-config.php’);
    global $userdata;
    get_currentuserinfo();

    echo(‘Username: ‘ . $userdata->user_login . “\n”);
    echo(‘User level: ‘ . $userdata->user_level . “\n”);
    echo(‘User ID: ‘ . $userdata->ID . “\n”);
    ?>

    Output:
    Username: User level: User ID:

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Don’t include wp-config.php like that. The correct file to include is wp-blog-header.php.

    Also, get_currentuserinfo sets the $current_user variable, not $userdata. If you want to set the $userdata variable, you need to call setup_userdata().

    Thread Starter sirux

    (@sirux)

    Hi,

    I am quite new here. Can someone please give me a working code. Also I noticed that I can’t post on my blog.

    I can login but one clicking to post comments, i need to login again and this keeps looping. Seems that it is not keeping my login name. Can anyone please help here?

    Thanks

    try this :

    <?php global $userdata;
    get_currentuserinfo();
    echo(‘<b>Hi, ‘ . ‘<i>’ . $userdata->user_login . ‘</i></b>!’);
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Capture Username’ is closed to new replies.