[wp-hackers] get_users() fields array parameter
Chip Bennett
chip at chipbennett.net
Thu Dec 13 17:40:24 UTC 2012
FYI: http://core.trac.wordpress.org/ticket/22921
On Thu, Dec 13, 2012 at 12:12 PM, Matt Martz <matt at sivel.net> wrote:
> I do however see no reason that we couldn't modify that code, to do what
> many may think it should.
>
> If it isn't an array, and it isn't the string 'all', then why not cast it
> to an array? Or at least if it is a whitelisted field, cast it to an
> array. I cannot see where anyone using it is actually benefiting from the
> fact that if it is not an array or not 'all' that it falls back to the ID.
> But I could be missing some history here...
>
> --
> Matt Martz
> matt at sivel.net
>
>
> On Thursday, December 13, 2012 at 11:07 AM, Chip Bennett wrote:
>
> > Thanks, Matt. So it'll be a Codex update, then.
> >
> > And #facepalm to me, for not looking in source before asking. :)
> >
> > Chip
> >
> >
> > On Thu, Dec 13, 2012 at 12:03 PM, Matt Martz <matt at sivel.net (mailto:
> matt at sivel.net)> wrote:
> >
> > > Looking at the code for WP_User_Query::prepare_query()
> > >
> > > The 'fields' arg needs to be an array, to achieve what you want.
> > >
> > > get_users( array( 'fields' => array( 'user_email' ) ) )
> > >
> > > If it is not an array, and not the string 'all', then it queries for
> ID.
> > >
> > >
> http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/user.php#L396
> > >
> > > --
> > > Matt Martz
> > > matt at sivel.net (mailto:matt at sivel.net)
> > >
> > >
> > > On Thursday, December 13, 2012 at 10:58 AM, Chip Bennett wrote:
> > >
> > > > I recently tried passing 'fields' => 'user_email' in the arguments
> array
> > > > for get_users(). Instead of returning user email addresses as
> expected,
> > > >
> > >
> > > the
> > > > call returned user IDs.
> > > >
> > > > var_dump( get_users( array( 'fields' => 'user_email' ) ) );
> > > >
> > > > outputs:
> > > >
> > > > array(3) { [0]=> string(2) "10" [1]=> string(1) "9" [2]=> string(1)
> "1" }
> > > >
> > > > According to the Codex, this should be an array of user
> > > > emails<
> > > >
> > >
> > >
> http://codex.wordpress.org/Function_Reference/get_users#Example_for_Array_of_Values_when_single_Field_specified
> > > >
> > > > .
> > > >
> > > > Is this a bug? Can anyone reproduce? (I found nothing related in
> Trac.)
> > > Or
> > > > am I doing something wrong?
> > > >
> > > > Note, if I make 'fields' an array, I get an array of objects that
> *do*
> > > > consist of user_email values:
> > > >
> > > > var_dump( get_users( array( 'fields' => array( 'user_email' ) ) ) );
> > > >
> > > > outputs:
> > > >
> > > > array(3) { [0]=> object(stdClass)#620 (1) { ["user_email"]=>
> string(22) "
> > > > testeditor at example.com (mailto:testeditor at example.com)" } [1]=>
> > > >
> > >
> > > object(stdClass)#621 (1) { ["user_email"]=>
> > > > string(26) "testsubscriber at example.com (mailto:
> testsubscriber at example.com) (mailto:
> > >
> > > testsubscriber at example.com (mailto:testsubscriber at example.com))" }
> [2]=> object(stdClass)#622 (1) {
> > > > ["user_email"]=> string(20) "chip at chipbennett.net (mailto:
> chip at chipbennett.net) (mailto:
> > >
> > > chip at chipbennett.net (mailto:chip at chipbennett.net))" } }
> > > >
> > > > Just doing a sanity check before submitting a bug report, and/or
> updating
> > > > the Codex.
> > > >
> > > > Thanks,
> > > >
> > > > Chip
> > > > _______________________________________________
> > > > wp-hackers mailing list
> > > > wp-hackers at lists.automattic.com (mailto:
> wp-hackers at lists.automattic.com)
> > > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > > >
> > >
> > >
> > >
> > > _______________________________________________
> > > wp-hackers mailing list
> > > wp-hackers at lists.automattic.com (mailto:
> wp-hackers at lists.automattic.com)
> > > http://lists.automattic.com/mailman/listinfo/wp-hackers
> > >
> >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com (mailto:wp-hackers at lists.automattic.com)
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> >
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list