acf_field_select::validate_rest_value
Validates select fields updated via the REST API.
Метод класса: acf_field_select{}
Хуков нет.
Возвращает
true|false|WP_Error.
Использование
$acf_field_select = new acf_field_select(); $acf_field_select->validate_rest_value( $valid, $value, $field );
- $valid(true|false) (обязательный)
- The current validity booleean.
- $value(int) (обязательный)
- The value of the field.
- $field(массив) (обязательный)
- The field array.
Код acf_field_select::validate_rest_value() acf field select::validate rest value ACF 6.4.2
public function validate_rest_value( $valid, $value, $field ) {
// rest_validate_request_arg() handles the other types, we just worry about strings.
if ( is_null( $value ) || is_array( $value ) ) {
return $valid;
}
$option_keys = array_diff(
array_keys( $field['choices'] ),
array_values( $field['choices'] )
);
$allowed = empty( $option_keys ) ? $field['choices'] : $option_keys;
if ( ! in_array( $value, $allowed ) ) {
$param = sprintf( '%s[%s]', $field['prefix'], $field['name'] );
$data = array(
'param' => $param,
'value' => $value,
);
$error = sprintf(
__( '%1$s is not one of %2$s', 'acf' ),
$param,
implode( ', ', $allowed )
);
return new WP_Error( 'rest_invalid_param', $error, $data );
}
return $valid;
}