Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #831 from rebeccahum/fix/get_cover_media
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryJones authored Sep 23, 2022
2 parents 4e1e59c + 247073b commit 62af72a
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions class-instant-articles-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,28 +505,22 @@ public function get_cover_media() {

$cover_media = Image::create();


// If someone else is handling this, let them. Otherwise fall back to us trying to use the featured image.
if ( has_filter( 'instant_articles_cover_media' ) ) {
/**
* Filter the cover media.
*
* @since 0.1
* @param Image $cover_media The cover media object.
* @param int $post_id The current post ID.
*/
$cover_media = apply_filters( 'instant_articles_cover_media', $cover_media, $this->_post->ID );
} else {

$featured_image_data = $this->get_the_featured_image();
if ( isset( $featured_image_data['src'] ) && strlen( $featured_image_data['src'] ) ) {
$cover_media = Image::create()->withURL($featured_image_data['src']);
if( isset( $featured_image_data['caption'] ) && strlen( $featured_image_data['caption'] )) {
$cover_media->withCaption(Caption::create()->withTitle($featured_image_data['caption']));
}
$featured_image_data = $this->get_the_featured_image();
if ( isset( $featured_image_data['src'] ) && strlen( $featured_image_data['src'] ) ) {
$cover_media = Image::create()->withURL($featured_image_data['src']);
if( isset( $featured_image_data['caption'] ) && strlen( $featured_image_data['caption'] )) {
$cover_media->withCaption(Caption::create()->withTitle($featured_image_data['caption']));
}
}

/**
* Filter the cover media
*
* @since 0.1
* @param Image $cover_media The cover media object.
* @param int $post_id The current post ID.
*/
$cover_media = apply_filters( 'instant_articles_cover_media', $cover_media, $this->_post->ID );
return $cover_media;
}

Expand Down

0 comments on commit 62af72a

Please sign in to comment.