WC_REST_Products_Catalog_Controller::validate_fields_arg
Validate fields argument.
Method of the class: WC_REST_Products_Catalog_Controller{}
No Hooks.
Returns
true|WP_Error. True if valid, WP_Error otherwise.
Usage
$WC_REST_Products_Catalog_Controller = new WC_REST_Products_Catalog_Controller(); $WC_REST_Products_Catalog_Controller->validate_fields_arg( $value );
- $value(mixed) (required)
- The value to validate.
WC_REST_Products_Catalog_Controller::validate_fields_arg() WC REST Products Catalog Controller::validate fields arg code WC 10.4.3
public function validate_fields_arg( $value ) {
if ( ! is_array( $value ) && ! is_string( $value ) ) {
return new WP_Error( 'invalid_fields', __( 'fields must be an array of strings or a comma-separated string.', 'woocommerce' ) );
}
if ( ( is_array( $value ) && empty( $value ) ) || ( is_string( $value ) && '' === trim( $value ) ) ) {
return new WP_Error( 'invalid_fields', __( 'fields cannot be empty.', 'woocommerce' ) );
}
return true;
}