private function build_post_featured_image()
{
$post_id = $this->ID;
$featured_html = get_the_post_thumbnail($post_id, 'large');
// Skip featured image if no featured image is available.
if (!$featured_html) {
return;
}
$featured_id = get_post_thumbnail_id($post_id);
// If an image with the same ID as the featured image exists in the content, skip the featured image markup.
// Prevents duplicate images, which is especially problematic for photo blogs.
// A bit crude but it's fast and should cover most cases.
$post_content = $this->post->post_content;
if (false !== strpos($post_content, 'wp-image-' . $featured_id) || false !== strpos($post_content, 'attachment_' . $featured_id)) {
return;
}
$featured_image = get_post($featured_id);
list($sanitized_html, $featured_scripts, $featured_styles) = AMP_Content_Sanitizer::sanitize($featured_html, array('AMP_Img_Sanitizer' => array()), array('content_max_width' => $this->get('content_max_width')));
$this->add_data_by_key('featured_image', array('amp_html' => $sanitized_html, 'caption' => $featured_image->post_excerpt));
if ($featured_scripts) {
$this->merge_data_for_key('amp_component_scripts', $featured_scripts);
}
if ($featured_styles) {
$this->add_data_by_key('post_amp_styles', $featured_styles);
}
}