WC_REST_Terms_Controller::get_collection_params │ public │ WC 1.0

Get the query params for collections

Метод класса: WC_REST_Terms_Controller{}

Хуки из метода

Возвращает

array.

Использование

$WC_REST_Terms_Controller = new WC_REST_Terms_Controller();
$WC_REST_Terms_Controller->get_collection_params();

Код WC_REST_Terms_Controller::get_collection_params() WC 11.3.0

public function get_collection_params() {
	$params = parent::get_collection_params();

	$params['context']['default'] = 'view';

	$params['exclude']    = array(
		'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
		'type'              => 'array',
		'items'             => array(
			'type' => 'integer',
		),
		'default'           => array(),
		'sanitize_callback' => 'wp_parse_id_list',
	);
	$params['include']    = array(
		'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
		'type'              => 'array',
		'items'             => array(
			'type' => 'integer',
		),
		'default'           => array(),
		'sanitize_callback' => 'wp_parse_id_list',
	);
	$params['offset']     = array(
		'description'       => __( 'Offset the result set by a specific number of items. Applies to hierarchical taxonomies only.', 'woocommerce' ),
		'type'              => 'integer',
		'sanitize_callback' => 'absint',
		'validate_callback' => 'rest_validate_request_arg',
	);
	$params['order']      = array(
		'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
		'type'              => 'string',
		'sanitize_callback' => 'sanitize_key',
		'default'           => 'asc',
		'enum'              => array(
			'asc',
			'desc',
		),
		'validate_callback' => 'rest_validate_request_arg',
	);
	$params['orderby']    = array(
		'description'       => __( 'Sort collection by resource attribute.', 'woocommerce' ),
		'type'              => 'string',
		'sanitize_callback' => 'sanitize_key',
		'default'           => 'name',
		'enum'              => array(
			'id',
			'include',
			'name',
			'slug',
			'term_group',
			'description',
			'count',
		),
		'validate_callback' => 'rest_validate_request_arg',
	);
	$params['hide_empty'] = array(
		'description'       => __( 'Whether to hide resources not assigned to any products.', 'woocommerce' ),
		'type'              => 'boolean',
		'default'           => false,
		'validate_callback' => 'rest_validate_request_arg',
	);
	$params['parent']     = array(
		'description'       => __( 'Limit result set to resources assigned to a specific parent. Applies to hierarchical taxonomies only.', 'woocommerce' ),
		'type'              => 'integer',
		'sanitize_callback' => 'absint',
		'validate_callback' => 'rest_validate_request_arg',
	);
	$params['product']    = array(
		'description'       => __( 'Limit result set to resources assigned to a specific product.', 'woocommerce' ),
		'type'              => 'integer',
		'default'           => null,
		'validate_callback' => 'rest_validate_request_arg',
	);
	$params['slug']       = array(
		'description'       => __( 'Limit result set to resources with a specific slug.', 'woocommerce' ),
		'type'              => array( 'string', 'array' ),
		'items'             => array(
			'type' => 'string',
		),
		'validate_callback' => 'rest_validate_request_arg',
	);

	$taxonomy_obj = get_taxonomy( $this->taxonomy );

	// Empty for the attribute terms route, which serves every pa_* taxonomy from one registration.
	if ( ! $taxonomy_obj ) {
		return $params;
	}

	/**
	 * Filter collection parameters for the terms controller.
	 *
	 * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
	 * Shares its name with the WordPress core hook, so a callback added for a taxonomy served by
	 * both /wp/v2 and /wc/v3 runs for both.
	 *
	 * This filter only registers parameters; use `woocommerce_rest_{$taxonomy}_query`
	 * to map them to `WP_Term_Query` arguments.
	 *
	 * @since 11.3.0
	 *
	 * @param array       $params   JSON Schema-formatted collection parameters.
	 * @param WP_Taxonomy $taxonomy Taxonomy object.
	 */
	return apply_filters( "rest_{$this->taxonomy}_collection_params", $params, $taxonomy_obj );
}