acf_format_value()
Returns a formatted version of the provided value.
Hooks from the function
Returns
Mixed.
Usage
acf_format_value( $value, $post_id, $field, $escape_html );
- $value(mixed) (required)
- The field value.
- $post_id(int|string) (required)
- The post id.
- $field(array) (required)
- The field array.
- $escape_html(true|false)
- Ask the field for a HTML safe version of it's output.
Default:false
Changelog
| Since 5.0.0 | Introduced. |
acf_format_value() acf format value code ACF 6.8.8
function acf_format_value( $value, $post_id, $field, $escape_html = false ) {
// Allow filter to short-circuit load_value logic.
$check = apply_filters( 'acf/pre_format_value', null, $value, $post_id, $field, $escape_html );
if ( $check !== null ) {
return $check;
}
// Get field name.
$field_name = $field['name'];
$cache_name = $escape_html ? "$post_id:$field_name:escaped" : "$post_id:$field_name:formatted";
// Check store.
$store = acf_get_store( 'values' );
if ( $store->has( $cache_name ) ) {
return $store->get( $cache_name );
}
/**
* Filters the $value for use in a template function.
*
* @since 5.0.0
*
* @param mixed $value The value to preview.
* @param string $post_id The post ID for this value.
* @param array $field The field array.
* @param boolean $escape_html Ask the field for a HTML safe version of it's output.
*/
$value = apply_filters( 'acf/format_value', $value, $post_id, $field, $escape_html );
// Update store.
$store->set( $cache_name, $value );
// Return value.
return $value;
}