acf_validate_value()
This function will validate a field's value
Хуки из функции
Возвращает
null. Ничего (null).
Использование
acf_validate_value( $value, $field, $input );
- $value(обязательный)
- .
- $field(обязательный)
- .
- $input(обязательный)
- .
Список изменений
| С версии 5.0.0 | Введена. |
Код acf_validate_value() acf validate value ACF 6.4.2
function acf_validate_value( $value, $field, $input ) {
// vars
$valid = true;
$message = sprintf( __( '%s value is required', 'acf' ), $field['label'] );
// valid
if ( $field['required'] ) {
// valid is set to false if the value is empty, but allow 0 as a valid value
if ( empty( $value ) && ! is_numeric( $value ) ) {
$valid = false;
}
}
/**
* Filters whether the value is valid.
*
* @date 28/09/13
* @since 5.0.0
*
* @param bool $valid The valid status. Return a string to display a custom error message.
* @param mixed $value The value.
* @param array $field The field array.
* @param string $input The input element's name attribute.
*/
$valid = apply_filters( "acf/validate_value/type={$field['type']}", $valid, $value, $field, $input );
$valid = apply_filters( "acf/validate_value/name={$field['_name']}", $valid, $value, $field, $input );
$valid = apply_filters( "acf/validate_value/key={$field['key']}", $valid, $value, $field, $input );
$valid = apply_filters( 'acf/validate_value', $valid, $value, $field, $input );
// allow $valid to be a custom error message
if ( ! empty( $valid ) && is_string( $valid ) ) {
$message = $valid;
$valid = false;
}
if ( ! $valid ) {
acf_add_validation_error( $input, $message );
return false;
}
// return
return true;
}