WC_REST_Product_Shipping_Classes_V1_Controller
extends WC_REST_Terms_Controller
in package
REST API Product Shipping Classes controller class.
Tags
Table of Contents
- $namespace : string
- Endpoint namespace.
- $rest_base : string
- Route base.
- $taxonomy : string
- Taxonomy.
- batch_items() : array
- Bulk create, update and delete items.
- batch_items_permissions_check() : bool|WP_Error
- Check if a given request has access batch create, update and delete items.
- create_item() : WP_REST_Request|WP_Error
- Create a single term for a taxonomy.
- create_item_permissions_check() : WP_Error|bool
- Check if a given request has access to create a term.
- delete_item() : WP_REST_Response|WP_Error
- Delete a single term from a taxonomy.
- delete_item_permissions_check() : WP_Error|bool
- Check if a given request has access to delete a term.
- get_collection_params() : array
- Get the query params for collections
- get_endpoint_args_for_item_schema() : array
- Compatibility functions for WP 5.5, since custom types are not supported anymore.
- get_fields_for_response() : array
- Gets an array of fields to be included on the response.
- get_item() : WP_REST_Request|WP_Error
- Get a single term from a taxonomy.
- get_item_permissions_check() : WP_Error|bool
- Check if a given request has access to read a term.
- get_item_schema() : array
- Get the Shipping Class schema, conforming to JSON Schema.
- get_items() : WP_REST_Response|WP_Error
- Get terms associated with a taxonomy.
- get_items_permissions_check() : WP_Error|bool
- Check if a given request has access to read the terms.
- get_public_batch_schema() : array
- Get the batch schema, conforming to JSON Schema.
- prepare_item_for_response() : WP_REST_Response
- Prepare a single product shipping class output for response.
- register_routes() : mixed
- Register the routes for terms.
- update_item() : WP_REST_Request|WP_Error
- Update a single term from a taxonomy.
- update_item_permissions_check() : WP_Error|bool
- Check if a given request has access to update a term.
- validate_setting_checkbox_field() : string|WP_Error
- Validate checkbox based settings.
- validate_setting_image_width_field() : string|WP_Error
- Validate image_width based settings.
- validate_setting_multiselect_field() : array|WP_Error
- Validate multiselect based settings.
- validate_setting_radio_field() : string|WP_Error
- Validate radio based settings.
- validate_setting_select_field() : string|WP_Error
- Validate select based settings.
- validate_setting_text_field() : string
- Validate a text value for a text based setting.
- validate_setting_textarea_field() : string
- Validate textarea based settings.
- add_additional_fields_schema() : array
- Add the schema from additional fields to an schema array.
- add_meta_query() : array
- Add meta query.
- adjust_wp_5_5_datatype_compatibility() : mixed
- 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.
- check_batch_limit() : bool|WP_Error
- Check batch limit.
- check_permissions() : bool|WP_Error
- Check permissions.
- compare_terms() : int
- Comparison function for sorting terms by a column.
- get_normalized_rest_base() : string
- Get normalized rest base.
- get_taxonomy() : int|WP_Error
- Get taxonomy.
- get_terms_for_product() : array
- Get the terms attached to a product.
- prepare_links() : array
- Prepare links for the request.
- update_term_meta_fields() : bool|WP_Error
- Update term meta fields.
Properties
$namespace
Endpoint namespace.
protected
string
$namespace
= 'wc/v1'
$rest_base
Route base.
protected
string
$rest_base
= 'products/shipping_classes'
$taxonomy
Taxonomy.
protected
string
$taxonomy
= 'product_shipping_class'
Methods
batch_items()
Bulk create, update and delete items.
public
batch_items(WP_REST_Request $request) : array
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
array — Of WP_Error or WP_REST_Response.batch_items_permissions_check()
Check if a given request has access batch create, update and delete items.
public
batch_items_permissions_check(WP_REST_Request $request) : bool|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
bool|WP_Errorcreate_item()
Create a single term for a taxonomy.
public
create_item(WP_REST_Request $request) : WP_REST_Request|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_REST_Request|WP_Errorcreate_item_permissions_check()
Check if a given request has access to create a term.
public
create_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|booldelete_item()
Delete a single term from a taxonomy.
public
delete_item(WP_REST_Request $request) : WP_REST_Response|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_REST_Response|WP_Errordelete_item_permissions_check()
Check if a given request has access to delete a term.
public
delete_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|boolget_collection_params()
Get the query params for collections
public
get_collection_params() : array
Return values
arrayget_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([string $method = WP_REST_Server::CREATABLE ]) : array
Parameters
- $method : string = WP_REST_Server::CREATABLE
-
Optional. HTTP method of the request.
Return values
array — Endpoint arguments.get_fields_for_response()
Gets an array of fields to be included on the response.
public
get_fields_for_response(WP_REST_Request $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
Return values
array — Fields to be included in the response.get_item()
Get a single term from a taxonomy.
public
get_item(WP_REST_Request $request) : WP_REST_Request|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_REST_Request|WP_Errorget_item_permissions_check()
Check if a given request has access to read a term.
public
get_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|boolget_item_schema()
Get the Shipping Class schema, conforming to JSON Schema.
public
get_item_schema() : array
Return values
arrayget_items()
Get terms associated with a taxonomy.
public
get_items(WP_REST_Request $request) : WP_REST_Response|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_REST_Response|WP_Errorget_items_permissions_check()
Check if a given request has access to read the terms.
public
get_items_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|boolget_public_batch_schema()
Get the batch schema, conforming to JSON Schema.
public
get_public_batch_schema() : array
Return values
arrayprepare_item_for_response()
Prepare a single product shipping class output for response.
public
prepare_item_for_response(obj $item, WP_REST_Request $request) : WP_REST_Response
Parameters
- $item : obj
-
Term object.
- $request : WP_REST_Request
Return values
WP_REST_Response — $responseregister_routes()
Register the routes for terms.
public
register_routes() : mixed
Return values
mixedupdate_item()
Update a single term from a taxonomy.
public
update_item(WP_REST_Request $request) : WP_REST_Request|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_REST_Request|WP_Errorupdate_item_permissions_check()
Check if a given request has access to update a term.
public
update_item_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
WP_Error|boolvalidate_setting_checkbox_field()
Validate checkbox based settings.
public
validate_setting_checkbox_field(string $value, array $setting) : string|WP_Error
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
string|WP_Errorvalidate_setting_image_width_field()
Validate image_width based settings.
public
validate_setting_image_width_field(array $values, array $setting) : string|WP_Error
Parameters
- $values : array
-
Values.
- $setting : array
-
Setting.
Tags
Return values
string|WP_Errorvalidate_setting_multiselect_field()
Validate multiselect based settings.
public
validate_setting_multiselect_field(array $values, array $setting) : array|WP_Error
Parameters
- $values : array
-
Values.
- $setting : array
-
Setting.
Tags
Return values
array|WP_Errorvalidate_setting_radio_field()
Validate radio based settings.
public
validate_setting_radio_field(string $value, array $setting) : string|WP_Error
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
string|WP_Errorvalidate_setting_select_field()
Validate select based settings.
public
validate_setting_select_field(string $value, array $setting) : string|WP_Error
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
string|WP_Errorvalidate_setting_text_field()
Validate a text value for a text based setting.
public
validate_setting_text_field(string $value, array $setting) : string
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
stringvalidate_setting_textarea_field()
Validate textarea based settings.
public
validate_setting_textarea_field(string $value, array $setting) : string
Parameters
- $value : string
-
Value.
- $setting : array
-
Setting.
Tags
Return values
stringadd_additional_fields_schema()
Add the schema from additional fields to an schema array.
protected
add_additional_fields_schema(array $schema) : array
The type of object is inferred from the passed schema.
Parameters
- $schema : array
-
Schema array.
Return values
arrayadd_meta_query()
Add meta query.
protected
add_meta_query(array $args, array $meta_query) : array
Parameters
- $args : array
-
Query args.
- $meta_query : array
-
Meta query.
Tags
Return values
arrayadjust_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(array $endpoint_args) : 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.check_batch_limit()
Check batch limit.
protected
check_batch_limit(array $items) : bool|WP_Error
Parameters
- $items : array
-
Request items.
Return values
bool|WP_Errorcheck_permissions()
Check permissions.
protected
check_permissions(WP_REST_Request $request[, string $context = 'read' ]) : bool|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
- $context : string = 'read'
-
Request context.
Return values
bool|WP_Errorcompare_terms()
Comparison function for sorting terms by a column.
protected
compare_terms(stdClass $left, stdClass $right) : 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 right is higher "priority" than left.get_normalized_rest_base()
Get normalized rest base.
protected
get_normalized_rest_base() : string
Return values
stringget_taxonomy()
Get taxonomy.
protected
get_taxonomy(WP_REST_Request $request) : int|WP_Error
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
int|WP_Errorget_terms_for_product()
Get the terms attached to a product.
protected
get_terms_for_product(array $prepared_args, WP_REST_Request $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`).prepare_links()
Prepare links for the request.
protected
prepare_links(object $term, WP_REST_Request $request) : array
Parameters
- $term : object
-
Term object.
- $request : WP_REST_Request
-
Full details about the request.
Return values
array — Links for the given term.update_term_meta_fields()
Update term meta fields.
protected
update_term_meta_fields(WP_Term $term, WP_REST_Request $request) : bool|WP_Error
Parameters
- $term : WP_Term
-
Term object.
- $request : WP_REST_Request
-
Full details about the request.