Skip to content

Commit af2d1e5

Browse files
committed
feat: improve external featured image handling
1 parent 72921d8 commit af2d1e5

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

includes/feedzy-rss-feeds-feed-tweaks.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function feedzy_el_display_external_post_image( $html, $settings, $image_size_ke
161161
* @param int|false $thumbnail_id Post thumbnail ID or false if the post does not exist.
162162
* @return bool
163163
*/
164-
function enable_external_url_support( $has_thumbnail, $post, $thumbnail_id ) {
164+
function feedzy_enable_external_url_support( $has_thumbnail, $post, $thumbnail_id ) {
165165
$post_id = get_the_ID();
166166
if ( $post && is_object( $post ) ) {
167167
$post_id = $post->ID;
@@ -175,7 +175,28 @@ function enable_external_url_support( $has_thumbnail, $post, $thumbnail_id ) {
175175
}
176176
return $has_thumbnail;
177177
}
178-
add_filter( 'has_post_thumbnail', 'enable_external_url_support', 10, 3 );
178+
add_filter( 'has_post_thumbnail', 'feedzy_enable_external_url_support', 10, 3 );
179+
180+
/**
181+
* Filters the attachment image source.
182+
*
183+
* @param array|false $image Either array with src, width & height, icon src, or false.
184+
* @param int $attachment_id Image attachment ID.
185+
* @param string|int[] $size Size of image. Image size or array of width and height values (in that order).
186+
* @param bool $icon Whether the image should be treated as an icon.
187+
* @return array|false
188+
*/
189+
function feedzy_get_attachment_image_src( $image, $attachment_id, $size, $icon ) {
190+
if ( 0 === $attachment_id ) {
191+
$external_url = get_post_meta( get_the_ID(), 'feedzy_item_external_url', true );
192+
if ( $external_url ) {
193+
$image = array( $external_url, 0, 0, false );
194+
}
195+
}
196+
return $image;
197+
}
198+
199+
add_filter( 'wp_get_attachment_image_src', 'feedzy_get_attachment_image_src', 10, 4 );
179200

180201
/**
181202
* Boostrap the plugin view.

0 commit comments

Comments
 (0)