WC_REST_Setting_Options_V2_Controller
extends WC_REST_Controller
in package
REST API Setting Options controller class.
Tags
Table of Contents
- $namespace : string
- WP REST API namespace/version.
- $rest_base : string
- Route base.
- $_fields : null|array
- Used to cache computed return fields.
- $_request : null|WP_REST_Request
- Used to verify if cached fields are for correct request object.
- allowed_setting_keys() : bool
- Callback for allowed keys for each setting response.
- batch_items() : array
- Bulk create, update and delete items.
- cast_image_width() : array
- For image_width, Crop can return "0" instead of false -- so we want to make sure we return these consistently the same we accept them.
- filter_setting() : array
- Filters out bad values from the settings array/filter so we only return known values via the API.
- 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_group_settings() : array|WP_Error
- Get all settings in a group.
- get_item() : WP_Error|WP_REST_Response
- Return a single setting.
- get_item_schema() : array
- Get the settings schema, conforming to JSON Schema.
- get_items() : WP_Error|WP_REST_Response
- Return all settings in a group.
- get_items_permissions_check() : WP_Error|bool
- Makes sure the current user has access to READ the settings APIs.
- get_public_batch_schema() : array
- Get the batch schema, conforming to JSON Schema.
- get_setting() : stdClass|WP_Error
- Get setting data.
- is_setting_type_valid() : bool
- Boolean for if a setting type is a valid supported setting type.
- prepare_item_for_response() : WP_REST_Response
- Prepare a single setting object for response.
- register_routes() : mixed
- Register routes.
- update_item() : WP_Error|WP_REST_Response
- Update a single setting in a group.
- update_items_permissions_check() : WP_Error|bool
- Makes sure the current user has access to WRITE the settings APIs.
- 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.
- get_normalized_rest_base() : string
- Get normalized rest base.
- prepare_links() : array
- Prepare links for the request.
- get_countries_and_states() : array
- Returns a list of countries and states for use in the base location setting.
Properties
$namespace
WP REST API namespace/version.
protected
string
$namespace
= 'wc/v2'
$rest_base
Route base.
protected
string
$rest_base
= 'settings/(?P<group_id>[\w-]+)'
$_fields
Used to cache computed return fields.
private
null|array
$_fields
=
ull
$_request
Used to verify if cached fields are for correct request object.
private
null|WP_REST_Request
$_request
=
ull
Methods
allowed_setting_keys()
Callback for allowed keys for each setting response.
public
allowed_setting_keys(string $key) : bool
Parameters
- $key : string
-
Key to check.
Tags
Return values
boolbatch_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.
Tags
Return values
array — Of WP_Error or WP_REST_Response.cast_image_width()
For image_width, Crop can return "0" instead of false -- so we want to make sure we return these consistently the same we accept them.
public
cast_image_width(array $setting) : array
Parameters
- $setting : array
-
Settings.
Tags
Return values
arrayfilter_setting()
Filters out bad values from the settings array/filter so we only return known values via the API.
public
filter_setting(array $setting) : array
Parameters
- $setting : array
-
Settings.
Tags
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_group_settings()
Get all settings in a group.
public
get_group_settings(string $group_id) : array|WP_Error
Parameters
- $group_id : string
-
Group ID.
Tags
Return values
array|WP_Errorget_item()
Return a single setting.
public
get_item(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
- $request : WP_REST_Request
-
Request data.
Tags
Return values
WP_Error|WP_REST_Responseget_item_schema()
Get the settings schema, conforming to JSON Schema.
public
get_item_schema() : array
Tags
Return values
arrayget_items()
Return all settings in a group.
public
get_items(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
- $request : WP_REST_Request
-
Request data.
Tags
Return values
WP_Error|WP_REST_Responseget_items_permissions_check()
Makes sure the current user has access to READ the settings APIs.
public
get_items_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
Full data about the request.
Tags
Return values
WP_Error|boolget_public_batch_schema()
Get the batch schema, conforming to JSON Schema.
public
get_public_batch_schema() : array
Return values
arrayget_setting()
Get setting data.
public
get_setting(string $group_id, string $setting_id) : stdClass|WP_Error
Parameters
- $group_id : string
-
Group ID.
- $setting_id : string
-
Setting ID.
Tags
Return values
stdClass|WP_Erroris_setting_type_valid()
Boolean for if a setting type is a valid supported setting type.
public
is_setting_type_valid(string $type) : bool
Parameters
- $type : string
-
Type.
Tags
Return values
boolprepare_item_for_response()
Prepare a single setting object for response.
public
prepare_item_for_response(object $item, WP_REST_Request $request) : WP_REST_Response
Parameters
- $item : object
-
Setting object.
- $request : WP_REST_Request
-
Request object.
Tags
Return values
WP_REST_Response — $response Response data.register_routes()
Register routes.
public
register_routes() : mixed
Tags
Return values
mixedupdate_item()
Update a single setting in a group.
public
update_item(WP_REST_Request $request) : WP_Error|WP_REST_Response
Parameters
- $request : WP_REST_Request
-
Request data.
Tags
Return values
WP_Error|WP_REST_Responseupdate_items_permissions_check()
Makes sure the current user has access to WRITE the settings APIs.
public
update_items_permissions_check(WP_REST_Request $request) : WP_Error|bool
Parameters
- $request : WP_REST_Request
-
Full data about the request.
Tags
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_Errorget_normalized_rest_base()
Get normalized rest base.
protected
get_normalized_rest_base() : string
Return values
stringprepare_links()
Prepare links for the request.
protected
prepare_links(string $setting_id, string $group_id) : array
Parameters
- $setting_id : string
-
Setting ID.
- $group_id : string
-
Group ID.
Tags
Return values
array — Links for the given setting.get_countries_and_states()
Returns a list of countries and states for use in the base location setting.
private
get_countries_and_states() : array