Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions includes/fields/class-acf-field-icon_picker.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,13 @@ class="acf-icon-picker-media-library-preview"
>
<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' );
// If the type is media_library, then we need to show the media library preview.
$img_url = '';

// Only fetch attachment image URL when the field type is media_library and the ID is valid.
if ( 'media_library' === $field['value']['type'] && ! empty( $field['value']['value'] ) && is_numeric( $field['value']['value'] ) ) {
$attachment_url = wp_get_attachment_image_url( (int) $field['value']['value'], 'thumbnail' );
$img_url = $attachment_url ? $attachment_url : '';
}
?>
<img src="<?php echo esc_url( $img_url ); ?>" alt="<?php esc_attr_e( 'The currently selected image preview', 'acf' ); ?>" />
</div>
Expand Down