acf_validate_is_image_attachment_prepare()
Validates image attachment data when preparing for the media library.
Хуков нет.
Возвращает
array.
Использование
acf_validate_is_image_attachment_prepare( $errors, $file, $attachment, $field, $context, $error_message );
- $errors(массив) (обязательный)
- Validation errors.
- $file(массив) (обязательный)
- Normalized file data.
- $attachment(массив) (обязательный)
- Raw attachment data for the current context.
- $field(массив) (обязательный)
- The field array.
- $context(строка) (обязательный)
- The validation context.
- $error_message(строка) (обязательный)
- The error message to use when validation fails.
Список изменений
| С версии 6.8.7 | Введена. |
Код acf_validate_is_image_attachment_prepare() acf validate is image attachment prepare ACF 6.8.8
function acf_validate_is_image_attachment_prepare( $errors, $file, $attachment, $field, $context, $error_message ) {
$attachment_id = (int) acf_maybe_get( $attachment, 'id', 0 );
if ( $attachment_id ) {
if ( ! wp_attachment_is_image( $attachment_id ) ) {
$errors['invalid_image'] = $error_message;
}
return acf_apply_validate_is_image_attachment_filters( $errors, $file, $attachment, $field, $context );
}
$mime = acf_maybe_get( $attachment, 'mime', acf_maybe_get( $attachment, 'type', '' ) );
if ( $mime && empty( wp_match_mime_types( 'image', $mime ) ) ) {
$errors['invalid_image'] = $error_message;
}
return acf_apply_validate_is_image_attachment_filters( $errors, $file, $attachment, $field, $context );
}