AdvancedCustomFields / AdvancedCustomFields/acf

Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+

Open Beginner friendly
#1,032 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

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
  1. 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+).
  2. Navigate to wp-admin/post-new.php?post_type=acf-post-type (ACF > Post Types > Add New).
  3. 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>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in includes/fields/class-acf-field-icon_picker.php around the media_library tab loop and inspect how the preview URL is built. Reproduce through wp-admin/post-new.php?post_type=acf-post-type with a Dashicon value and the reported filter-hooking plugin. Done means Dashicon values no longer trigger the PHP 8+ TypeError while media-library previews still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.