-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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: Add support for search_columns argument to the REST API #7909
base: trunk
Are you sure you want to change the base?
Conversation
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 Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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.
This looks good to me. It would be nice to add a PHPUnit test that confirms that users without list_users
caps are not able to use the user_email
search column.
@youknowriad, here's the patch. diff --git tests/phpunit/tests/rest-api/rest-users-controller.php tests/phpunit/tests/rest-api/rest-users-controller.php
index 009200f401..fcaf7cdf5f 100644
--- tests/phpunit/tests/rest-api/rest-users-controller.php
+++ tests/phpunit/tests/rest-api/rest-users-controller.php
@@ -713,6 +713,9 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$this->assertCount( 0, $response->get_data() );
}
+ /**
+ * @ticket 62596
+ */
public function test_get_items_search_columns() {
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
$request->set_param( 'search', 'yololololo' );
@@ -746,6 +749,27 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$this->assertCount( 1, $response->get_data() );
}
+ /**
+ * @ticket 62596
+ */
+ public function test_get_items_seach_columns_without_permission() {
+ self::factory()->user->create(
+ array(
+ 'display_name' => 'Adam',
+ 'user_email' => 'yololololo@example.localhost',
+ )
+ );
+
+ // Test user without sufficient capabilities - 'list_users'.
+ wp_set_current_user( self::$editor );
+
+ $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
+ $request->set_param( 'search', 'yololololo' );
+ $request->set_param( 'search_columns', 'email' );
+ $response = rest_get_server()->dispatch( $request );
+ $this->assertCount( 0, $response->get_data() );
+ }
+
public function test_get_items_slug_query() {
wp_set_current_user( self::$user ); |
Backports to change originally made in WordPress/gutenberg#67330
This adds support to search_columns to the user controller, mirroring a change that was done in the past for the post controller.
Trac ticket: https://core.trac.wordpress.org/ticket/62596
Todo