acf_field_file::format_valuepublicACF 3.6

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_file{}

No Hooks.

Returns

$value. (mixed) the modified value

Usage

$acf_field_file = new acf_field_file();
$acf_field_file->format_value( $value, $post_id, $field );
$value(required)
.
$post_id(required)
.
$field(required)
.

Changelog

Since 3.6 Introduced.

acf_field_file::format_value() code ACF 6.0.4

function format_value( $value, $post_id, $field ) {

	// bail early if no value
	if ( empty( $value ) ) {
		return false;
	}

	// bail early if not numeric (error message)
	if ( ! is_numeric( $value ) ) {
		return false;
	}

	// convert to int
	$value = intval( $value );

	// format
	if ( $field['return_format'] == 'url' ) {

		return wp_get_attachment_url( $value );

	} elseif ( $field['return_format'] == 'array' ) {

		return acf_get_attachment( $value );
	}

	// return
	return $value;
}