Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#17894 closed defect (bug) (fixed)

WP_User class uses ID as username when $id = null

Reported by: kawauso's profile kawauso Owned by: ryan's profile ryan
Milestone: 3.3 Priority: normal
Severity: normal Version: 3.1.3
Component: General Keywords: has-patch 3.3-early
Focuses: Cc:

Description

WP_User's __construct() function has:

if ( ! is_numeric( $id ) ) {
	$name = $id;
	$id = 0;
}

presumably for when people incorrectly pass the username as the ID. However, this also returns true when the ID is set as null and is used as the username.

Code to reproduce:

add_action( 'admin_init', 'display_admin_user' );

function display_admin_user() {
	$user_by_name = new WP_User( null, 'admin' );
	$user_by_id = new WP_User( 1 );

	echo '<p>' . print_r( $user_by_name, true ) . '</p>';
	echo '<p>' . print_r( $user_by_id, true ) . '</p>';
}

Attachments (2)

17894.diff (400 bytes) - added by kawauso 14 years ago.
! empty( $id )
17894.2.diff (400 bytes) - added by kawauso 14 years ago.
Refresg

Download all attachments as: .zip

Change History (6)

@kawauso
14 years ago

! empty( $id )

#1 @kawauso
14 years ago

  • Keywords 3.3-early added

@kawauso
14 years ago

Refresg

#2 @kawauso
14 years ago

  • Milestone changed from Awaiting Review to 3.3

#3 @ryan
14 years ago

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

In [18598]:

Handle null user ID in the WP_User constructor. Props kawauso. fixes #17894

Note: See TracTickets for help on using tickets.