-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REST API: Support search_columns argument in the user endpoint #67330
Conversation
@@ -5,6 +5,6 @@ export const BASE_QUERY = { | |||
|
|||
export const AUTHORS_QUERY = { | |||
who: 'authors', | |||
per_page: 50, | |||
per_page: 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason to limit this to 50, I just put 100 which I believe is the max.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember the exact reason; it was probably just an arbitrary number we chose. I'll have a better look tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. The 50
was just an arbitrary number. It might affect initial loading for the post editor on sites with a large user sets, but it's hard to measure locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to revert that if you think it's better for now, it's kind of outside the scope of the current PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep it. The query only fetches the id,name
fields; the response size difference between 50 and 100 should be minimal.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +11 B (0%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
A couple of surface notes:
|
I think this has no impact at all since it's the "search_columns" for WP_Query is already used in the search endpoint. It's just using the default value when the user has the "list_users" capability, otherwise it's using
My guess is that it was just not requested. Even the posts endpoint one is a recent addition https://core.trac.wordpress.org/ticket/43867 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some initial notes. Currently, trying to come dummy data generation method to actually test the fix :)
$search_columns_mapping = array( | ||
'id' => 'ID', | ||
'username' => 'user_login', | ||
'slug' => 'user_nicename', | ||
'email' => 'user_email', | ||
'name' => 'display_name', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question (non-blocking): The post controllers don't map these values; should we follow the same example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I think it's a mistake that they're not mapped in the posts controller. I think the arguments should match the "fields" that are present in the schema and also the _fields
argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the arguments should match the "fields" that are present in the schema and also the _fields argument.
Agreed. Just double checking for the record :)
lib/compat/wordpress-6.8/class-gutenberg-rest-user-controller.php
Outdated
Show resolved
Hide resolved
Flaky tests detected in 05433a6. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12048455541
|
I've updated the testing instructions. Props again to @claudiulodro for originally reporting the bug. |
While I get the use case described in the PR, someone could also search by email. This is subjective, but to be honest personally I usually go by emails at similar cases, as they are unique. Having said that, I think the By the way, you can test way easier by adjusting this value here. I just set it to 1 and had to create a single user. |
For me it doesn't make sense to search by email unless you actually show the emails in the results which we don't. |
lib/compat/wordpress-6.8/class-gutenberg-rest-user-controller.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some small comments, but this looks good. Thank you!
Fair enough. Ok. |
Re-updated search columns: The |
Co-authored-by: George Mamadashvili <[email protected]>
05433a6
to
289a0d0
Compare
…ress#67330) Co-authored-by: youknowriad <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: ntsekouras <[email protected]> Co-authored-by: mreishus <[email protected]> Co-authored-by claudiulodro < [email protected]>
Co-authored-by: youknowriad <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: ntsekouras <[email protected]> Co-authored-by: mreishus <[email protected]> Co-authored-by claudiulodro < [email protected]>
closes #67331
What?
There's a weird bug in the "post author" selector in the editor. Say you have a site with thousands of users, and imagine these users all have emails that end with
@automattic.com
:). This means that if you search for an author named "Matt" in the post author selector, you'll never be able to assign the post to that person. The reason is the following:What a funny 🐛 right :)
This PR solves this by adding support for a
search_columns
argument to the user endpoint. A similar argument is already supported for the posts endpoints.Testing Instructions
Based on #38791, props to @claudiulodro!
example.com
email address.User Example
.example
author.A snippet for user generation via WP CLI
Screenshot