__( 'Slide to compare images', 'jetpack' ),
)
);
if ( Blocks::is_amp_request() ) {
$content = preg_replace(
'#
#s',
render_amp( $attr ),
$content
);
}
return $content;
}
/**
* Render image compare block for AMP
*
* @param array $attr Array containing the image-compare block attributes.
*
* @return string Markup for amp-image-slider.
*/
function render_amp( $attr ) {
$img_before = $attr['imageBefore'];
$img_after = $attr['imageAfter'];
$width = ! empty( $img_before['width'] ) ? absint( $img_before['width'] ) : 0;
$height = ! empty( $img_before['height'] ) ? absint( $img_before['height'] ) : 0;
// As fallback, give 1:1 aspect ratio.
if ( ! $width || ! $height ) {
$width = 1;
$height = 1;
}
return sprintf(
'
',
esc_attr( $width ),
esc_attr( $height ),
absint( $img_before['id'] ?? 0 ),
esc_url( $img_before['url'] ?? '' ),
esc_attr( $img_before['alt'] ?? '' ),
absint( $img_after['id'] ?? 0 ),
esc_url( $img_after['url'] ?? '' ),
esc_attr( $img_after['alt'] ?? '' )
);
}