Skip to content

Commit 7a5937a

Browse files
fix: prevent duplicate downloads of fallback images
1 parent f6c89d5 commit 7a5937a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

includes/admin/feedzy-rss-feeds-import.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,7 @@ function ( $attr, $key ) {
17421742
$image_source_url = '';
17431743
$img_success = true;
17441744
$new_post_id = 0;
1745+
$img_title = $item['item_title'];
17451746
$feed_img_tag = ! empty( $import_featured_img ) && is_string( $import_featured_img ) ? $import_featured_img : '';
17461747

17471748
// image tag
@@ -1765,10 +1766,11 @@ function ( $attr, $key ) {
17651766
}
17661767
} else {
17671768
$image_source_url = $feed_img_tag;
1769+
$img_title = pathinfo( basename( $image_source_url ), PATHINFO_FILENAME );
17681770
}
17691771

17701772
if ( ! empty( $image_source_url ) ) {
1771-
$img_success = $this->try_save_featured_image( $image_source_url, 0, $item['item_title'], $import_errors, $import_info, $new_post );
1773+
$img_success = $this->try_save_featured_image( $image_source_url, 0, $img_title, $import_errors, $import_info, $new_post );
17721774
$new_post_id = $img_success;
17731775
}
17741776

@@ -1850,8 +1852,9 @@ function( $term ) {
18501852
do_action( 'feedzy_import_extra', $job, $item_obj, $new_post_id, $import_errors, $import_info );
18511853

18521854
if ( ! empty( $import_featured_img ) && 'attachment' !== $import_post_type ) {
1853-
$image_source_url = '';
1854-
$img_success = true;
1855+
$image_source_url = '';
1856+
$img_success = true;
1857+
$img_title = $item['item_title'];
18551858

18561859
$feed_img_tag = false === strpos( $import_featured_img, '[[{"value":' ) ? $import_featured_img : '[#item_image]'; // Use feed default image when we are using chained actions.
18571860

@@ -1874,6 +1877,7 @@ function( $term ) {
18741877
}
18751878
} elseif ( wp_http_validate_url( $import_featured_img ) ) {
18761879
$image_source_url = $import_featured_img;
1880+
$img_title = pathinfo( basename( $image_source_url ), PATHINFO_FILENAME );
18771881
}
18781882

18791883
// Fetch image from graby.
@@ -1920,7 +1924,7 @@ function( $term ) {
19201924
}
19211925
}
19221926

1923-
if ( 'yes' === $import_item_img_url || ! $this->tryReuseExistingFeaturedImage( $img_success, $item['item_title'], $new_post_id ) ) {
1927+
if ( 'yes' === $import_item_img_url || ! $this->tryReuseExistingFeaturedImage( $img_success, $img_title, $new_post_id ) ) {
19241928
// Run chained actions.
19251929
$import_featured_img = rawurldecode( $import_featured_img );
19261930
$import_featured_img = trim( $import_featured_img );
@@ -1934,7 +1938,7 @@ function( $term ) {
19341938
update_post_meta( $new_post_id, 'feedzy_item_external_url', $image_source_url );
19351939
} else {
19361940
// if import_featured_img is a tag.
1937-
$img_success = $this->try_save_featured_image( $image_source_url, $new_post_id, $item['item_title'], $import_errors, $import_info );
1941+
$img_success = $this->try_save_featured_image( $image_source_url, $new_post_id, $img_title, $import_errors, $import_info );
19381942
}
19391943
}
19401944
}

0 commit comments

Comments
 (0)