Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Related posts block: add srcset to thumbnails
3 changes: 1 addition & 2 deletions projects/plugins/jetpack/class.jetpack-post-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,9 @@ public static function generate_cropped_srcset( $image, $base_width, $base_heigh
return $srcset;
}

$multipliers = array( 1, 2, 3, 4 );
$multipliers = array( 1, 1.5, 2, 3, 4 );
$srcset_values = array();
foreach ( $multipliers as $multiplier ) {
// Forcefully cast to int, in case we ever add decimal multipliers.
$srcset_width = (int) ( $base_width * $multiplier );
$srcset_height = (int) ( $base_height * $multiplier );
if ( $srcset_width < 1 || $srcset_width > $image['src_width'] ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function get_client_rendered_html_unsupported() {
/**
* Echoes out items for the Gutenberg block
*
* @param array $related_post The post oject.
* @param array $related_post The post object.
* @param array $block_attributes The block attributes.
*/
public function render_block_item( $related_post, $block_attributes ) {
Expand All @@ -382,13 +382,14 @@ public function render_block_item( $related_post, $block_attributes ) {

if ( ! empty( $block_attributes['show_thumbnails'] ) && ! empty( $related_post['img']['src'] ) ) {
$img_link = sprintf(
'<li class="jp-related-posts-i2__post-img-link"><a href="%1$s" %2$s><img src="%3$s" width="%4$s" height="%5$s" alt="%6$s" loading="lazy" /></a></li>',
'<li class="jp-related-posts-i2__post-img-link"><a href="%1$s" %2$s><img loading="lazy" src="%3$s" width="%4$s" height="%5$s" alt="%6$s" %7$s/></a></li>',
esc_url( $related_post['url'] ),
( ! empty( $related_post['rel'] ) ? 'rel="' . esc_attr( $related_post['rel'] ) . '"' : '' ),
esc_url( $related_post['img']['src'] ),
esc_attr( $related_post['img']['width'] ),
esc_attr( $related_post['img']['height'] ),
esc_attr( $related_post['img']['alt_text'] )
esc_attr( $related_post['img']['alt_text'] ),
( ! empty( $related_post['img']['srcset'] ) ? 'srcset="' . esc_attr( $related_post['img']['srcset'] ) . '"' : '' )
);

$item_markup .= $img_link;
Expand Down