Title:
Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+
ACF Version: 6.3.x / 6.4.x (and latest)
WordPress Version: 6.7+ / 7.x
PHP Version: 8.2 / 8.3 / 8.4
Description
In includes/fields/class-acf-field-icon_picker.php, when rendering the tabs for the Icon Picker field (used on post types, taxonomies, and custom fields), ACF executes wp_get_attachment_image_url() unconditionally inside the media_library tab loop, even when the field's active value is a Dashicon string (such as 'dashicons-admin-post').
Because $field['value']['value'] is a string and not an attachment ID, WordPress passes this string through wp_get_attachment_image_src. Any plugin hooking into this filter with strict type hints (such as WP Offload Media 3.4+) immediately crashes with an Uncaught TypeError: Argument must be of type int, string given.
Steps to Reproduce
- Run a WordPress site on PHP 8.2+ with ACF and any plugin that hooks into
wp_get_attachment_image_src expecting an integer (e.g., WP Offload Media 3.4+).
- Navigate to
wp-admin/post-new.php?post_type=acf-post-type (ACF > Post Types > Add New).
- The page fails with a 500 Fatal Error (
TypeError).
Root Cause
In includes/fields/class-acf-field-icon_picker.php (around lines 215–220):
<div class="acf-icon-picker-media-library-preview-img" style="<?php echo esc_attr( 'media_library' !== $field['value']['type'] ? 'display: none;' : '' ); ?>">
<?php
$img_url = wp_get_attachment_image_url( $field['value']['value'], 'thumbnail' );
?>
<img src="<?php echo esc_url( $img_url ); ?>" alt="<?php esc_attr_e( 'The currently selected image preview', 'acf' ); ?>" />
</div>
The template attempts to hide the preview using CSS (display: none;), but PHP still evaluates wp_get_attachment_image_url( 'dashicons-admin-post', 'thumbnail' ).
Suggested Fix
Wrap the call so wp_get_attachment_image_url() is only invoked if the field type is actually media_library and the value is numeric:
<div class="acf-icon-picker-media-library-preview-img" style="<?php echo esc_attr( 'media_library' !== $field['value']['type'] ? 'display: none;' : '' ); ?>">
<?php
$img_url = '';
if ( 'media_library' === $field['value']['type'] && is_numeric( $field['value']['value'] ) ) {
$img_url = wp_get_attachment_image_url( (int) $field['value']['value'], 'thumbnail' );
}
?>
<img src="<?php echo esc_url( $img_url ); ?>" alt="<?php esc_attr_e( 'The currently selected image preview', 'acf' ); ?>" />
</div>
Title:
Bug:
class-acf-field-icon_picker.phpcallswp_get_attachment_image_url()with string Dashicon slug, causing fatal TypeError on PHP 8+ACF Version: 6.3.x / 6.4.x (and latest)
WordPress Version: 6.7+ / 7.x
PHP Version: 8.2 / 8.3 / 8.4
Description
In
includes/fields/class-acf-field-icon_picker.php, when rendering the tabs for the Icon Picker field (used on post types, taxonomies, and custom fields), ACF executeswp_get_attachment_image_url()unconditionally inside themedia_librarytab loop, even when the field's active value is a Dashicon string (such as'dashicons-admin-post').Because
$field['value']['value']is a string and not an attachment ID, WordPress passes this string throughwp_get_attachment_image_src. Any plugin hooking into this filter with strict type hints (such as WP Offload Media 3.4+) immediately crashes with anUncaught TypeError: Argument must be of type int, string given.Steps to Reproduce
wp_get_attachment_image_srcexpecting an integer (e.g., WP Offload Media 3.4+).wp-admin/post-new.php?post_type=acf-post-type(ACF > Post Types > Add New).TypeError).Root Cause
In
includes/fields/class-acf-field-icon_picker.php(around lines 215–220):The template attempts to hide the preview using CSS (
display: none;), but PHP still evaluateswp_get_attachment_image_url( 'dashicons-admin-post', 'thumbnail' ).Suggested Fix
Wrap the call so
wp_get_attachment_image_url()is only invoked if the field type is actuallymedia_libraryand the value is numeric: