acf_field_icon_picker::validate_rest_value
Validates a value sent via the REST API.
Method of the class: acf_field_icon_picker{}
No Hooks.
Returns
true|false|WP_Error.
Usage
$acf_field_icon_picker = new acf_field_icon_picker(); $acf_field_icon_picker->validate_rest_value( $valid, $value, $field );
- $valid(true|false) (required)
- The current validity boolean.
- $value(array|null) (required)
- The value of the field.
- $field(array) (required)
- The main field array.
Changelog
| Since 6.3 | Introduced. |
acf_field_icon_picker::validate_rest_value() acf field icon picker::validate rest value code ACF 6.8.8
public function validate_rest_value( $valid, $value, $field ) {
if ( is_null( $value ) ) {
if ( ! empty( $field['required'] ) ) {
return new WP_Error(
'rest_property_required',
/* translators: %s - field name */
sprintf( __( '%s is a required property of acf.', 'acf' ), $field['name'] )
);
} else {
return $valid;
}
}
if ( ! empty( $value['type'] ) && 'media_library' === $value['type'] ) {
$param = sprintf( '%s[%s][value]', $field['prefix'], $field['name'] );
$data = array(
'param' => $param,
'value' => (int) $value['value'],
);
if ( ! is_int( $value['value'] ) || 'attachment' !== get_post_type( $value['value'] ) ) {
/* translators: %s - field/param name */
$error = sprintf( __( '%s requires a valid attachment ID when type is set to media_library.', 'acf' ), $param );
return new WP_Error( 'rest_invalid_param', $error, $data );
}
}
return $valid;
}