Ensure Icon Picker only calls wp_get_attachment_image_url with valid attachment IDs - #1033
Open
antwonw wants to merge 1 commit into
Open
Conversation
…attachment IDs (Fixes AdvancedCustomFields#1032)
Member
|
@antwonw Thanks for the detailed report and PR! We'll look into getting this into a future release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Fixes #1032
In
includes/fields/class-acf-field-icon_picker.php, the template for themedia_librarytab unconditionally executeswp_get_attachment_image_url( $field['value']['value'], 'thumbnail' ).When creating a new custom post type (
post_type=acf-post-type) or editing any post type/taxonomy where a Dashicon or URL icon is selected,$field['value']['value']is a string (e.g.'dashicons-admin-post').While the template hides the image preview container via CSS (
display: none;), PHP still evaluates the function call and passes the string to WordPress core'swp_get_attachment_image_src(). Any active plugin or integration hooking intowp_get_attachment_image_srcthat enforces strict typing (such as WP Offload Media 3.4+) immediately crashes with a fatalTypeError:Proposed Solution
Harden the media library preview block in
class-acf-field-icon_picker.phpto verify that:'media_library'.is_numeric()).Only then invoke
wp_get_attachment_image_url()with the integer-cast ID(int) $field['value']['value']. If these conditions are not met,$img_urlsafely defaults to an empty string''.Steps to Test
wp_get_attachment_image_srcexpecting an integer ID (e.g. WP Offload Media 3.4+).wp-admin/post-new.php?post_type=acf-post-type(ACF > Post Types > Add New).TypeError.Test Verification & Output
1. PHP Syntax Check (
php -l)2. WordPress Coding Standards Check (
phpcs)Executed with
--standard=WordPressacross the file:3. Automated Scenario Unit Tests (PHP 8.5 Strict Types)
Ran automated test harness covering all field value states:
Diff