Ticket #40826: 40826.3.diff
File 40826.3.diff, 12.0 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-term-query.php
87 87 * @since 4.6.0 88 88 * @since 4.6.0 Introduced 'term_taxonomy_id' parameter. 89 89 * @since 4.7.0 Introduced 'object_ids' parameter. 90 * @since 4.9.0 Added 'slug__in' support for 'orderby'. 90 91 * 91 92 * @param string|array $query { 92 93 * Optional. Array or query string of term query parameters. Default empty. … … 98 99 * @type string $orderby Field(s) to order terms by. Accepts term fields ('name', 99 100 * 'slug', 'term_group', 'term_id', 'id', 'description', 'parent'), 100 101 * 'count' for term taxonomy count, 'include' to match the 101 * 'order' of the $include param, 'meta_value', 'meta_value_num', 102 * 'order' of the $include param, 'slug__in' to match the 103 * 'order' of the $slug param, 'meta_value', 'meta_value_num', 102 104 * the value of `$meta_key`, the array keys of `$meta_query`, or 103 105 * 'none' to omit the ORDER BY clause. Defaults to 'name'. 104 106 * @type string $order Whether to order terms in ascending or descending order. … … 841 843 } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) { 842 844 $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) ); 843 845 $orderby = "FIELD( t.term_id, $include )"; 846 } elseif ( 'slug__in' == $_orderby && ! empty( $this->query_vars['slug'] ) && is_array( $this->query_vars['slug'] ) ) { 847 $slugs = implode( "', '", array_map( 'sanitize_title', $this->query_vars['slug__in'] ) ); 848 $orderby = "FIELD( t.slug, '" . $slugs . "')"; 844 849 } elseif ( 'none' == $_orderby ) { 845 850 $orderby = ''; 846 851 } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) { -
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
874 874 // Map to proper WP_Query orderby param. 875 875 if ( isset( $query_args['orderby'] ) && isset( $request['orderby'] ) ) { 876 876 $orderby_mappings = array( 877 'id' => 'ID', 878 'include' => 'post__in', 879 'slug' => 'post_name', 877 'id' => 'ID', 878 'include' => 'post__in', 879 'slug' => 'post_name', 880 'include_slugs' => 'post_name__in', 880 881 ); 881 882 882 883 if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { … … 2109 2110 'parent', 2110 2111 'relevance', 2111 2112 'slug', 2113 'include_slugs', 2112 2114 'title', 2113 2115 ), 2114 2116 ); -
src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
188 188 } 189 189 } 190 190 191 if ( isset( $prepared_args['orderby'] ) && isset( $request['orderby'] ) ) { 192 $orderby_mappings = array( 193 'include_slugs' => 'slug__in', 194 ); 195 196 if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { 197 $prepared_args['orderby'] = $orderby_mappings[ $request['orderby'] ]; 198 } 199 } 200 191 201 if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) { 192 202 $prepared_args['offset'] = $request['offset']; 193 203 } else { … … 932 942 'include', 933 943 'name', 934 944 'slug', 945 'include_slugs', 935 946 'term_group', 936 947 'description', 937 948 'count', -
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
243 243 'name' => 'display_name', 244 244 'registered_date' => 'registered', 245 245 'slug' => 'user_nicename', 246 'include_slugs' => 'nicename__in', 246 247 'email' => 'user_email', 247 248 'url' => 'user_url', 248 249 ); … … 1338 1339 'name', 1339 1340 'registered_date', 1340 1341 'slug', 1342 'include_slugs', 1341 1343 'email', 1342 1344 'url', 1343 1345 ), -
tests/phpunit/tests/rest-api/rest-categories-controller.php
287 287 $this->assertEquals( 'Cantaloupe', $data[2]['name'] ); 288 288 } 289 289 290 public function test_get_items_orderby_slugs() { 291 $this->factory->category->create( array( 'name' => 'Burrito' ) ); 292 $this->factory->category->create( array( 'name' => 'Taco' ) ); 293 $this->factory->category->create( array( 'name' => 'Chalupa' ) ); 294 295 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 296 $request->set_param( 'orderby', 'include_slugs' ); 297 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 298 $response = $this->server->dispatch( $request ); 299 $data = $response->get_data(); 300 $this->assertEquals( 200, $response->get_status() ); 301 $this->assertEquals( 'taco', $data[0]['slug'] ); 302 $this->assertEquals( 'burrito', $data[1]['slug'] ); 303 $this->assertEquals( 'chalupa', $data[2]['slug'] ); 304 } 305 290 306 protected function post_with_categories() { 291 307 $post_id = $this->factory->post->create(); 292 308 $category1 = $this->factory->category->create( array( -
tests/phpunit/tests/rest-api/rest-posts-controller.php
598 598 $this->assertPostsOrderedBy( '{posts}.post_name DESC' ); 599 599 } 600 600 601 public function test_get_items_with_orderby_slugs() { 602 $slugs = array( 'burrito', 'taco', 'chalupa' ); 603 foreach ( $slugs as $slug ) { 604 $this->factory->post->create( array( 'post_title' => $slug, 'post_name' => $slug, 'post_status' => 'publish' ) ); 605 } 606 607 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 608 $request->set_param( 'orderby', 'include_slugs' ); 609 $request->set_param( 'slug', array( 'taco', 'chalupa', 'burrito' ) ); 610 611 $response = $this->server->dispatch( $request ); 612 $data = $response->get_data(); 613 614 $this->assertEquals( 'taco', $data[0]['slug'] ); 615 $this->assertEquals( 'chalupa', $data[1]['slug'] ); 616 $this->assertEquals( 'burrito', $data[2]['slug'] ); 617 } 618 601 619 public function test_get_items_with_orderby_relevance() { 602 620 $id1 = $this->factory->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish' ) ); 603 621 $id2 = $this->factory->post->create( array( 'post_title' => 'Title is', 'post_content' => 'Content is less relevant', 'post_status' => 'publish' ) ); -
tests/phpunit/tests/rest-api/rest-tags-controller.php
250 250 $this->assertEquals( 'Cantaloupe', $data[2]['name'] ); 251 251 } 252 252 253 public function test_get_items_orderby_slugs() { 254 $this->factory->tag->create( array( 'name' => 'Burrito' ) ); 255 $this->factory->tag->create( array( 'name' => 'Taco' ) ); 256 $this->factory->tag->create( array( 'name' => 'Chalupa' ) ); 257 258 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 259 $request->set_param( 'orderby', 'include_slugs' ); 260 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 261 $response = $this->server->dispatch( $request ); 262 $data = $response->get_data(); 263 $this->assertEquals( 200, $response->get_status() ); 264 $this->assertEquals( 'taco', $data[0]['slug'] ); 265 $this->assertEquals( 'burrito', $data[1]['slug'] ); 266 $this->assertEquals( 'chalupa', $data[2]['slug'] ); 267 } 268 253 269 public function test_get_items_post_args() { 254 270 $post_id = $this->factory->post->create(); 255 271 $tag1 = $this->factory->tag->create( array( 'name' => 'DC' ) ); -
tests/phpunit/tests/rest-api/rest-users-controller.php
409 409 $this->assertEquals( $low_id, $data[0]['id'] ); 410 410 } 411 411 412 public function test_get_items_orderby_slugs() { 413 wp_set_current_user( self::$user ); 414 415 $this->factory->user->create( array( 'user_nicename' => 'burrito' ) ); 416 $this->factory->user->create( array( 'user_nicename' => 'taco' ) ); 417 $this->factory->user->create( array( 'user_nicename' => 'chalupa' ) ); 418 419 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 420 $request->set_param( 'orderby', 'include_slugs' ); 421 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 422 $response = $this->server->dispatch( $request ); 423 $data = $response->get_data(); 424 425 $this->assertEquals( 'taco', $data[0]['slug'] ); 426 $this->assertEquals( 'burrito', $data[1]['slug'] ); 427 $this->assertEquals( 'chalupa', $data[2]['slug'] ); 428 } 429 412 430 public function test_get_items_orderby_email() { 413 431 wp_set_current_user( self::$user ); 414 432 -
tests/qunit/fixtures/wp-api-generated.js
284 284 "parent", 285 285 "relevance", 286 286 "slug", 287 "include_slugs", 287 288 "title" 288 289 ], 289 290 "description": "Sort collection by object attribute.", … … 905 906 "parent", 906 907 "relevance", 907 908 "slug", 909 "include_slugs", 908 910 "title", 909 911 "menu_order" 910 912 ], … … 1443 1445 "parent", 1444 1446 "relevance", 1445 1447 "slug", 1448 "include_slugs", 1446 1449 "title" 1447 1450 ], 1448 1451 "description": "Sort collection by object attribute.", … … 2023 2026 "include", 2024 2027 "name", 2025 2028 "slug", 2029 "include_slugs", 2026 2030 "term_group", 2027 2031 "description", 2028 2032 "count" … … 2266 2270 "include", 2267 2271 "name", 2268 2272 "slug", 2273 "include_slugs", 2269 2274 "term_group", 2270 2275 "description", 2271 2276 "count" … … 2495 2500 "name", 2496 2501 "registered_date", 2497 2502 "slug", 2503 "include_slugs", 2498 2504 "email", 2499 2505 "url" 2500 2506 ],