template_part_embed() method.
*
* See wordpress/wp-includes/theme-compat/embed-content.php.
*/
$embed_class = esc_attr( implode( ' ', get_post_class( 'wpsso-embed wp-embed' ) ) );
$thumbnail_url = apply_filters( 'embed_thumbnail_url', '' );
$thumbnail_id = 0;
$thumbnail_shape = 'rectangular';
$thumbnail_img = '';
$permalink = get_permalink();
if ( $thumbnail_url ) {
$thumbnail_shape = apply_filters( 'embed_thumbnail_url_image_shape', $thumbnail_shape, $thumbnail_url );
} else {
if ( has_post_thumbnail() ) {
$thumbnail_id = get_post_thumbnail_id();
}
if ( 'attachment' === get_post_type() && wp_attachment_is( 'image' ) ) {
$thumbnail_id = get_the_ID();
}
/*
* Filters the thumbnail image ID for use in the embed template.
*
* @since 4.9.0
*
* @param int $thumbnail_id Attachment ID.
*/
$thumbnail_id = apply_filters( 'embed_thumbnail_id', $thumbnail_id );
if ( $thumbnail_id ) {
$aspect_ratio = 1;
$measurements = array( 1, 1 );
$image_size = 'full'; // Fallback.
$img_meta = wp_get_attachment_metadata( $thumbnail_id ); // Returns a WP_Error object on failure.
if ( is_array( $img_meta ) ) {
if ( ! empty( $img_meta[ 'sizes' ] ) ) {
foreach ( $img_meta[ 'sizes' ] as $size => $data ) {
if ( $data[ 'height' ] > 0 && $data[ 'width' ] / $data[ 'height' ] > $aspect_ratio ) {
$aspect_ratio = $data[ 'width' ] / $data[ 'height' ];
$measurements = array( $data[ 'width' ], $data[ 'height' ] );
$image_size = $size;
}
}
}
}
/*
* Filters the thumbnail image size for use in the embed template.
*
* @since 4.4.0
* @since 4.5.0 Added `$thumbnail_id` parameter.
*
* @param string $image_size Thumbnail image size.
* @param int $thumbnail_id Attachment ID.
*/
$image_size = apply_filters( 'embed_thumbnail_image_size', $image_size, $thumbnail_id );
$thumbnail_shape = $measurements[ 0 ] / $measurements[ 1 ] >= 1.75 ? 'rectangular' : 'square';
/*
* Filters the thumbnail shape for use in the embed template.
*
* Rectangular images are shown above the title while square images
* are shown next to the content.
*
* @since 4.4.0
* @since 4.5.0 Added `$thumbnail_id` parameter.
*
* @param string $thumbnail_shape Thumbnail image shape. Either 'rectangular' or 'square'.
* @param int $thumbnail_id Attachment ID.
*/
$thumbnail_shape = apply_filters( 'embed_thumbnail_image_shape', $thumbnail_shape, $thumbnail_id );
}
}
if ( $thumbnail_url ) {
$loading = wp_lazy_loading_enabled( 'img', 'wp_get_attachment_image' ) ? 'loading="lazy"' : '';
$thumbnail_img = '' ;
} elseif ( $thumbnail_id ) {
$thumbnail_img = wp_get_attachment_image( $thumbnail_id, $image_size );
}
echo '