WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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');

function my_function2($content){
    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.


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 );
share|improve this question
Are all plugins disabled and all cache files deleted? – toscho 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

Code looks ok to me. Is there any consistency in what name/email is actually shown when showing incorrectly? (eg is it Admin?) Are you sure the user is logged in? Are you using wp_set_current_user anywhere for your user registration? Is your code in functions.php or the template for the file?

Also, why are you adding a filter to the_content? I'm unsure how you're attempting to use this data? Perhaps there is a better way of doing it using a call from the template file?

share|improve this answer
Hi TomC , this isn't really an answer and would be better suited as a comment. – Wyck Oct 29 '13 at 5:40
I agree - unfortunately I don't have rights to comment but felt this should help the OP. – TomC Oct 29 '13 at 5:42
Have a look at the wordpress.stackexchange.com/help, answers should not ecourage discussion or have questions. You only need 50 rep to comment which can be completed pretty easily. – Wyck Oct 29 '13 at 5:45
+1 for an extra 10-points. If someone else +1s it, you'll be able to comment as normal. – Denis de Bernardy Oct 29 '13 at 8:24
It's consistent in that I can reproduce the issue over and over and last night I ran a test with 3 users. Here was the situation: 1) I (User #1) logged in and sat (no clicks anywhere on the site). 2) User #2 logged in and clicked on a page and my information (User #1) was displayed. 3) User #3 logged in and then I (User #1) clicked on a page and User #3 information was displayed. I am filtering the_content because that is out I output my HTML to a specific page. – ClockwiseQ Oct 29 '13 at 13:21
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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