WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#9020 closed defect (bug) (fixed)

Add standard ID value (for user id's) to output of get_users_of_blog() to be compatible

Reported by: jeremyclarke Owned by: jeremyclarke
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.7
Component: General Keywords: has-patch, tested
Focuses: Cc:

Description

Currently the get_users_of_blog() function (which fetches all users of a given blog for WPMU but is also the only API way to get all the users at once on a normal wp install) returns an array of objects containing the most generally relevant information about users, but not the full contents of their row in the users and user_meta tables (it gets id, login, display name, email and permissions).

Unfortunately and a bit insanely, when fetching the user id it gets the user_id field from the user meta table rather than the plain ID from the users table. Pretty much everywhere in wp the ID label is used for checking IDs, and so the output of get_users_of_blog is pretty much useless except if you are writing custom functions (probably what it was designed for).

This patch does just one little thing, in the SQL inside get_users_of_blog() it fetches both the user_id from user meta table AND the ID from the users table. This way the output can be used with other user API functions when appropriate and it is backwards compatible with whatever people were already doign with the user_id field.

Admittedly it returns redundant information but IMHO its so worth it because it makes the function much more usefull and less confusing/insane.

[NOTE: This function should be replaced with a more general get_users() function that accepts get_posts/get_terms style arguments like blog=1 or role=admin. But this will make it more useful in the meantime]

I can't think of a reason not to commit this. Thanks,

Attachments (2)

get_users_of_blog_feb2-09.diff (867 bytes) - added by jeremyclarke 5 years ago.
fix get_users_of_blog to also return user id as ID
get_users_of_blog_with_ID.9020.diff (860 bytes) - added by filosofo 5 years ago.

Download all attachments as: .zip

Change History (5)

jeremyclarke5 years ago

fix get_users_of_blog to also return user id as ID

comment:1 filosofo5 years ago

Running this with about 5000 users and caching turned off, I get about a 20% performance improvement by aliasing user_id: "user_id AS ID," as in my attached patch.

comment:2 jeremyclarke5 years ago

  • Keywords tested added

@filosofo would you believe I didn't know you could do that with a value that was already there? Thanks for the optimization.

comment:3 ryan5 years ago

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

(In [10595]) Include ID in get_users_of_blog() results. Props jeremyclarke and filosofo. fixes #9020

Note: See TracTickets for help on using tickets.