3 * REST API: WP_REST_Terms_Controller class
11 * Core class used to managed terms associated with a taxonomy via the REST API.
15 * @see WP_REST_Controller
17 class WP_REST_Terms_Controller extends WP_REST_Controller {
29 * Instance of a term meta fields object.
33 * @var WP_REST_Term_Meta_Fields
38 * Column to have the terms be sorted by.
44 protected $sort_column;
47 * Number of terms that were found.
53 protected $total_terms;
61 * @param string $taxonomy Taxonomy key.
63 public function __construct( $taxonomy ) {
64 $this->taxonomy = $taxonomy;
65 $this->namespace = 'wp/v2';
66 $tax_obj = get_taxonomy( $taxonomy );
67 $this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name;
69 $this->meta = new WP_REST_Term_Meta_Fields( $taxonomy );
73 * Registers the routes for the objects of the controller.
78 * @see register_rest_route()
80 public function register_routes() {
82 register_rest_route( $this->namespace, '/' . $this->rest_base, array(
84 'methods' => WP_REST_Server::READABLE,
85 'callback' => array( $this, 'get_items' ),
86 'permission_callback' => array( $this, 'get_items_permissions_check' ),
87 'args' => $this->get_collection_params(),
90 'methods' => WP_REST_Server::CREATABLE,
91 'callback' => array( $this, 'create_item' ),
92 'permission_callback' => array( $this, 'create_item_permissions_check' ),
93 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
95 'schema' => array( $this, 'get_public_item_schema' ),
98 register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
101 'description' => __( 'Unique identifier for the term.' ),
106 'methods' => WP_REST_Server::READABLE,
107 'callback' => array( $this, 'get_item' ),
108 'permission_callback' => array( $this, 'get_item_permissions_check' ),
110 'context' => $this->get_context_param( array( 'default' => 'view' ) ),
114 'methods' => WP_REST_Server::EDITABLE,
115 'callback' => array( $this, 'update_item' ),
116 'permission_callback' => array( $this, 'update_item_permissions_check' ),
117 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
120 'methods' => WP_REST_Server::DELETABLE,
121 'callback' => array( $this, 'delete_item' ),
122 'permission_callback' => array( $this, 'delete_item_permissions_check' ),
127 'description' => __( 'Required to be true, as terms do not support trashing.' ),
131 'schema' => array( $this, 'get_public_item_schema' ),
136 * Checks if a request has access to read terms in the specified taxonomy.
141 * @param WP_REST_Request $request Full details about the request.
142 * @return bool|WP_Error True if the request has read access, otherwise false or WP_Error object.
144 public function get_items_permissions_check( $request ) {
145 $tax_obj = get_taxonomy( $this->taxonomy );
146 if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
149 if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) {
150 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) );
156 * Retrieves terms associated with a taxonomy.
161 * @param WP_REST_Request $request Full details about the request.
162 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
164 public function get_items( $request ) {
166 // Retrieve the list of registered collection query parameters.
167 $registered = $this->get_collection_params();
170 * This array defines mappings between public API query parameters whose
171 * values are accepted as-passed, and their internal WP_Query parameter
172 * name equivalents (some are the same). Only values which are also
173 * present in $registered will be set.
175 $parameter_mappings = array(
176 'exclude' => 'exclude',
177 'include' => 'include',
179 'orderby' => 'orderby',
181 'hide_empty' => 'hide_empty',
182 'per_page' => 'number',
183 'search' => 'search',
187 $prepared_args = array();
190 * For each known parameter which is both registered and present in the request,
191 * set the parameter's value on the query $prepared_args.
193 foreach ( $parameter_mappings as $api_param => $wp_param ) {
194 if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {
195 $prepared_args[ $wp_param ] = $request[ $api_param ];
199 if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) {
200 $prepared_args['offset'] = $request['offset'];
202 $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
205 $taxonomy_obj = get_taxonomy( $this->taxonomy );
207 if ( $taxonomy_obj->hierarchical && isset( $registered['parent'], $request['parent'] ) ) {
208 if ( 0 === $request['parent'] ) {
209 // Only query top-level terms.
210 $prepared_args['parent'] = 0;
212 if ( $request['parent'] ) {
213 $prepared_args['parent'] = $request['parent'];
219 * Filters the query arguments before passing them to get_terms().
221 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
223 * Enables adding extra arguments or setting defaults for a terms
224 * collection request.
228 * @link https://developer.wordpress.org/reference/functions/get_terms/
230 * @param array $prepared_args Array of arguments to be
231 * passed to get_terms().
232 * @param WP_REST_Request $request The current request.
234 $prepared_args = apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request );
236 if ( ! empty( $prepared_args['post'] ) ) {
237 $query_result = wp_get_object_terms( $prepared_args['post'], $this->taxonomy, $prepared_args );
239 // Used when calling wp_count_terms() below.
240 $prepared_args['object_ids'] = $prepared_args['post'];
242 $query_result = get_terms( $this->taxonomy, $prepared_args );
245 $count_args = $prepared_args;
247 unset( $count_args['number'], $count_args['offset'] );
249 $total_terms = wp_count_terms( $this->taxonomy, $count_args );
251 // wp_count_terms can return a falsy value when the term has no children.
252 if ( ! $total_terms ) {
258 foreach ( $query_result as $term ) {
259 $data = $this->prepare_item_for_response( $term, $request );
260 $response[] = $this->prepare_response_for_collection( $data );
263 $response = rest_ensure_response( $response );
265 // Store pagination values for headers.
266 $per_page = (int) $prepared_args['number'];
267 $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
269 $response->header( 'X-WP-Total', (int) $total_terms );
271 $max_pages = ceil( $total_terms / $per_page );
273 $response->header( 'X-WP-TotalPages', (int) $max_pages );
275 $base = add_query_arg( $request->get_query_params(), rest_url( $this->namespace . '/' . $this->rest_base ) );
277 $prev_page = $page - 1;
279 if ( $prev_page > $max_pages ) {
280 $prev_page = $max_pages;
283 $prev_link = add_query_arg( 'page', $prev_page, $base );
284 $response->link_header( 'prev', $prev_link );
286 if ( $max_pages > $page ) {
287 $next_page = $page + 1;
288 $next_link = add_query_arg( 'page', $next_page, $base );
290 $response->link_header( 'next', $next_link );
297 * Get the term, if the ID is valid.
301 * @param int $id Supplied ID.
302 * @return WP_Term|WP_Error Term object if ID is valid, WP_Error otherwise.
304 protected function get_term( $id ) {
305 $error = new WP_Error( 'rest_term_invalid', __( 'Term does not exist.' ), array( 'status' => 404 ) );
307 if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
311 if ( (int) $id <= 0 ) {
315 $term = get_term( (int) $id, $this->taxonomy );
316 if ( empty( $term ) || $term->taxonomy !== $this->taxonomy ) {
324 * Checks if a request has access to read or edit the specified term.
329 * @param WP_REST_Request $request Full details about the request.
330 * @return bool|WP_Error True if the request has read access for the item, otherwise false or WP_Error object.
332 public function get_item_permissions_check( $request ) {
333 $term = $this->get_term( $request['id'] );
334 if ( is_wp_error( $term ) ) {
338 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) {
339 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) );
345 * Gets a single term from a taxonomy.
350 * @param WP_REST_Request $request Full details about the request.
351 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
353 public function get_item( $request ) {
354 $term = $this->get_term( $request['id'] );
356 if ( is_wp_error( $term ) ) {
360 $response = $this->prepare_item_for_response( $term, $request );
362 return rest_ensure_response( $response );
366 * Checks if a request has access to create a term.
371 * @param WP_REST_Request $request Full details about the request.
372 * @return bool|WP_Error True if the request has access to create items, false or WP_Error object otherwise.
374 public function create_item_permissions_check( $request ) {
376 if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
380 $taxonomy_obj = get_taxonomy( $this->taxonomy );
381 if ( ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) {
382 return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) );
389 * Creates a single term in a taxonomy.
394 * @param WP_REST_Request $request Full details about the request.
395 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
397 public function create_item( $request ) {
398 if ( isset( $request['parent'] ) ) {
399 if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
400 return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
403 $parent = get_term( (int) $request['parent'], $this->taxonomy );
406 return new WP_Error( 'rest_term_invalid', __( "Parent term doesn't exist." ), array( 'status' => 400 ) );
410 $prepared_term = $this->prepare_item_for_database( $request );
412 $term = wp_insert_term( wp_slash( $prepared_term->name ), $this->taxonomy, wp_slash( (array) $prepared_term ) );
413 if ( is_wp_error( $term ) ) {
415 * If we're going to inform the client that the term already exists,
416 * give them the identifier for future use.
418 if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
419 $existing_term = get_term( $term_id, $this->taxonomy );
420 $term->add_data( $existing_term->term_id, 'term_exists' );
426 $term = get_term( $term['term_id'], $this->taxonomy );
429 * Fires after a single term is created or updated via the REST API.
431 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
435 * @param WP_Term $term Inserted or updated term object.
436 * @param WP_REST_Request $request Request object.
437 * @param bool $creating True when creating a term, false when updating.
439 do_action( "rest_insert_{$this->taxonomy}", $term, $request, true );
441 $schema = $this->get_item_schema();
442 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
443 $meta_update = $this->meta->update_value( $request['meta'], (int) $request['id'] );
445 if ( is_wp_error( $meta_update ) ) {
450 $fields_update = $this->update_additional_fields_for_object( $term, $request );
452 if ( is_wp_error( $fields_update ) ) {
453 return $fields_update;
456 $request->set_param( 'context', 'view' );
458 $response = $this->prepare_item_for_response( $term, $request );
459 $response = rest_ensure_response( $response );
461 $response->set_status( 201 );
462 $response->header( 'Location', rest_url( $this->namespace . '/' . $this->rest_base . '/' . $term->term_id ) );
468 * Checks if a request has access to update the specified term.
473 * @param WP_REST_Request $request Full details about the request.
474 * @return bool|WP_Error True if the request has access to update the item, false or WP_Error object otherwise.
476 public function update_item_permissions_check( $request ) {
477 $term = $this->get_term( $request['id'] );
478 if ( is_wp_error( $term ) ) {
482 if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
483 return new WP_Error( 'rest_cannot_update', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) );
490 * Updates a single term from a taxonomy.
495 * @param WP_REST_Request $request Full details about the request.
496 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
498 public function update_item( $request ) {
499 $term = $this->get_term( $request['id'] );
500 if ( is_wp_error( $term ) ) {
504 if ( isset( $request['parent'] ) ) {
505 if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
506 return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
509 $parent = get_term( (int) $request['parent'], $this->taxonomy );
512 return new WP_Error( 'rest_term_invalid', __( "Parent term doesn't exist." ), array( 'status' => 400 ) );
516 $prepared_term = $this->prepare_item_for_database( $request );
518 // Only update the term if we haz something to update.
519 if ( ! empty( $prepared_term ) ) {
520 $update = wp_update_term( $term->term_id, $term->taxonomy, wp_slash( (array) $prepared_term ) );
522 if ( is_wp_error( $update ) ) {
527 $term = get_term( $term->term_id, $this->taxonomy );
529 /* This action is documented in lib/endpoints/class-wp-rest-terms-controller.php */
530 do_action( "rest_insert_{$this->taxonomy}", $term, $request, false );
532 $schema = $this->get_item_schema();
533 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
534 $meta_update = $this->meta->update_value( $request['meta'], $term->term_id );
536 if ( is_wp_error( $meta_update ) ) {
541 $fields_update = $this->update_additional_fields_for_object( $term, $request );
543 if ( is_wp_error( $fields_update ) ) {
544 return $fields_update;
547 $request->set_param( 'context', 'view' );
549 $response = $this->prepare_item_for_response( $term, $request );
551 return rest_ensure_response( $response );
555 * Checks if a request has access to delete the specified term.
560 * @param WP_REST_Request $request Full details about the request.
561 * @return bool|WP_Error True if the request has access to delete the item, otherwise false or WP_Error object.
563 public function delete_item_permissions_check( $request ) {
564 $term = $this->get_term( $request['id'] );
565 if ( is_wp_error( $term ) ) {
569 if ( ! current_user_can( 'delete_term', $term->term_id ) ) {
570 return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) );
577 * Deletes a single term from a taxonomy.
582 * @param WP_REST_Request $request Full details about the request.
583 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
585 public function delete_item( $request ) {
586 $term = $this->get_term( $request['id'] );
587 if ( is_wp_error( $term ) ) {
591 $force = isset( $request['force'] ) ? (bool) $request['force'] : false;
593 // We don't support trashing for terms.
595 return new WP_Error( 'rest_trash_not_supported', __( 'Terms do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
598 $request->set_param( 'context', 'view' );
600 $previous = $this->prepare_item_for_response( $term, $request );
602 $retval = wp_delete_term( $term->term_id, $term->taxonomy );
605 return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) );
608 $response = new WP_REST_Response();
609 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
612 * Fires after a single term is deleted via the REST API.
614 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
618 * @param WP_Term $term The deleted term.
619 * @param WP_REST_Response $response The response data.
620 * @param WP_REST_Request $request The request sent to the API.
622 do_action( "rest_delete_{$this->taxonomy}", $term, $response, $request );
628 * Prepares a single term for create or update.
633 * @param WP_REST_Request $request Request object.
634 * @return object $prepared_term Term object.
636 public function prepare_item_for_database( $request ) {
637 $prepared_term = new stdClass;
639 $schema = $this->get_item_schema();
640 if ( isset( $request['name'] ) && ! empty( $schema['properties']['name'] ) ) {
641 $prepared_term->name = $request['name'];
644 if ( isset( $request['slug'] ) && ! empty( $schema['properties']['slug'] ) ) {
645 $prepared_term->slug = $request['slug'];
648 if ( isset( $request['taxonomy'] ) && ! empty( $schema['properties']['taxonomy'] ) ) {
649 $prepared_term->taxonomy = $request['taxonomy'];
652 if ( isset( $request['description'] ) && ! empty( $schema['properties']['description'] ) ) {
653 $prepared_term->description = $request['description'];
656 if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) {
658 $parent_term = get_term( (int) $request['parent'], $this->taxonomy );
660 if ( $parent_term ) {
661 $parent_term_id = $parent_term->term_id;
664 $prepared_term->parent = $parent_term_id;
668 * Filters term data before inserting term via the REST API.
670 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
674 * @param object $prepared_term Term object.
675 * @param WP_REST_Request $request Request object.
677 return apply_filters( "rest_pre_insert_{$this->taxonomy}", $prepared_term, $request );
681 * Prepares a single term output for response.
686 * @param obj $item Term object.
687 * @param WP_REST_Request $request Request object.
688 * @return WP_REST_Response $response Response object.
690 public function prepare_item_for_response( $item, $request ) {
692 $schema = $this->get_item_schema();
695 if ( ! empty( $schema['properties']['id'] ) ) {
696 $data['id'] = (int) $item->term_id;
699 if ( ! empty( $schema['properties']['count'] ) ) {
700 $data['count'] = (int) $item->count;
703 if ( ! empty( $schema['properties']['description'] ) ) {
704 $data['description'] = $item->description;
707 if ( ! empty( $schema['properties']['link'] ) ) {
708 $data['link'] = get_term_link( $item );
711 if ( ! empty( $schema['properties']['name'] ) ) {
712 $data['name'] = $item->name;
715 if ( ! empty( $schema['properties']['slug'] ) ) {
716 $data['slug'] = $item->slug;
719 if ( ! empty( $schema['properties']['taxonomy'] ) ) {
720 $data['taxonomy'] = $item->taxonomy;
723 if ( ! empty( $schema['properties']['parent'] ) ) {
724 $data['parent'] = (int) $item->parent;
727 if ( ! empty( $schema['properties']['meta'] ) ) {
728 $data['meta'] = $this->meta->get_value( $item->term_id, $request );
731 $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
732 $data = $this->add_additional_fields_to_object( $data, $request );
733 $data = $this->filter_response_by_context( $data, $context );
735 $response = rest_ensure_response( $data );
737 $response->add_links( $this->prepare_links( $item ) );
740 * Filters a term item returned from the API.
742 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
744 * Allows modification of the term data right before it is returned.
748 * @param WP_REST_Response $response The response object.
749 * @param object $item The original term object.
750 * @param WP_REST_Request $request Request used to generate the response.
752 return apply_filters( "rest_prepare_{$this->taxonomy}", $response, $item, $request );
756 * Prepares links for the request.
761 * @param object $term Term object.
762 * @return array Links for the given term.
764 protected function prepare_links( $term ) {
765 $base = $this->namespace . '/' . $this->rest_base;
768 'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
770 'collection' => array(
771 'href' => rest_url( $base ),
774 'href' => rest_url( sprintf( 'wp/v2/taxonomies/%s', $this->taxonomy ) ),
778 if ( $term->parent ) {
779 $parent_term = get_term( (int) $term->parent, $term->taxonomy );
781 if ( $parent_term ) {
782 $links['up'] = array(
783 'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
784 'embeddable' => true,
789 $taxonomy_obj = get_taxonomy( $term->taxonomy );
791 if ( empty( $taxonomy_obj->object_type ) ) {
795 $post_type_links = array();
797 foreach ( $taxonomy_obj->object_type as $type ) {
798 $post_type_object = get_post_type_object( $type );
800 if ( empty( $post_type_object->show_in_rest ) ) {
804 $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
805 $post_type_links[] = array(
806 'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ),
810 if ( ! empty( $post_type_links ) ) {
811 $links['https://api.w.org/post_type'] = $post_type_links;
818 * Retrieves the term's schema, conforming to JSON Schema.
823 * @return array Item schema data.
825 public function get_item_schema() {
827 '$schema' => 'http://json-schema.org/schema#',
828 'title' => 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy,
830 'properties' => array(
832 'description' => __( 'Unique identifier for the term.' ),
834 'context' => array( 'view', 'embed', 'edit' ),
838 'description' => __( 'Number of published posts for the term.' ),
840 'context' => array( 'view', 'edit' ),
843 'description' => array(
844 'description' => __( 'HTML description of the term.' ),
846 'context' => array( 'view', 'edit' ),
849 'description' => __( 'URL of the term.' ),
852 'context' => array( 'view', 'embed', 'edit' ),
856 'description' => __( 'HTML title for the term.' ),
858 'context' => array( 'view', 'embed', 'edit' ),
859 'arg_options' => array(
860 'sanitize_callback' => 'sanitize_text_field',
865 'description' => __( 'An alphanumeric identifier for the term unique to its type.' ),
867 'context' => array( 'view', 'embed', 'edit' ),
868 'arg_options' => array(
869 'sanitize_callback' => array( $this, 'sanitize_slug' ),
873 'description' => __( 'Type attribution for the term.' ),
875 'enum' => array_keys( get_taxonomies() ),
876 'context' => array( 'view', 'embed', 'edit' ),
882 $taxonomy = get_taxonomy( $this->taxonomy );
884 if ( $taxonomy->hierarchical ) {
885 $schema['properties']['parent'] = array(
886 'description' => __( 'The parent term ID.' ),
888 'context' => array( 'view', 'edit' ),
892 $schema['properties']['meta'] = $this->meta->get_field_schema();
894 return $this->add_additional_fields_schema( $schema );
898 * Retrieves the query params for collections.
903 * @return array Collection parameters.
905 public function get_collection_params() {
906 $query_params = parent::get_collection_params();
907 $taxonomy = get_taxonomy( $this->taxonomy );
909 $query_params['context']['default'] = 'view';
911 $query_params['exclude'] = array(
912 'description' => __( 'Ensure result set excludes specific IDs.' ),
917 'default' => array(),
920 $query_params['include'] = array(
921 'description' => __( 'Limit result set to specific IDs.' ),
926 'default' => array(),
929 if ( ! $taxonomy->hierarchical ) {
930 $query_params['offset'] = array(
931 'description' => __( 'Offset the result set by a specific number of items.' ),
936 $query_params['order'] = array(
937 'description' => __( 'Order sort attribute ascending or descending.' ),
946 $query_params['orderby'] = array(
947 'description' => __( 'Sort collection by term attribute.' ),
961 $query_params['hide_empty'] = array(
962 'description' => __( 'Whether to hide terms not assigned to any posts.' ),
967 if ( $taxonomy->hierarchical ) {
968 $query_params['parent'] = array(
969 'description' => __( 'Limit result set to terms assigned to a specific parent.' ),
974 $query_params['post'] = array(
975 'description' => __( 'Limit result set to terms assigned to a specific post.' ),
980 $query_params['slug'] = array(
981 'description' => __( 'Limit result set to terms with a specific slug.' ),
986 * Filter collection parameters for the terms controller.
988 * The dynamic part of the filter `$this->taxonomy` refers to the taxonomy
989 * slug for the controller.
991 * This filter registers the collection parameter, but does not map the
992 * collection parameter to an internal WP_Term_Query parameter. Use the
993 * `rest_{$this->taxonomy}_query` filter to set WP_Term_Query parameters.
997 * @param array $query_params JSON Schema-formatted collection parameters.
998 * @param WP_Taxonomy $taxonomy Taxonomy object.
1000 return apply_filters( "rest_{$this->taxonomy}_collection_params", $query_params, $taxonomy );
1004 * Checks that the taxonomy is valid.
1009 * @param string $taxonomy Taxonomy to check.
1010 * @return bool Whether the taxonomy is allowed for REST management.
1012 protected function check_is_taxonomy_allowed( $taxonomy ) {
1013 $taxonomy_obj = get_taxonomy( $taxonomy );
1014 if ( $taxonomy_obj && ! empty( $taxonomy_obj->show_in_rest ) ) {