acf_revisions::wp_post_revision_field
Load the value for the given field and return it for rendering.
Method of the class: acf_revisions{}
No Hooks.
Returns
string. $value
Usage
$acf_revisions = new acf_revisions(); $acf_revisions->wp_post_revision_field( $value, $field_name, $post, $direction );
- $value(mixed) (required)
- Should be false as it has not yet been loaded.
- $field_name(string) (required)
- The name of the field.
- $post(mixed)
- Holds the
$postobject to load from - in WP 3.5, this is not passed!.
Default:null - $direction(string)
- To / from - not used.
Default:false
acf_revisions::wp_post_revision_field() acf revisions::wp post revision field code ACF 6.8.8
public function wp_post_revision_field( $value, $field_name, $post = null, $direction = false ) {
// Bail early if is empty.
if ( empty( $value ) ) {
return '';
}
$value = acf_maybe_unserialize( $value );
$post_id = $post->ID;
// load field.
$field = acf_maybe_get_field( $field_name, $post_id );
// default formatting.
if ( is_array( $value ) ) {
$value = implode( ', ', $value );
} elseif ( is_object( $value ) ) {
$value = serialize( $value );
}
// image.
if ( is_array( $field ) && isset( $field['type'] ) && ( $field['type'] === 'image' || $field['type'] === 'file' ) ) {
$url = wp_get_attachment_url( $value );
$value = $value . ' (' . $url . ')';
}
return $value;
}