WooCommerce Code Reference

Options extends WC_REST_Data_Controller
in package

Options Controller.

Tags
deprecated

since 6.2.0

extends

WC_REST_Data_Controller

Table of Contents

$namespace  : string
Endpoint namespace.
$rest_base  : string
Route base.
$_fields  : null|array<string|int, mixed>
Used to cache computed return fields.
$_request  : null|WP_REST_Request
Used to verify if cached fields are for correct request object.
batch_items()  : array<string|int, mixed>
Bulk create, update and delete items.
get_default_option_permissions()  : array<string|int, mixed>
Get the default available option permissions.
get_endpoint_args_for_item_schema()  : array<string|int, mixed>
Compatibility functions for WP 5.5, since custom types are not supported anymore.
get_fields_for_response()  : array<string|int, mixed>
Gets an array of fields to be included on the response.
get_item_permissions_check()  : WP_Error|bool
Check if a given request has access to get options.
get_item_schema()  : array<string|int, mixed>
Get the schema, conforming to JSON Schema.
get_items()  : WP_Error|WP_REST_Response
Return the list of data resources.
get_items_permissions_check()  : WP_Error|bool
Check whether a given request has permission to read site data.
get_option_permissions()  : array<string|int, mixed>
Get an array of options and respective permissions for the current user.
get_options()  : array<string|int, mixed>
Gets an array of options and respective values.
get_public_batch_schema()  : array<string|int, mixed>
Get the batch schema, conforming to JSON Schema.
prepare_item_for_response()  : WP_REST_Response
Prepare a data resource object for serialization.
register_routes()  : mixed
Register routes.
update_item_permissions_check()  : WP_Error|bool
Check if a given request has access to update options.
update_options()  : array<string|int, mixed>
Updates an array of objects.
user_has_permission()  : bool
Check if the user has permission given an option name.
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<string|int, mixed>|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<string|int, mixed>
Add the schema from additional fields to an schema array.
add_meta_query()  : array<string|int, mixed>
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_meta_data_for_response()  : array<string|int, mixed>
Limit the contents of the meta_data property based on certain request parameters.
get_normalized_rest_base()  : string
Get normalized rest base.
prepare_links()  : array<string|int, mixed>
Prepare links for the request.

Properties

Methods

batch_items()

Bulk create, update and delete items.

public batch_items(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
array<string|int, mixed>Of WP_Error or WP_REST_Response.

get_default_option_permissions()

Get the default available option permissions.

public static get_default_option_permissions() : array<string|int, mixed>
Return values
array<string|int, mixed>

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([string $method = WP_REST_Server::CREATABLE ]) : array<string|int, mixed>

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<string|int, mixed>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<string|int, mixed>

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
array<string|int, mixed>Fields to be included in the response.

get_item_permissions_check()

Check if a given request has access to get options.

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|bool

get_item_schema()

Get the schema, conforming to JSON Schema.

public get_item_schema() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_option_permissions()

Get an array of options and respective permissions for the current user.

public get_option_permissions(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
array<string|int, mixed>

get_options()

Gets an array of options and respective values.

public get_options(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
array<string|int, mixed>Options object with option values.

prepare_item_for_response()

Prepare a data resource object for serialization.

public prepare_item_for_response(stdClass $resource, WP_REST_Request $request) : WP_REST_Response
Parameters
$resource : stdClass

Resource data.

$request : WP_REST_Request

Request object.

Return values
WP_REST_Response$response Response data.

update_item_permissions_check()

Check if a given request has access to update options.

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|bool

update_options()

Updates an array of objects.

public update_options(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
array<string|int, mixed>Options object with a boolean if the option was updated.

user_has_permission()

Check if the user has permission given an option name.

public user_has_permission(string $option, WP_REST_Request $request[, bool $is_update = false ]) : bool
Parameters
$option : string

Option name.

$request : WP_REST_Request

Full details about the request.

$is_update : bool = false

If the request is to update the option.

Return values
bool

validate_setting_checkbox_field()

Validate checkbox based settings.

public validate_setting_checkbox_field(string $value, array<string|int, mixed> $setting) : string|WP_Error
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

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<string|int, mixed> $values, array<string|int, mixed> $setting) : string|WP_Error
Parameters
$values : array<string|int, mixed>

Values.

$setting : array<string|int, mixed>

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<string|int, mixed> $values, array<string|int, mixed> $setting) : array<string|int, mixed>|WP_Error
Parameters
$values : array<string|int, mixed>

Values.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
array<string|int, mixed>|WP_Error

validate_setting_radio_field()

Validate radio based settings.

public validate_setting_radio_field(string $value, array<string|int, mixed> $setting) : string|WP_Error
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string|WP_Error

validate_setting_select_field()

Validate select based settings.

public validate_setting_select_field(string $value, array<string|int, mixed> $setting) : string|WP_Error
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string|WP_Error

validate_setting_text_field()

Validate a text value for a text based setting.

public validate_setting_text_field(string $value, array<string|int, mixed> $setting) : string
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string

validate_setting_textarea_field()

Validate textarea based settings.

public validate_setting_textarea_field(string $value, array<string|int, mixed> $setting) : string
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string

add_additional_fields_schema()

Add the schema from additional fields to an schema array.

protected add_additional_fields_schema(array<string|int, mixed> $schema) : array<string|int, mixed>

The type of object is inferred from the passed schema.

Parameters
$schema : array<string|int, mixed>

Schema array.

Return values
array<string|int, mixed>

add_meta_query()

Add meta query.

protected add_meta_query(array<string|int, mixed> $args, array<string|int, mixed> $meta_query) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Query args.

$meta_query : array<string|int, mixed>

Meta query.

Tags
since
3.0.0
Return values
array<string|int, mixed>

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<string|int, mixed> $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<string|int, mixed>

Schema with datatypes to convert.

Return values
mixedSchema with converted datatype.

get_meta_data_for_response()

Limit the contents of the meta_data property based on certain request parameters.

protected get_meta_data_for_response(WP_REST_Request $request, array<string|int, mixed> $meta_data) : array<string|int, mixed>

Note that if both include_meta and exclude_meta are present in the request, include_meta will take precedence.

Parameters
$request : WP_REST_Request

The request.

$meta_data : array<string|int, mixed>

All of the meta data for an object.

Return values
array<string|int, mixed>