WooCommerce Code Reference

WC_REST_Settings_V2_Controller extends WC_REST_Controller

REST API Settings controller class.

Tags
extends

WC_REST_Controller

Table of Contents

$namespace  : string
WP REST API namespace/version.
$rest_base  : string
Route base.
allowed_group_keys()  : bool
Callback for allowed keys for each group response.
batch_items()  : array
Bulk create, update and delete items.
filter_group()  : array
Filters out bad values from the groups 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_item_schema()  : array
Get the groups schema, conforming to JSON Schema.
get_items()  : WP_Error|WP_REST_Response
Get all settings groups items.
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.
prepare_item_for_response()  : WP_REST_Response
Prepare a report sales object for serialization.
register_routes()  : mixed
Register routes.
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.
group_defaults()  : array
Returns default settings for groups. null means the field is required.
prepare_links()  : array
Prepare links for the request.

Properties

Methods

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
since
3.5.0
Return values
arrayFields to be included in the response.

prepare_item_for_response()

Prepare a report sales object for serialization.

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

Group object.

$request : WP_REST_Request

Request object.

Tags
since
3.0.0
Return values
WP_REST_Response$response Response data.

validate_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
since
3.0.0
Return values
string|WP_Error

validate_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
since
3.0.0
Return values
string|WP_Error

validate_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
since
3.0.0
Return values
array|WP_Error

add_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
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.

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
mixedSchema with converted datatype.