acf_format_value()ACF 5.0.0

Returns a formatted version of the provided value.

Хуки из функции

Возвращает

Разное.

Использование

acf_format_value( $value, $post_id, $field, $escape_html );
$value(разное) (обязательный)
The field value.
$post_id(int|строка) (обязательный)
The post id.
$field(массив) (обязательный)
The field array.
$escape_html(true|false)
Ask the field for a HTML safe version of it's output.
По умолчанию: false

Список изменений

С версии 5.0.0 Введена.

Код acf_format_value() ACF 6.4.2

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;
}