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(
100 'methods' => WP_REST_Server::READABLE,
101 'callback' => array( $this, 'get_item' ),
102 'permission_callback' => array( $this, 'get_item_permissions_check' ),
104 'context' => $this->get_context_param( array( 'default' => 'view' ) ),
108 'methods' => WP_REST_Server::EDITABLE,
109 'callback' => array( $this, 'update_item' ),
110 'permission_callback' => array( $this, 'update_item_permissions_check' ),
111 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
114 'methods' => WP_REST_Server::DELETABLE,
115 'callback' => array( $this, 'delete_item' ),
116 'permission_callback' => array( $this, 'delete_item_permissions_check' ),
121 'description' => __( 'Required to be true, as terms do not support trashing.' ),
125 'schema' => array( $this, 'get_public_item_schema' ),
130 * Checks if a request has access to read terms in the specified taxonomy.
135 * @param WP_REST_Request $request Full details about the request.
136 * @return bool|WP_Error True if the request has read access, otherwise false or WP_Error object.
138 public function get_items_permissions_check( $request ) {
139 $tax_obj = get_taxonomy( $this->taxonomy );
140 if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
143 if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) {
144 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) );
150 * Retrieves terms associated with a taxonomy.
155 * @param WP_REST_Request $request Full details about the request.
156 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
158 public function get_items( $request ) {
160 // Retrieve the list of registered collection query parameters.
161 $registered = $this->get_collection_params();
164 * This array defines mappings between public API query parameters whose
165 * values are accepted as-passed, and their internal WP_Query parameter
166 * name equivalents (some are the same). Only values which are also
167 * present in $registered will be set.
169 $parameter_mappings = array(
170 'exclude' => 'exclude',
171 'include' => 'include',
173 'orderby' => 'orderby',
175 'hide_empty' => 'hide_empty',
176 'per_page' => 'number',
177 'search' => 'search',
181 $prepared_args = array();
184 * For each known parameter which is both registered and present in the request,
185 * set the parameter's value on the query $prepared_args.
187 foreach ( $parameter_mappings as $api_param => $wp_param ) {
188 if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {
189 $prepared_args[ $wp_param ] = $request[ $api_param ];
193 if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) {
194 $prepared_args['offset'] = $request['offset'];
196 $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
199 $taxonomy_obj = get_taxonomy( $this->taxonomy );
201 if ( $taxonomy_obj->hierarchical && isset( $registered['parent'], $request['parent'] ) ) {
202 if ( 0 === $request['parent'] ) {
203 // Only query top-level terms.
204 $prepared_args['parent'] = 0;
206 if ( $request['parent'] ) {
207 $prepared_args['parent'] = $request['parent'];
213 * Filters the query arguments before passing them to get_terms().
215 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
217 * Enables adding extra arguments or setting defaults for a terms
218 * collection request.
222 * @link https://developer.wordpress.org/reference/functions/get_terms/
224 * @param array $prepared_args Array of arguments to be
225 * passed to get_terms().
226 * @param WP_REST_Request $request The current request.
228 $prepared_args = apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request );
230 if ( ! empty( $prepared_args['post'] ) ) {
231 $query_result = wp_get_object_terms( $prepared_args['post'], $this->taxonomy, $prepared_args );
233 // Used when calling wp_count_terms() below.
234 $prepared_args['object_ids'] = $prepared_args['post'];
236 $query_result = get_terms( $this->taxonomy, $prepared_args );
239 $count_args = $prepared_args;
241 unset( $count_args['number'], $count_args['offset'] );
243 $total_terms = wp_count_terms( $this->taxonomy, $count_args );
245 // wp_count_terms can return a falsy value when the term has no children.
246 if ( ! $total_terms ) {
252 foreach ( $query_result as $term ) {
253 $data = $this->prepare_item_for_response( $term, $request );
254 $response[] = $this->prepare_response_for_collection( $data );
257 $response = rest_ensure_response( $response );
259 // Store pagination values for headers.
260 $per_page = (int) $prepared_args['number'];
261 $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
263 $response->header( 'X-WP-Total', (int) $total_terms );
265 $max_pages = ceil( $total_terms / $per_page );
267 $response->header( 'X-WP-TotalPages', (int) $max_pages );
269 $base = add_query_arg( $request->get_query_params(), rest_url( $this->namespace . '/' . $this->rest_base ) );
271 $prev_page = $page - 1;
273 if ( $prev_page > $max_pages ) {
274 $prev_page = $max_pages;
277 $prev_link = add_query_arg( 'page', $prev_page, $base );
278 $response->link_header( 'prev', $prev_link );
280 if ( $max_pages > $page ) {
281 $next_page = $page + 1;
282 $next_link = add_query_arg( 'page', $next_page, $base );
284 $response->link_header( 'next', $next_link );
291 * Checks if a request has access to read or edit the specified term.
296 * @param WP_REST_Request $request Full details about the request.
297 * @return bool|WP_Error True if the request has read access for the item, otherwise false or WP_Error object.
299 public function get_item_permissions_check( $request ) {
300 $tax_obj = get_taxonomy( $this->taxonomy );
301 if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
304 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', (int) $request['id'] ) ) {
305 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) );
311 * Gets a single term from a taxonomy.
316 * @param WP_REST_Request $request Full details about the request.
317 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
319 public function get_item( $request ) {
321 $term = get_term( (int) $request['id'], $this->taxonomy );
323 if ( ! $term || $term->taxonomy !== $this->taxonomy ) {
324 return new WP_Error( 'rest_term_invalid', __( "Term doesn't exist." ), array( 'status' => 404 ) );
327 if ( is_wp_error( $term ) ) {
331 $response = $this->prepare_item_for_response( $term, $request );
333 return rest_ensure_response( $response );
337 * Checks if a request has access to create a term.
342 * @param WP_REST_Request $request Full details about the request.
343 * @return bool|WP_Error True if the request has access to create items, false or WP_Error object otherwise.
345 public function create_item_permissions_check( $request ) {
347 if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
351 $taxonomy_obj = get_taxonomy( $this->taxonomy );
352 if ( ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) {
353 return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) );
360 * Creates a single term in a taxonomy.
365 * @param WP_REST_Request $request Full details about the request.
366 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
368 public function create_item( $request ) {
369 if ( isset( $request['parent'] ) ) {
370 if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
371 return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
374 $parent = get_term( (int) $request['parent'], $this->taxonomy );
377 return new WP_Error( 'rest_term_invalid', __( "Parent term doesn't exist." ), array( 'status' => 400 ) );
381 $prepared_term = $this->prepare_item_for_database( $request );
383 $term = wp_insert_term( wp_slash( $prepared_term->name ), $this->taxonomy, wp_slash( (array) $prepared_term ) );
384 if ( is_wp_error( $term ) ) {
386 * If we're going to inform the client that the term already exists,
387 * give them the identifier for future use.
389 if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
390 $existing_term = get_term( $term_id, $this->taxonomy );
391 $term->add_data( $existing_term->term_id, 'term_exists' );
397 $term = get_term( $term['term_id'], $this->taxonomy );
400 * Fires after a single term is created or updated via the REST API.
402 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
406 * @param WP_Term $term Inserted or updated term object.
407 * @param WP_REST_Request $request Request object.
408 * @param bool $creating True when creating a term, false when updating.
410 do_action( "rest_insert_{$this->taxonomy}", $term, $request, true );
412 $schema = $this->get_item_schema();
413 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
414 $meta_update = $this->meta->update_value( $request['meta'], (int) $request['id'] );
416 if ( is_wp_error( $meta_update ) ) {
421 $fields_update = $this->update_additional_fields_for_object( $term, $request );
423 if ( is_wp_error( $fields_update ) ) {
424 return $fields_update;
427 $request->set_param( 'context', 'view' );
429 $response = $this->prepare_item_for_response( $term, $request );
430 $response = rest_ensure_response( $response );
432 $response->set_status( 201 );
433 $response->header( 'Location', rest_url( $this->namespace . '/' . $this->rest_base . '/' . $term->term_id ) );
439 * Checks if a request has access to update the specified term.
444 * @param WP_REST_Request $request Full details about the request.
445 * @return bool|WP_Error True if the request has access to update the item, false or WP_Error object otherwise.
447 public function update_item_permissions_check( $request ) {
449 if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
453 $term = get_term( (int) $request['id'], $this->taxonomy );
456 return new WP_Error( 'rest_term_invalid', __( "Term doesn't exist." ), array( 'status' => 404 ) );
459 if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
460 return new WP_Error( 'rest_cannot_update', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) );
467 * Updates a single term from a taxonomy.
472 * @param WP_REST_Request $request Full details about the request.
473 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
475 public function update_item( $request ) {
476 if ( isset( $request['parent'] ) ) {
477 if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
478 return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
481 $parent = get_term( (int) $request['parent'], $this->taxonomy );
484 return new WP_Error( 'rest_term_invalid', __( "Parent term doesn't exist." ), array( 'status' => 400 ) );
488 $prepared_term = $this->prepare_item_for_database( $request );
490 $term = get_term( (int) $request['id'], $this->taxonomy );
492 // Only update the term if we haz something to update.
493 if ( ! empty( $prepared_term ) ) {
494 $update = wp_update_term( $term->term_id, $term->taxonomy, wp_slash( (array) $prepared_term ) );
496 if ( is_wp_error( $update ) ) {
501 $term = get_term( (int) $request['id'], $this->taxonomy );
503 /* This action is documented in lib/endpoints/class-wp-rest-terms-controller.php */
504 do_action( "rest_insert_{$this->taxonomy}", $term, $request, false );
506 $schema = $this->get_item_schema();
507 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
508 $meta_update = $this->meta->update_value( $request['meta'], (int) $request['id'] );
510 if ( is_wp_error( $meta_update ) ) {
515 $fields_update = $this->update_additional_fields_for_object( $term, $request );
517 if ( is_wp_error( $fields_update ) ) {
518 return $fields_update;
521 $request->set_param( 'context', 'view' );
523 $response = $this->prepare_item_for_response( $term, $request );
525 return rest_ensure_response( $response );
529 * Checks if a request has access to delete the specified term.
534 * @param WP_REST_Request $request Full details about the request.
535 * @return bool|WP_Error True if the request has access to delete the item, otherwise false or WP_Error object.
537 public function delete_item_permissions_check( $request ) {
538 if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
542 $term = get_term( (int) $request['id'], $this->taxonomy );
545 return new WP_Error( 'rest_term_invalid', __( "Term doesn't exist." ), array( 'status' => 404 ) );
548 if ( ! current_user_can( 'delete_term', $term->term_id ) ) {
549 return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) );
556 * Deletes a single term from a taxonomy.
561 * @param WP_REST_Request $request Full details about the request.
562 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
564 public function delete_item( $request ) {
566 $force = isset( $request['force'] ) ? (bool) $request['force'] : false;
568 // We don't support trashing for terms.
570 return new WP_Error( 'rest_trash_not_supported', __( 'Terms do not support trashing. Set force=true to delete.' ), array( 'status' => 501 ) );
573 $term = get_term( (int) $request['id'], $this->taxonomy );
575 $request->set_param( 'context', 'view' );
577 $previous = $this->prepare_item_for_response( $term, $request );
579 $retval = wp_delete_term( $term->term_id, $term->taxonomy );
582 return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) );
585 $response = new WP_REST_Response();
586 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
589 * Fires after a single term is deleted via the REST API.
591 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
595 * @param WP_Term $term The deleted term.
596 * @param WP_REST_Response $response The response data.
597 * @param WP_REST_Request $request The request sent to the API.
599 do_action( "rest_delete_{$this->taxonomy}", $term, $response, $request );
605 * Prepares a single term for create or update.
610 * @param WP_REST_Request $request Request object.
611 * @return object $prepared_term Term object.
613 public function prepare_item_for_database( $request ) {
614 $prepared_term = new stdClass;
616 $schema = $this->get_item_schema();
617 if ( isset( $request['name'] ) && ! empty( $schema['properties']['name'] ) ) {
618 $prepared_term->name = $request['name'];
621 if ( isset( $request['slug'] ) && ! empty( $schema['properties']['slug'] ) ) {
622 $prepared_term->slug = $request['slug'];
625 if ( isset( $request['taxonomy'] ) && ! empty( $schema['properties']['taxonomy'] ) ) {
626 $prepared_term->taxonomy = $request['taxonomy'];
629 if ( isset( $request['description'] ) && ! empty( $schema['properties']['description'] ) ) {
630 $prepared_term->description = $request['description'];
633 if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) {
635 $parent_term = get_term( (int) $request['parent'], $this->taxonomy );
637 if ( $parent_term ) {
638 $parent_term_id = $parent_term->term_id;
641 $prepared_term->parent = $parent_term_id;
645 * Filters term data before inserting term via the REST API.
647 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
651 * @param object $prepared_term Term object.
652 * @param WP_REST_Request $request Request object.
654 return apply_filters( "rest_pre_insert_{$this->taxonomy}", $prepared_term, $request );
658 * Prepares a single term output for response.
663 * @param obj $item Term object.
664 * @param WP_REST_Request $request Request object.
665 * @return WP_REST_Response $response Response object.
667 public function prepare_item_for_response( $item, $request ) {
669 $schema = $this->get_item_schema();
672 if ( ! empty( $schema['properties']['id'] ) ) {
673 $data['id'] = (int) $item->term_id;
676 if ( ! empty( $schema['properties']['count'] ) ) {
677 $data['count'] = (int) $item->count;
680 if ( ! empty( $schema['properties']['description'] ) ) {
681 $data['description'] = $item->description;
684 if ( ! empty( $schema['properties']['link'] ) ) {
685 $data['link'] = get_term_link( $item );
688 if ( ! empty( $schema['properties']['name'] ) ) {
689 $data['name'] = $item->name;
692 if ( ! empty( $schema['properties']['slug'] ) ) {
693 $data['slug'] = $item->slug;
696 if ( ! empty( $schema['properties']['taxonomy'] ) ) {
697 $data['taxonomy'] = $item->taxonomy;
700 if ( ! empty( $schema['properties']['parent'] ) ) {
701 $data['parent'] = (int) $item->parent;
704 if ( ! empty( $schema['properties']['meta'] ) ) {
705 $data['meta'] = $this->meta->get_value( $item->term_id, $request );
708 $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
709 $data = $this->add_additional_fields_to_object( $data, $request );
710 $data = $this->filter_response_by_context( $data, $context );
712 $response = rest_ensure_response( $data );
714 $response->add_links( $this->prepare_links( $item ) );
717 * Filters a term item returned from the API.
719 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
721 * Allows modification of the term data right before it is returned.
725 * @param WP_REST_Response $response The response object.
726 * @param object $item The original term object.
727 * @param WP_REST_Request $request Request used to generate the response.
729 return apply_filters( "rest_prepare_{$this->taxonomy}", $response, $item, $request );
733 * Prepares links for the request.
738 * @param object $term Term object.
739 * @return array Links for the given term.
741 protected function prepare_links( $term ) {
742 $base = $this->namespace . '/' . $this->rest_base;
745 'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
747 'collection' => array(
748 'href' => rest_url( $base ),
751 'href' => rest_url( sprintf( 'wp/v2/taxonomies/%s', $this->taxonomy ) ),
755 if ( $term->parent ) {
756 $parent_term = get_term( (int) $term->parent, $term->taxonomy );
758 if ( $parent_term ) {
759 $links['up'] = array(
760 'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
761 'embeddable' => true,
766 $taxonomy_obj = get_taxonomy( $term->taxonomy );
768 if ( empty( $taxonomy_obj->object_type ) ) {
772 $post_type_links = array();
774 foreach ( $taxonomy_obj->object_type as $type ) {
775 $post_type_object = get_post_type_object( $type );
777 if ( empty( $post_type_object->show_in_rest ) ) {
781 $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
782 $post_type_links[] = array(
783 'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ),
787 if ( ! empty( $post_type_links ) ) {
788 $links['https://api.w.org/post_type'] = $post_type_links;
795 * Retrieves the term's schema, conforming to JSON Schema.
800 * @return array Item schema data.
802 public function get_item_schema() {
804 '$schema' => 'http://json-schema.org/schema#',
805 'title' => 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy,
807 'properties' => array(
809 'description' => __( 'Unique identifier for the term.' ),
811 'context' => array( 'view', 'embed', 'edit' ),
815 'description' => __( 'Number of published posts for the term.' ),
817 'context' => array( 'view', 'edit' ),
820 'description' => array(
821 'description' => __( 'HTML description of the term.' ),
823 'context' => array( 'view', 'edit' ),
826 'description' => __( 'URL of the term.' ),
829 'context' => array( 'view', 'embed', 'edit' ),
833 'description' => __( 'HTML title for the term.' ),
835 'context' => array( 'view', 'embed', 'edit' ),
836 'arg_options' => array(
837 'sanitize_callback' => 'sanitize_text_field',
842 'description' => __( 'An alphanumeric identifier for the term unique to its type.' ),
844 'context' => array( 'view', 'embed', 'edit' ),
845 'arg_options' => array(
846 'sanitize_callback' => array( $this, 'sanitize_slug' ),
850 'description' => __( 'Type attribution for the term.' ),
852 'enum' => array_keys( get_taxonomies() ),
853 'context' => array( 'view', 'embed', 'edit' ),
859 $taxonomy = get_taxonomy( $this->taxonomy );
861 if ( $taxonomy->hierarchical ) {
862 $schema['properties']['parent'] = array(
863 'description' => __( 'The parent term ID.' ),
865 'context' => array( 'view', 'edit' ),
869 $schema['properties']['meta'] = $this->meta->get_field_schema();
871 return $this->add_additional_fields_schema( $schema );
875 * Retrieves the query params for collections.
880 * @return array Collection parameters.
882 public function get_collection_params() {
883 $query_params = parent::get_collection_params();
884 $taxonomy = get_taxonomy( $this->taxonomy );
886 $query_params['context']['default'] = 'view';
888 $query_params['exclude'] = array(
889 'description' => __( 'Ensure result set excludes specific IDs.' ),
894 'default' => array(),
897 $query_params['include'] = array(
898 'description' => __( 'Limit result set to specific IDs.' ),
903 'default' => array(),
906 if ( ! $taxonomy->hierarchical ) {
907 $query_params['offset'] = array(
908 'description' => __( 'Offset the result set by a specific number of items.' ),
913 $query_params['order'] = array(
914 'description' => __( 'Order sort attribute ascending or descending.' ),
923 $query_params['orderby'] = array(
924 'description' => __( 'Sort collection by term attribute.' ),
938 $query_params['hide_empty'] = array(
939 'description' => __( 'Whether to hide terms not assigned to any posts.' ),
944 if ( $taxonomy->hierarchical ) {
945 $query_params['parent'] = array(
946 'description' => __( 'Limit result set to terms assigned to a specific parent.' ),
951 $query_params['post'] = array(
952 'description' => __( 'Limit result set to terms assigned to a specific post.' ),
957 $query_params['slug'] = array(
958 'description' => __( 'Limit result set to terms with a specific slug.' ),
963 * Filter collection parameters for the terms controller.
965 * The dynamic part of the filter `$this->taxonomy` refers to the taxonomy
966 * slug for the controller.
968 * This filter registers the collection parameter, but does not map the
969 * collection parameter to an internal WP_Term_Query parameter. Use the
970 * `rest_{$this->taxonomy}_query` filter to set WP_Term_Query parameters.
974 * @param $params JSON Schema-formatted collection parameters.
975 * @param WP_Taxonomy $taxonomy_obj Taxonomy object.
977 return apply_filters( 'rest_{$this->taxonomy}_collection_params', $query_params, $taxonomy );
981 * Checks that the taxonomy is valid.
986 * @param string $taxonomy Taxonomy to check.
987 * @return bool Whether the taxonomy is allowed for REST management.
989 protected function check_is_taxonomy_allowed( $taxonomy ) {
990 $taxonomy_obj = get_taxonomy( $taxonomy );
991 if ( $taxonomy_obj && ! empty( $taxonomy_obj->show_in_rest ) ) {