Opened 16 years ago
Closed 16 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: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (5)
#1
@
16 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.
fix get_users_of_blog to also return user id as ID