Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
preda-bogdan committed Mar 29, 2024
1 parent aa6ce06 commit 65e4a5b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -1978,23 +1978,23 @@ public function tryReuseExistingFeaturedImage( &$result, $title_feed, $post_id =
}

/**
* Will retireve the file type of a file by its URL.
*
* Will retireve the file type of a file by its URL.
*
* @param string $url The URL of the file.
*
* @return string
*/
private function get_file_type_by_url( $url ) {
$response = wp_remote_get( $url );
private function get_file_type_by_url( $url ) {
$response = wp_remote_get( $url );

// wp_remote_retrieve_header can return an array if there are multiple headers with the same name
$content_type = wp_remote_retrieve_header( $response, 'content-type' );
if ( is_array( $content_type ) ) {
$content_type = $content_type[0];
}
// wp_remote_retrieve_header can return an array if there are multiple headers with the same name
$content_type = wp_remote_retrieve_header( $response, 'content-type' );
if ( is_array( $content_type ) ) {
$content_type = $content_type[0];
}

return $content_type;
}
return $content_type;
}

/**
* Downloads and sets a post featured image if possible.
Expand Down Expand Up @@ -2038,10 +2038,10 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title
return false;
}

$type = $this->get_file_type_by_url( $img_source_url );
if ( empty( $type ) && function_exists( 'mime_content_type' ) ) {
$type = mime_content_type( $local_file );
}
$type = $this->get_file_type_by_url( $img_source_url );
if ( empty( $type ) && function_exists( 'mime_content_type' ) ) {
$type = mime_content_type( $local_file );
}
// the file is downloaded with a .tmp extension
// if the URL mentions the extension of the file, the upload succeeds
// but if the URL is like https://source.unsplash.com/random, then the upload fails
Expand Down

0 comments on commit 65e4a5b

Please sign in to comment.