wp/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    54 	 * @since 4.7.0
    54 	 * @since 4.7.0
    55 	 *
    55 	 *
    56 	 * @param string $taxonomy Taxonomy key.
    56 	 * @param string $taxonomy Taxonomy key.
    57 	 */
    57 	 */
    58 	public function __construct( $taxonomy ) {
    58 	public function __construct( $taxonomy ) {
    59 		$this->taxonomy = $taxonomy;
    59 		$this->taxonomy  = $taxonomy;
    60 		$this->namespace = 'wp/v2';
    60 		$this->namespace = 'wp/v2';
    61 		$tax_obj = get_taxonomy( $taxonomy );
    61 		$tax_obj         = get_taxonomy( $taxonomy );
    62 		$this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name;
    62 		$this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name;
    63 
    63 
    64 		$this->meta = new WP_REST_Term_Meta_Fields( $taxonomy );
    64 		$this->meta = new WP_REST_Term_Meta_Fields( $taxonomy );
    65 	}
    65 	}
    66 
    66 
    71 	 *
    71 	 *
    72 	 * @see register_rest_route()
    72 	 * @see register_rest_route()
    73 	 */
    73 	 */
    74 	public function register_routes() {
    74 	public function register_routes() {
    75 
    75 
    76 		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
    76 		register_rest_route(
       
    77 			$this->namespace,
       
    78 			'/' . $this->rest_base,
    77 			array(
    79 			array(
    78 				'methods'             => WP_REST_Server::READABLE,
    80 				array(
    79 				'callback'            => array( $this, 'get_items' ),
    81 					'methods'             => WP_REST_Server::READABLE,
    80 				'permission_callback' => array( $this, 'get_items_permissions_check' ),
    82 					'callback'            => array( $this, 'get_items' ),
    81 				'args'                => $this->get_collection_params(),
    83 					'permission_callback' => array( $this, 'get_items_permissions_check' ),
    82 			),
    84 					'args'                => $this->get_collection_params(),
       
    85 				),
       
    86 				array(
       
    87 					'methods'             => WP_REST_Server::CREATABLE,
       
    88 					'callback'            => array( $this, 'create_item' ),
       
    89 					'permission_callback' => array( $this, 'create_item_permissions_check' ),
       
    90 					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
       
    91 				),
       
    92 				'schema' => array( $this, 'get_public_item_schema' ),
       
    93 			)
       
    94 		);
       
    95 
       
    96 		register_rest_route(
       
    97 			$this->namespace,
       
    98 			'/' . $this->rest_base . '/(?P<id>[\d]+)',
    83 			array(
    99 			array(
    84 				'methods'             => WP_REST_Server::CREATABLE,
   100 				'args'   => array(
    85 				'callback'            => array( $this, 'create_item' ),
   101 					'id' => array(
    86 				'permission_callback' => array( $this, 'create_item_permissions_check' ),
   102 						'description' => __( 'Unique identifier for the term.' ),
    87 				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
   103 						'type'        => 'integer',
    88 			),
       
    89 			'schema' => array( $this, 'get_public_item_schema' ),
       
    90 		) );
       
    91 
       
    92 		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
       
    93 			'args' => array(
       
    94 				'id' => array(
       
    95 					'description' => __( 'Unique identifier for the term.' ),
       
    96 					'type'        => 'integer',
       
    97 				),
       
    98 			),
       
    99 			array(
       
   100 				'methods'             => WP_REST_Server::READABLE,
       
   101 				'callback'            => array( $this, 'get_item' ),
       
   102 				'permission_callback' => array( $this, 'get_item_permissions_check' ),
       
   103 				'args'                => array(
       
   104 					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
       
   105 				),
       
   106 			),
       
   107 			array(
       
   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 ),
       
   112 			),
       
   113 			array(
       
   114 				'methods'             => WP_REST_Server::DELETABLE,
       
   115 				'callback'            => array( $this, 'delete_item' ),
       
   116 				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
       
   117 				'args'                => array(
       
   118 					'force' => array(
       
   119 						'type'        => 'boolean',
       
   120 						'default'     => false,
       
   121 						'description' => __( 'Required to be true, as terms do not support trashing.' ),
       
   122 					),
   104 					),
   123 				),
   105 				),
   124 			),
   106 				array(
   125 			'schema' => array( $this, 'get_public_item_schema' ),
   107 					'methods'             => WP_REST_Server::READABLE,
   126 		) );
   108 					'callback'            => array( $this, 'get_item' ),
       
   109 					'permission_callback' => array( $this, 'get_item_permissions_check' ),
       
   110 					'args'                => array(
       
   111 						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
       
   112 					),
       
   113 				),
       
   114 				array(
       
   115 					'methods'             => WP_REST_Server::EDITABLE,
       
   116 					'callback'            => array( $this, 'update_item' ),
       
   117 					'permission_callback' => array( $this, 'update_item_permissions_check' ),
       
   118 					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
       
   119 				),
       
   120 				array(
       
   121 					'methods'             => WP_REST_Server::DELETABLE,
       
   122 					'callback'            => array( $this, 'delete_item' ),
       
   123 					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
       
   124 					'args'                => array(
       
   125 						'force' => array(
       
   126 							'type'        => 'boolean',
       
   127 							'default'     => false,
       
   128 							'description' => __( 'Required to be true, as terms do not support trashing.' ),
       
   129 						),
       
   130 					),
       
   131 				),
       
   132 				'schema' => array( $this, 'get_public_item_schema' ),
       
   133 			)
       
   134 		);
   127 	}
   135 	}
   128 
   136 
   129 	/**
   137 	/**
   130 	 * Checks if a request has access to read terms in the specified taxonomy.
   138 	 * Checks if a request has access to read terms in the specified taxonomy.
   131 	 *
   139 	 *
   233 		 *                                       passed to get_terms().
   241 		 *                                       passed to get_terms().
   234 		 * @param WP_REST_Request $request       The current request.
   242 		 * @param WP_REST_Request $request       The current request.
   235 		 */
   243 		 */
   236 		$prepared_args = apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request );
   244 		$prepared_args = apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request );
   237 
   245 
   238 		if ( ! empty( $prepared_args['post'] )  ) {
   246 		if ( ! empty( $prepared_args['post'] ) ) {
   239 			$query_result = wp_get_object_terms( $prepared_args['post'], $this->taxonomy, $prepared_args );
   247 			$query_result = wp_get_object_terms( $prepared_args['post'], $this->taxonomy, $prepared_args );
   240 
   248 
   241 			// Used when calling wp_count_terms() below.
   249 			// Used when calling wp_count_terms() below.
   242 			$prepared_args['object_ids'] = $prepared_args['post'];
   250 			$prepared_args['object_ids'] = $prepared_args['post'];
   243 		} else {
   251 		} else {
   256 		}
   264 		}
   257 
   265 
   258 		$response = array();
   266 		$response = array();
   259 
   267 
   260 		foreach ( $query_result as $term ) {
   268 		foreach ( $query_result as $term ) {
   261 			$data = $this->prepare_item_for_response( $term, $request );
   269 			$data       = $this->prepare_item_for_response( $term, $request );
   262 			$response[] = $this->prepare_response_for_collection( $data );
   270 			$response[] = $this->prepare_response_for_collection( $data );
   263 		}
   271 		}
   264 
   272 
   265 		$response = rest_ensure_response( $response );
   273 		$response = rest_ensure_response( $response );
   266 
   274 
   272 
   280 
   273 		$max_pages = ceil( $total_terms / $per_page );
   281 		$max_pages = ceil( $total_terms / $per_page );
   274 
   282 
   275 		$response->header( 'X-WP-TotalPages', (int) $max_pages );
   283 		$response->header( 'X-WP-TotalPages', (int) $max_pages );
   276 
   284 
   277 		$base = add_query_arg( $request->get_query_params(), rest_url( $this->namespace . '/' . $this->rest_base ) );
   285 		$base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( $this->namespace . '/' . $this->rest_base ) );
   278 		if ( $page > 1 ) {
   286 		if ( $page > 1 ) {
   279 			$prev_page = $page - 1;
   287 			$prev_page = $page - 1;
   280 
   288 
   281 			if ( $prev_page > $max_pages ) {
   289 			if ( $prev_page > $max_pages ) {
   282 				$prev_page = $max_pages;
   290 				$prev_page = $max_pages;
   416 			 * give them the identifier for future use.
   424 			 * give them the identifier for future use.
   417 			 */
   425 			 */
   418 			if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
   426 			if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
   419 				$existing_term = get_term( $term_id, $this->taxonomy );
   427 				$existing_term = get_term( $term_id, $this->taxonomy );
   420 				$term->add_data( $existing_term->term_id, 'term_exists' );
   428 				$term->add_data( $existing_term->term_id, 'term_exists' );
   421 				$term->add_data( array( 'status' => 409, 'term_id' => $term_id ) );
   429 				$term->add_data(
       
   430 					array(
       
   431 						'status'  => 400,
       
   432 						'term_id' => $term_id,
       
   433 					)
       
   434 				);
   422 			}
   435 			}
   423 
   436 
   424 			return $term;
   437 			return $term;
   425 		}
   438 		}
   426 
   439 
   439 		 */
   452 		 */
   440 		do_action( "rest_insert_{$this->taxonomy}", $term, $request, true );
   453 		do_action( "rest_insert_{$this->taxonomy}", $term, $request, true );
   441 
   454 
   442 		$schema = $this->get_item_schema();
   455 		$schema = $this->get_item_schema();
   443 		if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
   456 		if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
   444 			$meta_update = $this->meta->update_value( $request['meta'], (int) $request['id'] );
   457 			$meta_update = $this->meta->update_value( $request['meta'], $term->term_id );
   445 
   458 
   446 			if ( is_wp_error( $meta_update ) ) {
   459 			if ( is_wp_error( $meta_update ) ) {
   447 				return $meta_update;
   460 				return $meta_update;
   448 			}
   461 			}
   449 		}
   462 		}
   453 		if ( is_wp_error( $fields_update ) ) {
   466 		if ( is_wp_error( $fields_update ) ) {
   454 			return $fields_update;
   467 			return $fields_update;
   455 		}
   468 		}
   456 
   469 
   457 		$request->set_param( 'context', 'view' );
   470 		$request->set_param( 'context', 'view' );
       
   471 
       
   472 		/**
       
   473 		 * Fires after a single term is completely created or updated via the REST API.
       
   474 		 *
       
   475 		 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
       
   476 		 *
       
   477 		 * @since 5.0.0
       
   478 		 *
       
   479 		 * @param WP_Term         $term     Inserted or updated term object.
       
   480 		 * @param WP_REST_Request $request  Request object.
       
   481 		 * @param bool            $creating True when creating a term, false when updating.
       
   482 		 */
       
   483 		do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, true );
   458 
   484 
   459 		$response = $this->prepare_item_for_response( $term, $request );
   485 		$response = $this->prepare_item_for_response( $term, $request );
   460 		$response = rest_ensure_response( $response );
   486 		$response = rest_ensure_response( $response );
   461 
   487 
   462 		$response->set_status( 201 );
   488 		$response->set_status( 201 );
   543 			return $fields_update;
   569 			return $fields_update;
   544 		}
   570 		}
   545 
   571 
   546 		$request->set_param( 'context', 'view' );
   572 		$request->set_param( 'context', 'view' );
   547 
   573 
       
   574 		/** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */
       
   575 		do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, false );
       
   576 
   548 		$response = $this->prepare_item_for_response( $term, $request );
   577 		$response = $this->prepare_item_for_response( $term, $request );
   549 
   578 
   550 		return rest_ensure_response( $response );
   579 		return rest_ensure_response( $response );
   551 	}
   580 	}
   552 
   581 
   602 		if ( ! $retval ) {
   631 		if ( ! $retval ) {
   603 			return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) );
   632 			return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) );
   604 		}
   633 		}
   605 
   634 
   606 		$response = new WP_REST_Response();
   635 		$response = new WP_REST_Response();
   607 		$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
   636 		$response->set_data(
       
   637 			array(
       
   638 				'deleted'  => true,
       
   639 				'previous' => $previous->get_data(),
       
   640 			)
       
   641 		);
   608 
   642 
   609 		/**
   643 		/**
   610 		 * Fires after a single term is deleted via the REST API.
   644 		 * Fires after a single term is deleted via the REST API.
   611 		 *
   645 		 *
   612 		 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
   646 		 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
   649 		if ( isset( $request['description'] ) && ! empty( $schema['properties']['description'] ) ) {
   683 		if ( isset( $request['description'] ) && ! empty( $schema['properties']['description'] ) ) {
   650 			$prepared_term->description = $request['description'];
   684 			$prepared_term->description = $request['description'];
   651 		}
   685 		}
   652 
   686 
   653 		if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) {
   687 		if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) {
   654 			$parent_term_id = 0;
   688 			$parent_term_id   = 0;
   655 			$parent_term    = get_term( (int) $request['parent'], $this->taxonomy );
   689 			$requested_parent = (int) $request['parent'];
   656 
   690 
   657 			if ( $parent_term ) {
   691 			if ( $requested_parent ) {
   658 				$parent_term_id = $parent_term->term_id;
   692 				$parent_term = get_term( $requested_parent, $this->taxonomy );
       
   693 
       
   694 				if ( $parent_term instanceof WP_Term ) {
       
   695 					$parent_term_id = $parent_term->term_id;
       
   696 				}
   659 			}
   697 			}
   660 
   698 
   661 			$prepared_term->parent = $parent_term_id;
   699 			$prepared_term->parent = $parent_term_id;
   662 		}
   700 		}
   663 
   701 
   755 	 *
   793 	 *
   756 	 * @param object $term Term object.
   794 	 * @param object $term Term object.
   757 	 * @return array Links for the given term.
   795 	 * @return array Links for the given term.
   758 	 */
   796 	 */
   759 	protected function prepare_links( $term ) {
   797 	protected function prepare_links( $term ) {
   760 		$base = $this->namespace . '/' . $this->rest_base;
   798 		$base  = $this->namespace . '/' . $this->rest_base;
   761 		$links = array(
   799 		$links = array(
   762 			'self'       => array(
   800 			'self'       => array(
   763 				'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
   801 				'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
   764 			),
   802 			),
   765 			'collection' => array(
   803 			'collection' => array(
   794 
   832 
   795 			if ( empty( $post_type_object->show_in_rest ) ) {
   833 			if ( empty( $post_type_object->show_in_rest ) ) {
   796 				continue;
   834 				continue;
   797 			}
   835 			}
   798 
   836 
   799 			$rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
   837 			$rest_base         = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
   800 			$post_type_links[] = array(
   838 			$post_type_links[] = array(
   801 				'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ),
   839 				'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ),
   802 			);
   840 			);
   803 		}
   841 		}
   804 
   842 
   821 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
   859 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
   822 			'title'      => 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy,
   860 			'title'      => 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy,
   823 			'type'       => 'object',
   861 			'type'       => 'object',
   824 			'properties' => array(
   862 			'properties' => array(
   825 				'id'          => array(
   863 				'id'          => array(
   826 					'description'  => __( 'Unique identifier for the term.' ),
   864 					'description' => __( 'Unique identifier for the term.' ),
   827 					'type'         => 'integer',
   865 					'type'        => 'integer',
   828 					'context'      => array( 'view', 'embed', 'edit' ),
   866 					'context'     => array( 'view', 'embed', 'edit' ),
   829 					'readonly'     => true,
   867 					'readonly'    => true,
   830 				),
   868 				),
   831 				'count'       => array(
   869 				'count'       => array(
   832 					'description'  => __( 'Number of published posts for the term.' ),
   870 					'description' => __( 'Number of published posts for the term.' ),
   833 					'type'         => 'integer',
   871 					'type'        => 'integer',
   834 					'context'      => array( 'view', 'edit' ),
   872 					'context'     => array( 'view', 'edit' ),
   835 					'readonly'     => true,
   873 					'readonly'    => true,
   836 				),
   874 				),
   837 				'description' => array(
   875 				'description' => array(
   838 					'description'  => __( 'HTML description of the term.' ),
   876 					'description' => __( 'HTML description of the term.' ),
   839 					'type'         => 'string',
   877 					'type'        => 'string',
   840 					'context'      => array( 'view', 'edit' ),
   878 					'context'     => array( 'view', 'edit' ),
   841 				),
   879 				),
   842 				'link'        => array(
   880 				'link'        => array(
   843 					'description'  => __( 'URL of the term.' ),
   881 					'description' => __( 'URL of the term.' ),
   844 					'type'         => 'string',
   882 					'type'        => 'string',
   845 					'format'       => 'uri',
   883 					'format'      => 'uri',
   846 					'context'      => array( 'view', 'embed', 'edit' ),
   884 					'context'     => array( 'view', 'embed', 'edit' ),
   847 					'readonly'     => true,
   885 					'readonly'    => true,
   848 				),
   886 				),
   849 				'name'        => array(
   887 				'name'        => array(
   850 					'description'  => __( 'HTML title for the term.' ),
   888 					'description' => __( 'HTML title for the term.' ),
   851 					'type'         => 'string',
   889 					'type'        => 'string',
   852 					'context'      => array( 'view', 'embed', 'edit' ),
   890 					'context'     => array( 'view', 'embed', 'edit' ),
   853 					'arg_options'  => array(
   891 					'arg_options' => array(
   854 						'sanitize_callback' => 'sanitize_text_field',
   892 						'sanitize_callback' => 'sanitize_text_field',
   855 					),
   893 					),
   856 					'required'     => true,
   894 					'required'    => true,
   857 				),
   895 				),
   858 				'slug'        => array(
   896 				'slug'        => array(
   859 					'description'  => __( 'An alphanumeric identifier for the term unique to its type.' ),
   897 					'description' => __( 'An alphanumeric identifier for the term unique to its type.' ),
   860 					'type'         => 'string',
   898 					'type'        => 'string',
   861 					'context'      => array( 'view', 'embed', 'edit' ),
   899 					'context'     => array( 'view', 'embed', 'edit' ),
   862 					'arg_options'  => array(
   900 					'arg_options' => array(
   863 						'sanitize_callback' => array( $this, 'sanitize_slug' ),
   901 						'sanitize_callback' => array( $this, 'sanitize_slug' ),
   864 					),
   902 					),
   865 				),
   903 				),
   866 				'taxonomy'    => array(
   904 				'taxonomy'    => array(
   867 					'description'  => __( 'Type attribution for the term.' ),
   905 					'description' => __( 'Type attribution for the term.' ),
   868 					'type'         => 'string',
   906 					'type'        => 'string',
   869 					'enum'         => array_keys( get_taxonomies() ),
   907 					'enum'        => array_keys( get_taxonomies() ),
   870 					'context'      => array( 'view', 'embed', 'edit' ),
   908 					'context'     => array( 'view', 'embed', 'edit' ),
   871 					'readonly'     => true,
   909 					'readonly'    => true,
   872 				),
   910 				),
   873 			),
   911 			),
   874 		);
   912 		);
   875 
   913 
   876 		$taxonomy = get_taxonomy( $this->taxonomy );
   914 		$taxonomy = get_taxonomy( $this->taxonomy );
   877 
   915 
   878 		if ( $taxonomy->hierarchical ) {
   916 		if ( $taxonomy->hierarchical ) {
   879 			$schema['properties']['parent'] = array(
   917 			$schema['properties']['parent'] = array(
   880 				'description'  => __( 'The parent term ID.' ),
   918 				'description' => __( 'The parent term ID.' ),
   881 				'type'         => 'integer',
   919 				'type'        => 'integer',
   882 				'context'      => array( 'view', 'edit' ),
   920 				'context'     => array( 'view', 'edit' ),
   883 			);
   921 			);
   884 		}
   922 		}
   885 
   923 
   886 		$schema['properties']['meta'] = $this->meta->get_field_schema();
   924 		$schema['properties']['meta'] = $this->meta->get_field_schema();
   887 
   925 
   895 	 *
   933 	 *
   896 	 * @return array Collection parameters.
   934 	 * @return array Collection parameters.
   897 	 */
   935 	 */
   898 	public function get_collection_params() {
   936 	public function get_collection_params() {
   899 		$query_params = parent::get_collection_params();
   937 		$query_params = parent::get_collection_params();
   900 		$taxonomy = get_taxonomy( $this->taxonomy );
   938 		$taxonomy     = get_taxonomy( $this->taxonomy );
   901 
   939 
   902 		$query_params['context']['default'] = 'view';
   940 		$query_params['context']['default'] = 'view';
   903 
   941 
   904 		$query_params['exclude'] = array(
   942 		$query_params['exclude'] = array(
   905 			'description'       => __( 'Ensure result set excludes specific IDs.' ),
   943 			'description' => __( 'Ensure result set excludes specific IDs.' ),
   906 			'type'              => 'array',
   944 			'type'        => 'array',
   907 			'items'             => array(
   945 			'items'       => array(
   908 				'type'          => 'integer',
   946 				'type' => 'integer',
   909 			),
   947 			),
   910 			'default'           => array(),
   948 			'default'     => array(),
   911 		);
   949 		);
   912 
   950 
   913 		$query_params['include'] = array(
   951 		$query_params['include'] = array(
   914 			'description'       => __( 'Limit result set to specific IDs.' ),
   952 			'description' => __( 'Limit result set to specific IDs.' ),
   915 			'type'              => 'array',
   953 			'type'        => 'array',
   916 			'items'             => array(
   954 			'items'       => array(
   917 				'type'          => 'integer',
   955 				'type' => 'integer',
   918 			),
   956 			),
   919 			'default'           => array(),
   957 			'default'     => array(),
   920 		);
   958 		);
   921 
   959 
   922 		if ( ! $taxonomy->hierarchical ) {
   960 		if ( ! $taxonomy->hierarchical ) {
   923 			$query_params['offset'] = array(
   961 			$query_params['offset'] = array(
   924 				'description'       => __( 'Offset the result set by a specific number of items.' ),
   962 				'description' => __( 'Offset the result set by a specific number of items.' ),
   925 				'type'              => 'integer',
   963 				'type'        => 'integer',
   926 			);
   964 			);
   927 		}
   965 		}
   928 
   966 
   929 		$query_params['order'] = array(
   967 		$query_params['order'] = array(
   930 			'description'       => __( 'Order sort attribute ascending or descending.' ),
   968 			'description' => __( 'Order sort attribute ascending or descending.' ),
   931 			'type'              => 'string',
   969 			'type'        => 'string',
   932 			'default'           => 'asc',
   970 			'default'     => 'asc',
   933 			'enum'              => array(
   971 			'enum'        => array(
   934 				'asc',
   972 				'asc',
   935 				'desc',
   973 				'desc',
   936 			),
   974 			),
   937 		);
   975 		);
   938 
   976 
   939 		$query_params['orderby'] = array(
   977 		$query_params['orderby'] = array(
   940 			'description'       => __( 'Sort collection by term attribute.' ),
   978 			'description' => __( 'Sort collection by term attribute.' ),
   941 			'type'              => 'string',
   979 			'type'        => 'string',
   942 			'default'           => 'name',
   980 			'default'     => 'name',
   943 			'enum'              => array(
   981 			'enum'        => array(
   944 				'id',
   982 				'id',
   945 				'include',
   983 				'include',
   946 				'name',
   984 				'name',
   947 				'slug',
   985 				'slug',
   948 				'include_slugs',
   986 				'include_slugs',
   951 				'count',
   989 				'count',
   952 			),
   990 			),
   953 		);
   991 		);
   954 
   992 
   955 		$query_params['hide_empty'] = array(
   993 		$query_params['hide_empty'] = array(
   956 			'description'       => __( 'Whether to hide terms not assigned to any posts.' ),
   994 			'description' => __( 'Whether to hide terms not assigned to any posts.' ),
   957 			'type'              => 'boolean',
   995 			'type'        => 'boolean',
   958 			'default'           => false,
   996 			'default'     => false,
   959 		);
   997 		);
   960 
   998 
   961 		if ( $taxonomy->hierarchical ) {
   999 		if ( $taxonomy->hierarchical ) {
   962 			$query_params['parent'] = array(
  1000 			$query_params['parent'] = array(
   963 				'description'       => __( 'Limit result set to terms assigned to a specific parent.' ),
  1001 				'description' => __( 'Limit result set to terms assigned to a specific parent.' ),
   964 				'type'              => 'integer',
  1002 				'type'        => 'integer',
   965 			);
  1003 			);
   966 		}
  1004 		}
   967 
  1005 
   968 		$query_params['post'] = array(
  1006 		$query_params['post'] = array(
   969 			'description'       => __( 'Limit result set to terms assigned to a specific post.' ),
  1007 			'description' => __( 'Limit result set to terms assigned to a specific post.' ),
   970 			'type'              => 'integer',
  1008 			'type'        => 'integer',
   971 			'default'           => null,
  1009 			'default'     => null,
   972 		);
  1010 		);
   973 
  1011 
   974 		$query_params['slug'] = array(
  1012 		$query_params['slug'] = array(
   975 			'description'       => __( 'Limit result set to terms with one or more specific slugs.' ),
  1013 			'description' => __( 'Limit result set to terms with one or more specific slugs.' ),
   976 			'type'              => 'array',
  1014 			'type'        => 'array',
   977 			'items'             => array(
  1015 			'items'       => array(
   978 				'type'          => 'string'
  1016 				'type' => 'string',
   979 			),
  1017 			),
   980 		);
  1018 		);
   981 
  1019 
   982 		/**
  1020 		/**
   983 		 * Filter collection parameters for the terms controller.
  1021 		 * Filter collection parameters for the terms controller.