Unsupported ACF column creates notice
Dear AdminColumns employee,
When we are creating a column for an unsupported ACF field, for example a Google Map field, the following PHP notice occurs:
Notice: Array to string conversion in /path/to/wordpress/wp-content/plugins/admin-columns-pro/addons/acf/classes/Column/Unsupported.php on line 12
.
This happens because in /path/to/wordpress/wp-content/plugins/admin-columns-pro/addons/acf/classes/Column/Unsupported.php
, line 12
, the result of the get_field()
function is casted to a string. However, in this case,get_field()
returns an array. And this is a problem, because that cannot be casted to a string.
The best would to use something like this for returning the value as a string:
public function get_value( $id ) {
$value = get_field( $this->get_meta_key(), $id );
$value = is_scalar( $value ) ? (string) $value : wp_json_encode( $value );
}
This would then convert the value to json.
There are also other options for removing the notice, by falling back to an empty string ''
, serialize()
the array, or using var_export()
.
We see this warning continuously, as we are attempting to add support for the ACF Google Maps field in our theme using the ac/column/value
filter, but that does not bypass getting the field value, and thus creating this notice.
I hope I’ve been able to help to resolve this bug in a future version. If there are questions, please feel free to send a reply.
Thank you in advance and kind regards,
Menno van den Ende
Level Level
You must be logged in to reply to this topic.