WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 23 months ago

#19769 closed defect (bug) (fixed)

$userdata is not empty for anonymous requests

Reported by: MattyRob Owned by: 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 2 years ago.
19769.2.diff (345 bytes) - added by duck_ 2 years ago.
19769.3.diff (558 bytes) - added by nacin 2 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 follow-up: linuxologos2 years ago

Possibly related: #19595.

comment:2 in reply to: ↑ 1 MattyRob2 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).

comment:3 scribu2 years ago

  • Milestone changed from Awaiting Review to 3.3.2

Yeah, this should be fixed somehow.

comment:4 follow-up: MattyRob2 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.

MattyRob2 years ago

duck_2 years ago

comment:5 in reply to: ↑ 4 duck_2 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.

comment:7 MattyRob2 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

nacin2 years ago

comment:8 nacin2 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.

comment:9 nacin2 years ago

In [20087]:

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

Note: See TracTickets for help on using tickets.