[wp-trac] [WordPress Trac] #17894: WP_User class uses ID as username when $id = null

WordPress Trac wp-trac at lists.automattic.com
Sat Jun 25 20:03:27 UTC 2011


#17894: WP_User class uses ID as username when $id = null
--------------------------+-----------------------------
 Reporter:  kawauso       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.1.3
 Severity:  normal        |   Keywords:  has-patch
--------------------------+-----------------------------
 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>';
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17894>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list