WooCommerce Code Reference

Search results

WC_REST_Setting_Options_Controller extends WC_REST_Setting_Options_V2_Controller

REST API Setting Options controller class.

Table of Contents

$namespace Endpoint namespace. string
$namespace Endpoint namespace. string
$rest_base Route base. string
get_setting() Get setting data. stdClass|WP_Error
allowed_setting_keys() Callback for allowed keys for each setting response. bool
get_group_settings() Get all settings in a group. array|WP_Error
get_countries_and_states() Returns a list of countries and states for use in the base location setting. array
get_item_schema() Get the settings schema, conforming to JSON Schema. array
register_routes() Register routes. mixed
get_item() Return a single setting. WP_Error|WP_REST_Response
get_items() Return all settings in a group. WP_Error|WP_REST_Response
get_group_settings() Get all settings in a group. array|WP_Error
get_countries_and_states() Returns a list of countries and states for use in the base location setting. array
get_setting() Get setting data. stdClass|WP_Error
batch_items() Bulk create, update and delete items. array
update_item() Update a single setting in a group. WP_Error|WP_REST_Response
prepare_item_for_response() Prepare a single setting object for response. WP_REST_Response
prepare_links() Prepare links for the request. array
get_items_permissions_check() Makes sure the current user has access to READ the settings APIs. WP_Error|bool
update_items_permissions_check() Makes sure the current user has access to WRITE the settings APIs. WP_Error|bool
filter_setting() Filters out bad values from the settings array/filter so we only return known values via the API. array
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. array
allowed_setting_keys() Callback for allowed keys for each setting response. bool
is_setting_type_valid() Boolean for if a setting type is a valid supported setting type. bool
get_item_schema() Get the settings schema, conforming to JSON Schema. array
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
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

get_setting()

Get setting data.

public get_setting( $group_id : string , $setting_id : string ) : stdClass|WP_Error
Parameters
$group_id : string

Group ID.

$setting_id : string

Setting ID.

Return values
stdClass|WP_Error

allowed_setting_keys()

Callback for allowed keys for each setting response.

public allowed_setting_keys( $key : string ) : bool
Parameters
$key : string

Key to check.

Return values
bool

get_group_settings()

Get all settings in a group.

public get_group_settings( $group_id : string ) : array|WP_Error
Parameters
$group_id : string

Group ID.

Return values
array|WP_Error

get_countries_and_states()

Returns a list of countries and states for use in the base location setting.

private get_countries_and_states( ) : array
Tags
since
Return values
array

Array of states and countries.

get_item()

Return a single setting.

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

Request data.

Tags
since
Return values
WP_Error|WP_REST_Response

get_items()

Return all settings in a group.

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

Request data.

Tags
since
Return values
WP_Error|WP_REST_Response

get_group_settings()

Get all settings in a group.

public get_group_settings( $group_id : string ) : array|WP_Error
Parameters
$group_id : string

Group ID.

Tags
since
Return values
array|WP_Error

get_countries_and_states()

Returns a list of countries and states for use in the base location setting.

private get_countries_and_states( ) : array
Tags
since
Return values
array

Array of states and countries.

get_setting()

Get setting data.

public get_setting( $group_id : string , $setting_id : string ) : stdClass|WP_Error
Parameters
$group_id : string

Group ID.

$setting_id : string

Setting ID.

Tags
since
Return values
stdClass|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.

update_item()

Update a single setting in a group.

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

Request data.

Tags
since
Return values
WP_Error|WP_REST_Response

prepare_item_for_response()

Prepare a single setting object for response.

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

Setting object.

$request : WP_REST_Request

Request object.

Tags
since
Return values
WP_REST_Response

$response Response data.

prepare_links()

Prepare links for the request.

protected prepare_links( $setting_id : string , $group_id : string ) : array
Parameters
$setting_id : string

Setting ID.

$group_id : string

Group ID.

Tags
since
Return values
array

Links for the given setting.

get_items_permissions_check()

Makes sure the current user has access to READ the settings APIs.

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

Full data about the request.

Tags
since
Return values
WP_Error|bool

update_items_permissions_check()

Makes sure the current user has access to WRITE the settings APIs.

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

Full data about the request.

Tags
since
Return values
WP_Error|bool

filter_setting()

Filters out bad values from the settings array/filter so we only return known values via the API.

public filter_setting( $setting : array ) : array
Parameters
$setting : array

Settings.

Tags
since
Return values
array

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( $setting : array ) : array
Parameters
$setting : array

Settings.

Tags
todo

remove in 4.0

since
Return values
array

allowed_setting_keys()

Callback for allowed keys for each setting response.

public allowed_setting_keys( $key : string ) : bool
Parameters
$key : string

Key to check.

Tags
since
Return values
bool

is_setting_type_valid()

Boolean for if a setting type is a valid supported setting type.

public is_setting_type_valid( $type : string ) : bool
Parameters
$type : string

Type.

Tags
since
Return values
bool

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

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