acf_field_icon_picker::format_value
This filter is appied to the $value after it is loaded from the db and before it is returned to the template
Method of the class: acf_field_icon_picker{}
No Hooks.
Returns
Mixed. $value The modified value.
Usage
$acf_field_icon_picker = new acf_field_icon_picker(); $acf_field_icon_picker->format_value( $value, $post_id, $field );
- $value(mixed) (required)
- The value which was loaded from the database.
- $post_id(int) (required)
- The
$post_idfrom which the value was loaded. - $field(array) (required)
- The field array holding all the field options.
Changelog
| Since 6.3 | Introduced. |
acf_field_icon_picker::format_value() acf field icon picker::format value code ACF 6.8.8
public function format_value( $value, $post_id, $field ) {
// Handle empty values.
if ( empty( $value ) ) {
// Return the default value if there is one.
if ( isset( $field['default_value'] ) ) {
return $field['default_value'];
} else {
// Otherwise return false.
return false;
}
}
// If media_library, behave the same as an image field.
if ( $value['type'] === 'media_library' ) {
// convert to int
$value['value'] = intval( $value['value'] );
// format
if ( $field['return_format'] === 'string' ) {
return wp_get_attachment_url( $value['value'] );
} elseif ( $field['return_format'] === 'array' ) {
$value['value'] = acf_get_attachment( $value['value'] );
return $value;
}
}
// If the desired return format is a string
if ( $field['return_format'] === 'string' ) {
return $value['value'];
}
// If nothing specific matched the return format, just return the value.
return $value;
}