Make WordPress Core

Ticket #40826: slugs-patch.diff

File slugs-patch.diff, 12.1 KB (added by wonderboymusic, 8 years ago)
  • src/wp-includes/class-wp-term-query.php

    diff --git src/wp-includes/class-wp-term-query.php src/wp-includes/class-wp-term-query.php
    index 74386bc9ab..c71735286e 100644
    class WP_Term_Query { 
    106106         *     @type string       $orderby                Field(s) to order terms by. Accepts term fields ('name',
    107107         *                                                'slug', 'term_group', 'term_id', 'id', 'description'),
    108108         *                                                'count' for term taxonomy count, 'include' to match the
    109          *                                                'order' of the $include param, 'meta_value', 'meta_value_num',
    110          *                                                the value of `$meta_key`, the array keys of `$meta_query`, or
    111          *                                                'none' to omit the ORDER BY clause. Defaults to 'name'.
     109         *                                                'order' of the $include param, 'slugs' to match the 'order'
     110         *                                                of the $slug param (when it is an array), 'meta_value',
     111         *                                                'meta_value_num', the value of `$meta_key`, the array keys
     112         *                                                of `$meta_query`, or 'none' to omit the ORDER BY clause.
     113         *                                                Defaults to 'name'.
    112114         *     @type string       $order                  Whether to order terms in ascending or descending order.
    113115         *                                                Accepts 'ASC' (ascending) or 'DESC' (descending).
    114116         *                                                Default 'ASC'.
    class WP_Term_Query { 
    842844                } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) {
    843845                        $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) );
    844846                        $orderby = "FIELD( t.term_id, $include )";
     847                } elseif ( 'slugs' == $_orderby && ! empty( $this->query_vars['slug'] ) && is_array( $this->query_vars['slug'] ) ) {
     848                        $slugs = implode( "', '", array_map( 'sanitize_title', $this->query_vars['slug'] ) );
     849                        $orderby = "FIELD( t.slug, '" . $slugs . "')";
    845850                } elseif ( 'none' == $_orderby ) {
    846851                        $orderby = '';
    847852                } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) {
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
    index 39593cbe3e..e03aaa6cdd 100644
    class WP_REST_Posts_Controller extends WP_REST_Controller { 
    892892                                'id'      => 'ID',
    893893                                'include' => 'post__in',
    894894                                'slug'    => 'post_name',
     895                                'slugs'   => 'post_name__in',
    895896                        );
    896897
    897898                        if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) {
    class WP_REST_Posts_Controller extends WP_REST_Controller { 
    21382139                                'parent',
    21392140                                'relevance',
    21402141                                'slug',
     2142                                'slugs',
    21412143                                'title',
    21422144                        ),
    21432145                );
  • src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
    index 299b034329..3ec6e5f579 100644
    class WP_REST_Terms_Controller extends WP_REST_Controller { 
    951951                                'include',
    952952                                'name',
    953953                                'slug',
     954                                'slugs',
    954955                                'term_group',
    955956                                'description',
    956957                                'count',
  • src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
    index 63fb4e9e99..bfbea9a295 100644
    class WP_REST_Users_Controller extends WP_REST_Controller { 
    249249                                'name'            => 'display_name',
    250250                                'registered_date' => 'registered',
    251251                                'slug'            => 'user_nicename',
     252                                'slugs'           => 'nicename__in',
    252253                                'email'           => 'user_email',
    253254                                'url'             => 'user_url',
    254255                        );
    class WP_REST_Users_Controller extends WP_REST_Controller { 
    13511352                                'name',
    13521353                                'registered_date',
    13531354                                'slug',
     1355                                'slugs',
    13541356                                'email',
    13551357                                'url',
    13561358                        ),
  • tests/phpunit/tests/rest-api/rest-categories-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-categories-controller.php tests/phpunit/tests/rest-api/rest-categories-controller.php
    index fbf7d06018..e9b70ca075 100644
    class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas 
    287287                $this->assertEquals( 'Cantaloupe', $data[2]['name'] );
    288288        }
    289289
     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', '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
    290306        protected function post_with_categories() {
    291307                $post_id = $this->factory->post->create();
    292308                $category1 = $this->factory->category->create( array(
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
    index c86879cffc..889eee77a8 100644
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    598598                $this->assertPostsOrderedBy( '{posts}.post_name DESC' );
    599599        }
    600600
     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', '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
    601619        public function test_get_items_with_orderby_relevance() {
    602620                $id1 = $this->factory->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish' ) );
    603621                $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

    diff --git tests/phpunit/tests/rest-api/rest-tags-controller.php tests/phpunit/tests/rest-api/rest-tags-controller.php
    index fccc4d702d..9c2f5613ab 100644
    class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 
    250250                $this->assertEquals( 'Cantaloupe', $data[2]['name'] );
    251251        }
    252252
     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', '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
    253269        public function test_get_items_post_args() {
    254270                $post_id = $this->factory->post->create();
    255271                $tag1 = $this->factory->tag->create( array( 'name' => 'DC' ) );
  • tests/phpunit/tests/rest-api/rest-users-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-users-controller.php tests/phpunit/tests/rest-api/rest-users-controller.php
    index 44853aa13a..9f17882d54 100644
    class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { 
    409409                $this->assertEquals( $low_id, $data[0]['id'] );
    410410        }
    411411
     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', '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
    412430        public function test_get_items_orderby_email() {
    413431                wp_set_current_user( self::$user );
    414432
  • tests/qunit/fixtures/wp-api-generated.js

    diff --git tests/qunit/fixtures/wp-api-generated.js tests/qunit/fixtures/wp-api-generated.js
    index 69e2375563..38086a9dbc 100644
    mockedApiResponse.Schema = { 
    284284                                "parent",
    285285                                "relevance",
    286286                                "slug",
     287                                "slugs",
    287288                                "title"
    288289                            ],
    289290                            "description": "Sort collection by object attribute.",
    mockedApiResponse.Schema = { 
    905906                                "parent",
    906907                                "relevance",
    907908                                "slug",
     909                                "slugs",
    908910                                "title",
    909911                                "menu_order"
    910912                            ],
    mockedApiResponse.Schema = { 
    14431445                                "parent",
    14441446                                "relevance",
    14451447                                "slug",
     1448                                "slugs",
    14461449                                "title"
    14471450                            ],
    14481451                            "description": "Sort collection by object attribute.",
    mockedApiResponse.Schema = { 
    20232026                                "include",
    20242027                                "name",
    20252028                                "slug",
     2029                                "slugs",
    20262030                                "term_group",
    20272031                                "description",
    20282032                                "count"
    mockedApiResponse.Schema = { 
    22662270                                "include",
    22672271                                "name",
    22682272                                "slug",
     2273                                "slugs",
    22692274                                "term_group",
    22702275                                "description",
    22712276                                "count"
    mockedApiResponse.Schema = { 
    24952500                                "name",
    24962501                                "registered_date",
    24972502                                "slug",
     2503                                "slugs",
    24982504                                "email",
    24992505                                "url"
    25002506                            ],