Changeset 41760
- Timestamp:
- 10/05/2017 12:36:43 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-term-query.php
r41377 r41760 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 { … … 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'. … … 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_for_query', $this->query_vars['slug__in'] ) ); 848 $orderby = "FIELD( t.slug, '" . $slugs . "')"; 844 849 } elseif ( 'none' == $_orderby ) { 845 850 $orderby = ''; -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r41731 r41760 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 … … 2110 2111 'relevance', 2111 2112 'slug', 2113 'include_slugs', 2112 2114 'title', 2113 2115 ), -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r41737 r41760 186 186 if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) { 187 187 $prepared_args[ $wp_param ] = $request[ $api_param ]; 188 } 189 } 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'] ]; 188 198 } 189 199 } … … 933 943 'name', 934 944 'slug', 945 'include_slugs', 935 946 'term_group', 936 947 'description', -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r41731 r41760 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', … … 1339 1340 'registered_date', 1340 1341 'slug', 1342 'include_slugs', 1341 1343 'email', 1342 1344 'url', -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r41737 r41760 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(); -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r40605 r41760 597 597 $this->assertEquals( 'abc', $data[1]['slug'] ); 598 598 $this->assertPostsOrderedBy( '{posts}.post_name DESC' ); 599 } 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'] ); 599 617 } 600 618 -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r40376 r41760 249 249 $this->assertEquals( 'Apple', $data[1]['name'] ); 250 250 $this->assertEquals( 'Cantaloupe', $data[2]['name'] ); 251 } 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'] ); 251 267 } 252 268 -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r41226 r41760 408 408 $data = $response->get_data(); 409 409 $this->assertEquals( $low_id, $data[0]['id'] ); 410 } 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'] ); 410 428 } 411 429 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r41678 r41760 285 285 "relevance", 286 286 "slug", 287 "include_slugs", 287 288 "title" 288 289 ], … … 906 907 "relevance", 907 908 "slug", 909 "include_slugs", 908 910 "title", 909 911 "menu_order" … … 1444 1446 "relevance", 1445 1447 "slug", 1448 "include_slugs", 1446 1449 "title" 1447 1450 ], … … 2024 2027 "name", 2025 2028 "slug", 2029 "include_slugs", 2026 2030 "term_group", 2027 2031 "description", … … 2267 2271 "name", 2268 2272 "slug", 2273 "include_slugs", 2269 2274 "term_group", 2270 2275 "description", … … 2496 2501 "registered_date", 2497 2502 "slug", 2503 "include_slugs", 2498 2504 "email", 2499 2505 "url"
Note: See TracChangeset
for help on using the changeset viewer.