acf_field_file::validate_rest_value()
Validates file fields updated via the REST API.
Метод класса: acf_field_file{}
Хуков нет.
Возвращает
true|false|WP_Error
.
Использование
$acf_field_file = new acf_field_file(); $acf_field_file->validate_rest_value( $valid, $value, $field );
- $valid(true|false) (обязательный)
- -
- $value(int) (обязательный)
- -
- $field(массив) (обязательный)
- -
Код acf_field_file::validate_rest_value() acf field file::validate rest value ACF 6.0.4
public function validate_rest_value( $valid, $value, $field ) { if ( is_null( $value ) && empty( $field['required'] ) ) { return $valid; } /** * A bit of a hack, but we use `wp_prepare_attachment_for_js()` here * since it returns all the data we need to validate the file, and we use this anyways * to validate fields updated via UI. */ $attachment = wp_prepare_attachment_for_js( $value ); $param = sprintf( '%s[%s]', $field['prefix'], $field['name'] ); $data = array( 'param' => $param, 'value' => (int) $value, ); if ( ! $attachment ) { $error = sprintf( __( '%s requires a valid attachment ID.', 'acf' ), $param ); return new WP_Error( 'rest_invalid_param', $error, $data ); } $errors = acf_validate_attachment( $attachment, $field, 'prepare' ); if ( ! empty( $errors ) ) { $error = $param . ' - ' . implode( ' ', $errors ); return new WP_Error( 'rest_invalid_param', $error, $data ); } return $valid; }