Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#13362 closed defect (bug) (fixed)

setup_userdata() should set the userdata globals even if the current user is 0

Reported by: mdawaffe's profile mdawaffe Owned by:
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: General Keywords: has-patch
Focuses: Cc:



When calling wp_set_current_user( 0 ), setup_userdata() returns before clearing the userdata globals. Since we still rely on those globals in several places, returning before clearing has unexpected consequences.

setup_userdata() should clear those globals if called for an empty user object.


wp_set_current_user( 1 );
wp_set_current_user( 0 );
$post_id = wp_insert_post( 'post_author=0' );
$post = get_post( $post_id ); // This post has an author!

wp_insert_post() falls back to $GLOBALS['user_ID'] when post_author is empty.

This particular example is more likely to crop up now that we have awesome support for custome post types, but there are several places where we rely on these lame userdata globals.

Marking as 3.0, but is it too late?

Attachments (1)

13362.diff (803 bytes) - added by mdawaffe 14 years ago.

Download all attachments as: .zip

Change History (2)

14 years ago

#1 @ryan
14 years ago

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

(In [14573]) Setup user globals for user id 0. Props mdawaffe. fixes #13362

Note: See TracTickets for help on using tickets.