WordPress.org

Ready to get started?Download WordPress

Forums

get_currentuserinfo() performance question (2 posts)

  1. rick_williams
    Member
    Posted 5 years ago #

    Hello Everybody! (I feel like Dr. Nick from 'the Simpsons.')

    Ok, I force people to log into my blog to view certain categories (because I'm a sadist), and as a cheap reward I thought it appropriate to echo out that person's name in the header of the blog.

    "Welcome [USER_NAME]! Thank you for bothering to log into my site for otherwise petty reasons."

    So anyways, in my header, I'm using the following code to get the current user's information.

    <?php global $current_user;
    get_currentuserinfo(); ?>

    and printing it out with something like:

    echo $current_user->user_login

    Doing this has increased the blog page load time by three-fold, at least.

    So, I was wondering if there were any better ways -- perhaps doing this once and storing that information in a cookie and using that on each subsequent page load -- or --

    is there already a cookie generated by wordpress's login with the information that I'm looking for (the user's name) stored on the client's computer?

    To those that may respond, I want to you to know that I love you and I will do anything for you as long as it doesn't inconvienince me or cause me to go out of my way in the least bit.

    Really, Thanks. :)

  2. Austin Matzko
    Member
    Posted 5 years ago #

    Wow. If you're consistently getting those kinds of performance hits just from using get_currentuserinfo() then please open a support ticket, as this is a bug that needs to be addressed.

    To get the current username from the cookie, do the following:

    $cookie_data = explode('|', $_COOKIE[LOGGED_IN_COOKIE]);
    $username = $cookie_data[0];

Topic Closed

This topic has been closed to new replies.

About this Topic