WooCommerce Code Reference

Search results

WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V2_Controller

REST API Product Categories controller class.

Table of Contents

$namespace Endpoint namespace. string
$namespace Endpoint namespace. string
$rest_base Route base. string
$taxonomy Taxonomy. string
prepare_item_for_response() Prepare a single product category output for response. WP_REST_Response
get_item_schema() Get the Category schema, conforming to JSON Schema. array
update_term_meta_fields() Update term meta fields. bool|WP_Error
prepare_item_for_response() Prepare a single product category output for response. WP_REST_Response
get_item_schema() Get the Category schema, conforming to JSON Schema. array
update_term_meta_fields() Update term meta fields. bool|WP_Error
register_routes() Register the routes for terms. mixed
get_items_permissions_check() Check if a given request has access to read the terms. WP_Error|bool
create_item_permissions_check() Check if a given request has access to create a term. WP_Error|bool
get_item_permissions_check() Check if a given request has access to read a term. WP_Error|bool
update_item_permissions_check() Check if a given request has access to update a term. WP_Error|bool
delete_item_permissions_check() Check if a given request has access to delete a term. WP_Error|bool
batch_items_permissions_check() Check if a given request has access batch create, update and delete items. bool|WP_Error
check_permissions() Check permissions. bool|WP_Error
get_items() Get terms associated with a taxonomy. WP_REST_Response|WP_Error
create_item() Create a single term for a taxonomy. WP_REST_Request|WP_Error
get_item() Get a single term from a taxonomy. WP_REST_Request|WP_Error
update_item() Update a single term from a taxonomy. WP_REST_Request|WP_Error
delete_item() Delete a single term from a taxonomy. WP_REST_Response|WP_Error
prepare_links() Prepare links for the request. array
get_terms_for_product() Get the terms attached to a product. array
compare_terms() Comparison function for sorting terms by a column. int
get_collection_params() Get the query params for collections array
get_taxonomy() Get taxonomy. int|WP_Error
add_additional_fields_schema() Add the schema from additional fields to an schema array. array
get_endpoint_args_for_item_schema() Compatibility functions for WP 5.5, since custom types are not supported anymore. array
adjust_wp_5_5_datatype_compatibility() Change datatypes `date-time` to string, and `mixed` to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore. mixed
get_normalized_rest_base() Get normalized rest base. string
check_batch_limit() Check batch limit. bool|WP_Error
batch_items() Bulk create, update and delete items. array
validate_setting_text_field() Validate a text value for a text based setting. string
validate_setting_select_field() Validate select based settings. string|WP_Error
validate_setting_multiselect_field() Validate multiselect based settings. array|WP_Error
validate_setting_image_width_field() Validate image_width based settings. string|WP_Error
validate_setting_radio_field() Validate radio based settings. string|WP_Error
validate_setting_checkbox_field() Validate checkbox based settings. string|WP_Error
validate_setting_textarea_field() Validate textarea based settings. string
add_meta_query() Add meta query. array
get_public_batch_schema() Get the batch schema, conforming to JSON Schema. array
get_fields_for_response() Gets an array of fields to be included on the response. array

Properties

Methods

prepare_item_for_response()

Prepare a single product category output for response.

public prepare_item_for_response( $item : WP_Term , $request : WP_REST_Request ) : WP_REST_Response
Parameters
$item : WP_Term

Term object.

$request : WP_REST_Request

Request instance.

Return values
WP_REST_Response

update_term_meta_fields()

Update term meta fields.

protected update_term_meta_fields( $term : WP_Term , $request : WP_REST_Request ) : bool|WP_Error
Parameters
$term : WP_Term

Term object.

$request : WP_REST_Request

Request instance.

Tags
since
Return values
bool|WP_Error

prepare_item_for_response()

Prepare a single product category output for response.

public prepare_item_for_response( $item : WP_Term , $request : WP_REST_Request ) : WP_REST_Response
Parameters
$item : WP_Term

Term object.

$request : WP_REST_Request

Request instance.

Return values
WP_REST_Response

update_term_meta_fields()

Update term meta fields.

protected update_term_meta_fields( $term : WP_Term , $request : WP_REST_Request ) : bool|WP_Error
Parameters
$term : WP_Term

Term object.

$request : WP_REST_Request

Full details about the request.

Return values
bool|WP_Error

get_items_permissions_check()

Check if a given request has access to read the terms.

public get_items_permissions_check( $request : WP_REST_Request ) : WP_Error|bool
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|bool

create_item_permissions_check()

Check if a given request has access to create a term.

public create_item_permissions_check( $request : WP_REST_Request ) : WP_Error|bool
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|bool

get_item_permissions_check()

Check if a given request has access to read a term.

public get_item_permissions_check( $request : WP_REST_Request ) : WP_Error|bool
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|bool

update_item_permissions_check()

Check if a given request has access to update a term.

public update_item_permissions_check( $request : WP_REST_Request ) : WP_Error|bool
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|bool

delete_item_permissions_check()

Check if a given request has access to delete a term.

public delete_item_permissions_check( $request : WP_REST_Request ) : WP_Error|bool
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_Error|bool

batch_items_permissions_check()

Check if a given request has access batch create, update and delete items.

public batch_items_permissions_check( $request : WP_REST_Request ) : bool|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
bool|WP_Error

check_permissions()

Check permissions.

protected check_permissions( $request : WP_REST_Request [, $context : string = 'read' ] ) : bool|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

$context : string = 'read'

Request context.

Return values
bool|WP_Error

get_items()

Get terms associated with a taxonomy.

public get_items( $request : WP_REST_Request ) : WP_REST_Response|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_REST_Response|WP_Error

create_item()

Create a single term for a taxonomy.

public create_item( $request : WP_REST_Request ) : WP_REST_Request|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_REST_Request|WP_Error

get_item()

Get a single term from a taxonomy.

public get_item( $request : WP_REST_Request ) : WP_REST_Request|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_REST_Request|WP_Error

update_item()

Update a single term from a taxonomy.

public update_item( $request : WP_REST_Request ) : WP_REST_Request|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_REST_Request|WP_Error

delete_item()

Delete a single term from a taxonomy.

public delete_item( $request : WP_REST_Request ) : WP_REST_Response|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
WP_REST_Response|WP_Error

prepare_links()

Prepare links for the request.

protected prepare_links( $term : object , $request : WP_REST_Request ) : array
Parameters
$term : object

Term object.

$request : WP_REST_Request

Full details about the request.

Return values
array

Links for the given term.

get_terms_for_product()

Get the terms attached to a product.

protected get_terms_for_product( $prepared_args : array , $request : WP_REST_Request ) : array

This is an alternative to get_terms() that uses get_the_terms() instead, which hits the object cache. There are a few things not supported, notably include, exclude. In self::get_items() these are instead treated as a full query.

Parameters
$prepared_args : array

Arguments for get_terms().

$request : WP_REST_Request

Full details about the request.

Return values
array

List of term objects. (Total count in $this->total_terms).

compare_terms()

Comparison function for sorting terms by a column.

protected compare_terms( $left : stdClass , $right : stdClass ) : int

Uses $this->sort_column to determine field to sort by.

Parameters
$left : stdClass

Term object.

$right : stdClass

Term object.

Return values
int

<0 if left is higher "priority" than right, 0 if equal, >0 if right is higher "priority" than left.

get_taxonomy()

Get taxonomy.

protected get_taxonomy( $request : WP_REST_Request ) : int|WP_Error
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
int|WP_Error

add_additional_fields_schema()

Add the schema from additional fields to an schema array.

protected add_additional_fields_schema( $schema : array ) : array

The type of object is inferred from the passed schema.

Parameters
$schema : array

Schema array.

Return values
array

get_endpoint_args_for_item_schema()

Compatibility functions for WP 5.5, since custom types are not supported anymore.

public get_endpoint_args_for_item_schema( [ $method : string = WP_REST_Server::CREATABLE ] ) : array

See @link https://core.trac.wordpress.org/changeset/48306

Parameters
$method : string = WP_REST_Server::CREATABLE

Optional. HTTP method of the request.

Return values
array

Endpoint arguments.

adjust_wp_5_5_datatype_compatibility()

Change datatypes `date-time` to string, and `mixed` to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore.

protected adjust_wp_5_5_datatype_compatibility( $endpoint_args : array ) : mixed

See @link https://core.trac.wordpress.org/changeset/48306

We still use the 'mixed' type, since if we convert to composite type everywhere, it won't work in 5.4 anymore because they require to define the full schema.

Parameters
$endpoint_args : array

Schema with datatypes to convert.

Return values
mixed

Schema with converted datatype.

get_normalized_rest_base()

Get normalized rest base.

protected get_normalized_rest_base( ) : string
Return values
string

check_batch_limit()

Check batch limit.

protected check_batch_limit( $items : array ) : bool|WP_Error
Parameters
$items : array

Request items.

Return values
bool|WP_Error

batch_items()

Bulk create, update and delete items.

public batch_items( $request : WP_REST_Request ) : array
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
array

Of WP_Error or WP_REST_Response.

validate_setting_text_field()

Validate a text value for a text based setting.

public validate_setting_text_field( $value : string , $setting : array ) : string
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string

validate_setting_select_field()

Validate select based settings.

public validate_setting_select_field( $value : string , $setting : array ) : string|WP_Error
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string|WP_Error

validate_setting_multiselect_field()

Validate multiselect based settings.

public validate_setting_multiselect_field( $values : array , $setting : array ) : array|WP_Error
Parameters
$values : array

Values.

$setting : array

Setting.

Tags
since
Return values
array|WP_Error

validate_setting_image_width_field()

Validate image_width based settings.

public validate_setting_image_width_field( $values : array , $setting : array ) : string|WP_Error
Parameters
$values : array

Values.

$setting : array

Setting.

Tags
since
Return values
string|WP_Error

validate_setting_radio_field()

Validate radio based settings.

public validate_setting_radio_field( $value : string , $setting : array ) : string|WP_Error
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string|WP_Error

validate_setting_checkbox_field()

Validate checkbox based settings.

public validate_setting_checkbox_field( $value : string , $setting : array ) : string|WP_Error
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string|WP_Error

validate_setting_textarea_field()

Validate textarea based settings.

public validate_setting_textarea_field( $value : string , $setting : array ) : string
Parameters
$value : string

Value.

$setting : array

Setting.

Tags
since
Return values
string

add_meta_query()

Add meta query.

protected add_meta_query( $args : array , $meta_query : array ) : array
Parameters
$args : array

Query args.

$meta_query : array

Meta query.

Tags
since
Return values
array

get_public_batch_schema()

Get the batch schema, conforming to JSON Schema.

public get_public_batch_schema( ) : array
Return values
array

get_fields_for_response()

Gets an array of fields to be included on the response.

public get_fields_for_response( $request : WP_REST_Request ) : array

Included fields are based on item schema and _fields= request argument. Updated from WordPress 5.3, included into this class to support old versions.

Parameters
$request : WP_REST_Request

Full details about the request.

Tags
since
Return values
array

Fields to be included in the response.

Back to the top