ACF image compatibility issue
-
Hello,
I recently updated canto to version 3.1.1 which caused an issue with Advanced Custom Fields.
If I create an ACF image field and set it to return an ID, an image array is returned if canto 3.1.1 is installed, where it should just be the ID. this works fine in 3.1.0
The issue comes from this file:wp-content/plugins/canto/includes/lib/class-canto-acf-integration.phpThe hook on line 42 is the cause of the issue.
add_filter('acf/format_value/type=image', array($this, 'format_image_value'), 20, 3);the format_image_value function contains this section which doesn’t make sense, the $cached_data is clearly an array when an image should be returned. I assume it should return something like $cached_data[‘ID’]
$cached_data = get_post_meta($value, '_acf_image_data', true);
if ($cached_data && isset($cached_data['url'])) {
return $cached_data;
}public function format_image_value($value, $post_id, $field) { if (empty($value)) { return $value; } // If we already have a properly formatted array with url, just return it if (is_array($value) && isset($value['url'])) { return $value; } // If we have an attachment ID, get the proper image data if (is_numeric($value)) { // Try to get cached data first $cached_data = get_post_meta($value, '_acf_image_data', true); if ($cached_data && isset($cached_data['url'])) { return $cached_data; } // If no cached data, format it now return $this->format_asset_for_acf($value, 'image'); } return $value; }Steps to reproduce:
Install advanced-custom-fields and canto on a clean WordPress installAdd a new image field called test_image and set the Return Format to Image ID and set the location rules to show on pages.
add var_dump(get_field(‘test_image’, $post->ID)); to a template file (or just anywhere really)
The var dump should be an image ID, instead it is an array
You must be logged in to reply to this topic.