Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#1,032 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
86/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php, wordpress
領域
backend

調査の方向性

includes/fields/class-acf-field-icon_picker.php の media_library タブのループ付近から始め、プレビュー URL がどのように構築されているかを確認します。Dashicon の値と、報告されているフィルターフックを使用するプラグインを使って、wp-admin/post-new.php?post_type=acf-post-type から再現します。Dashicon の値で PHP 8+ の TypeError が発生しなくなり、media-library のプレビューが引き続き機能すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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>
主要言語
PHP
スター
946
フォーク
197
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

AdvancedCustomFields/acf のほかの issue

AdvancedCustomFields/acf の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。