Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19769 closed defect (bug) (fixed)

$userdata is not empty for anonymous requests

Reported by: mattyrob's profile MattyRob Owned by: nacin's profile nacin
Milestone: 3.3.2 Priority: normal
Severity: normal Version: 3.3.1
Component: Users Keywords: has-patch dev-feedback
Focuses: Cc:

Description

When an anonymous user visit a WordPress 3.3.x installation (i.e. a user who has not logged in) the $userdata global variable is set but virtually unpopulated.

In previous versions of WordPress (3.2.1 checked) the $userdata variable returns NULL. In the 3.3 branch it returns the following:

object(WP_User)#251 (7) {
  ["data"]=>
  NULL
  ["ID"]=>
  int(0)
  ["caps"]=>
  array(0) {
  }
  ["cap_key"]=>
  NULL
  ["roles"]=>
  array(0) {
  }
  ["allcaps"]=>
  array(0) {
  }
  ["filter"]=>
  NULL
}

Is this expected behaviour? I would have though $userdata should be NULL for visits from users who are not logged in.

I tested with this simple plugin:

function ud_check() {
	global $userdata;
	var_dump($userdata);
}

add_action('shutdown', 'ud_check');

Attachments (3)

19769.diff (364 bytes) - added by MattyRob 12 years ago.
19769.2.diff (345 bytes) - added by duck_ 12 years ago.
19769.3.diff (558 bytes) - added by nacin 12 years ago.

Download all attachments as: .zip

Change History (13)

#1 follow-up: @linuxologos
12 years ago

Possibly related: #19595.

#2 in reply to: ↑ 1 @MattyRob
12 years ago

Replying to linuxologos:

Possibly related: #19595.

Thanks, I'd seen that ticket but that was more about the data for a user not being fully populated. This is more about the data being there when perhaps it should not be (unless this is a new feature and by design).

#3 @scribu
12 years ago

  • Milestone changed from Awaiting Review to 3.3.2

Yeah, this should be fixed somehow.

#4 follow-up: @MattyRob
12 years ago

  • Keywords has-patch dev-feedback needs-testing added

This is certainly a new area of WordPress code to me but it seems to be something to do with maybe cookies and setting wp_set_current_user(0);

I can get a NULL returned with the attached pitch but I am not sure if this will have additional consequences, so needs a second opinion from the core devs.

@MattyRob
12 years ago

@duck_
12 years ago

#5 in reply to: ↑ 4 @duck_
12 years ago

  • Version changed from 3.3 to 3.3.1

Replying to MattyRob:

I can get a NULL returned with the attached patch

Doesn't work for me. $value === 0 is already caught by the conditional before checking if $value is falsey.

Attached patch to set $userdata to null in setup_userdata().

The bug is in 3.3.1 only and was caused by [19625] for #19595.

#7 @MattyRob
12 years ago

  • Keywords needs-testing removed

I've tested this new patch and it fixes the original problem reported. needs-testing removed, unable to add tested or commit

@nacin
12 years ago

#8 @nacin
12 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [20085]:

$userdata should be null for anonymous requests. props MattyRob. props duck_ for the unit test. fixes #19769 for trunk.

#9 @nacin
12 years ago

In [20087]:

$userdata should be null for anonymous requests. props duck_. fixes #19769 for 3.3. see #19595.

#10 @scribu
12 years ago

Related: #20845

Note: See TracTickets for help on using tickets.