WordPress at Your Fingertips
function is not described

WC_REST_Controller::validate_setting_checkbox_field() public WC 3.0.0

Validate checkbox based settings.

{} It's a method of the class: WC_REST_Controller{}

No Hooks.

Return

String|WP_Error.

Usage

$WC_REST_Controller = new WC_REST_Controller();
$WC_REST_Controller->validate_setting_checkbox_field( $value, $setting );
$value(string) (required)
Value.
$setting(array) (required)
Setting.

Changelog

Since 3.0.0 Introduced.

Code of WC_REST_Controller::validate_setting_checkbox_field() WC 5.9.0

public function validate_setting_checkbox_field( $value, $setting ) {
	if ( in_array( $value, array( 'yes', 'no' ) ) ) {
		return $value;
	} elseif ( empty( $value ) ) {
		$value = isset( $setting['default'] ) ? $setting['default'] : 'no';
		return $value;
	} else {
		return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
	}
}