[wp-trac] [WordPress Trac] #22921: Allow get_users() to return array of values via 'fields' parameter

WordPress Trac noreply at wordpress.org
Sat Dec 15 15:47:35 UTC 2012


#22921: Allow get_users() to return array of values via 'fields' parameter
-------------------------------------+------------------------------
 Reporter:  chipbennett              |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Users                    |     Version:  3.5
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |
-------------------------------------+------------------------------

Comment (by chipbennett):

 Replying to [comment:5 DavidAnderson]:
 > dd32: Yes, that's right - it'll break code that uses the existing
 function. I've written such code. The existing function does something
 useful, and works whilst doing it, and people are using it. There's a
 real-world cost to breaking that.

 Let's consider the purpose of the `'fields'` array parameter: to return
 ''only the fields specified'', instead of ''all'' user data. The code
 provides two forms of output, based on the type of input:

 1. An array of ''objects'' comprised of one or more values, if
 '''`'fields' => array( $fields )`''' is passed
 2. An array of ''values'', if '''`'fields' => $field`''' is passed

 Thus, the only way this patch would break existing code is if someone
 passed a field other than `'ID'` for `'fields'`, e.g.:

 {{{
 $user_IDs = get_users( array( 'fields' => 'user_email' ) );
 }}}

 ...and then used the output as if an array of '''IDs''' was the expected
 return value.

 That just doesn't make logical sense. Why would someone pass
 '''`'user_email'`''' as the value for `'fields'`, and then subsequently
 use the output as if '''`'ID'`''' had been passed?

 Any normal developer would look at that output and do one of two things:

 1. Change the function call to '''`'fields' => 'ID'`''', if the
 ''desired'' return value is `'ID'`
 2. Change the function call to pass '''`'fields' => array( 'user_email'
 )`''' if the ''desired'' return value is `'user_email'`

 I contend that if a developer leaves the code as-is, the ''user code'' is
 at fault, and such a use case shouldn't be something that keeps the core
 function itself from being improved.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22921#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list