1

I believe I have a misunderstanding of what the global variable $current_user is exactly. I'm attempting to display the current user's email and name on a page using add_filter('the_content', 'my_function') and if two users click the button at the same time, you will see another user's information. I can reproduce this over and over. The code I'm using is below:

function my_function($content){
    $current_user = wp_get_current_user();
    $content .= "User Email: " . $current_user->user_email;
    return $content;
}

add_filter('the_content', 'my_function');

// ALSO PRODUCES SAME RESULT:
function my_function2($content){
    get_currentuserinfo();
    global $current_user;
    $content .= "User Email: " . $current_user->user_email;
    return $content;
}

What am I doing wrong? I've tried this in init action and results the same.

UPDATE:

I also want to make sure that the method in which I'm creating a user is not causing the problem either. I use the standard WP login, but I redirect to my custom registration page which asks for basic info and then does the following to create a user. Is there anything wrong with this (or is it missing something that a normal WordPress user would have?):

$userdata = array(
                    'user_pass'         => $password,
                    'user_login'        => $email_1,
                    'user_nicename'     => $nickname,
                    'user_email'        => $email_1,
                    'display_name'      => $nickname,
                    'nickname'          => $nickname,
                    'first_name'        => $first_name_1,
                    'last_name'         => $last_name_1,
                    'description'       => NULL,
                    'rich_editing'      => 'true',
                    'user_registered'   => date("Y-m-d H:i:s"),
                    'role'              => 'ssm_user'
                );

$user_id = wp_insert_user($userdata);
$user = new WP_User( $user_id );
  • 1
    Are all plugins disabled and all cache files deleted? – fuxia Oct 29 '13 at 2:43
  • No, there are other plugins activated and I don't know how to delete the cache files...how does one do that? – clockwiseq Oct 29 '13 at 2:54
  • What do you mean by "two users click the button at the same time"? I am not sure how that is possible except by using two different computers, and I tried that-- couldn't duplicate what you describe. Also, what button? – s_ha_dum Oct 29 '13 at 2:56
  • toscho, I deactived all plugins except mine. testing now. And s_ha_dum, yes, I have 100's of users and they are all hitting the site at the same time (clicking menu items, options on my dashboards, etc.). – clockwiseq Oct 29 '13 at 3:01
  • toscho, after deactivating, I still get the wrong login information for my user. Any suggestions? – clockwiseq Oct 29 '13 at 3:38
0

Before answering my own question, I would like to preface it with a very well-deserved thank you for all of your comments and suggestions. It led me to the root of the issue. @toscho, it was your comment that made me think about disabling the other plugins that were activated on the site. That narrowed it down to my plugin (which I thought was the culprit) and after multiple tests (on various servers besides my host), found out that the issue disappeared. Below was the solution (which was also suggested by @toscho):

I contacted my host (SmarterASP.Net - great group of guys by the way), and explained the situation, and they said that there was an output-caching option enabled on my site. They then proceeded to inform me of how to disable it and voila! Ghost-login issue has disappeared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.