acf_field_icon_picker::validate_valuepublicACF 6.3

Validates the field value before it is saved into the database.

Method of the class: acf_field_icon_picker{}

No Hooks.

Returns

true|false. true If the value is valid, false if not.

Usage

$acf_field_icon_picker = new acf_field_icon_picker();
$acf_field_icon_picker->validate_value( $valid, $value, $field, $input );
$valid(int) (required)
The current validation status.
$value(mixed) (required)
The value of the field.
$field(array) (required)
The field array holding all the field options.
$input(string) (required)
The corresponding input name for $_POST value.

Changelog

Since 6.3 Introduced.

acf_field_icon_picker::validate_value() code ACF 6.8.8

public function validate_value( $valid, $value, $field, $input ) {
	// If the value is empty and it's not required, return true. You're allowed to save nothing.
	if ( empty( $value ) && empty( $field['required'] ) ) {
		return true;
	}

	// Validate required.
	if ( $field['required'] && ( empty( $value ) || empty( $value['value'] ) ) ) {
		return false;
	}

	// If the value is not an array, return $valid status.
	if ( ! is_array( $value ) ) {
		return $valid;
	}

	// If the value is an array, but the type is not set, fail validation.
	if ( ! isset( $value['type'] ) ) {
		return __( 'Icon picker requires an icon type.', 'acf' );
	}

	// If the value is an array, but the value is not set, fail validation.
	if ( ! isset( $value['value'] ) ) {
		return __( 'Icon picker requires a value.', 'acf' );
	}

	return true;
}