Make WordPress Core

Ticket #44388: 44388.patch

File 44388.patch, 2.1 KB (added by enrico.sorcinelli, 7 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
    index ea2d0d1..95dc27b 100644
    a b class WP_REST_Terms_Controller extends WP_REST_Controller { 
    159159         */
    160160        public function get_items( $request ) {
    161161
     162                // Check for taxonomy param.
     163                $taxonomy = isset( $request['taxonomy'] ) ? $request['taxonomy'] : $this->taxonomy;
     164
     165                $taxonomy_obj = get_taxonomy( $taxonomy );
     166
     167                if ( false === $taxonomy_obj ) {
     168                        return new WP_Error( 'invalid-taxonomy', sprintf( __( "Invalid '%s' taxonomy" ), $taxonomy ), array( 'status' => 405 ) );
     169                }
     170
     171                $this->taxonomy = $taxonomy;
     172
    162173                // Retrieve the list of registered collection query parameters.
    163174                $registered = $this->get_collection_params();
    164175
    class WP_REST_Terms_Controller extends WP_REST_Controller { 
    208219                        $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
    209220                }
    210221
    211                 $taxonomy_obj = get_taxonomy( $this->taxonomy );
    212 
    213222                if ( $taxonomy_obj->hierarchical && isset( $registered['parent'], $request['parent'] ) ) {
    214223                        if ( 0 === $request['parent'] ) {
    215224                                // Only query top-level terms.
    class WP_REST_Terms_Controller extends WP_REST_Controller { 
    985994                        ),
    986995                );
    987996
     997                $query_params['taxonomy'] = array(
     998                        'description' => __( 'Taxonomy.' ),
     999                        'type'        => 'string',
     1000                        'default'     => null,
     1001                );
     1002
    9881003                /**
    9891004                 * Filter collection parameters for the terms controller.
    9901005                 *
  • tests/phpunit/tests/rest-api/rest-tags-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php
    index f2cd6a7..48026dd 100644
    a b class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 
    9191                                'post',
    9292                                'search',
    9393                                'slug',
     94                                'taxonomy',
    9495                        ), $keys
    9596                );
    9697        }