Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 86/100
調査の方向性
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
- Run a WordPress site on PHP 8.2+ with ACF and any plugin that hooks into
wp_get_attachment_image_srcexpecting 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>
- 主要言語
- PHP
- スター
- 946
- フォーク
- 197
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
AdvancedCustomFields/acf のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1041 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
AdvancedCustomFields/acf#1038 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1034 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1029 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
AdvancedCustomFields/acf#1028 · コメント 1 件 ·
AdvancedCustomFields/acf の issue をすべて見る
似ている issue
-
[Sync EN] Fix session read handler docs: false reports a failure, not a missing session (#5902)オープンsync-en
難易度 2/5 1〜2日 初心者へのやさしさ 84/100
メンテナーはふだん 2 日以内に返信
-
feature-request needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
aws/aws-sdk-php#3365 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 90/100
-
bug status: unverified
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
woocommerce/google-listings-and-ads#3884 ·
メンテナーはふだん 1 日以内に返信