Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/extensio.../blocks/image-co...
File: image-compare.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Image Compare Block.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 8.6
[4] Fix | Delete
*
[5] Fix | Delete
* @package automattic/jetpack
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
namespace Automattic\Jetpack\Extensions\ImageCompare;
[9] Fix | Delete
[10] Fix | Delete
use Automattic\Jetpack\Blocks;
[11] Fix | Delete
use Jetpack_Gutenberg;
[12] Fix | Delete
[13] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[14] Fix | Delete
exit( 0 );
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Registers the block for use in Gutenberg
[19] Fix | Delete
* This is done via an action so that we can disable
[20] Fix | Delete
* registration if we need to.
[21] Fix | Delete
*/
[22] Fix | Delete
function register_block() {
[23] Fix | Delete
Blocks::jetpack_register_block(
[24] Fix | Delete
__DIR__,
[25] Fix | Delete
array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
[26] Fix | Delete
);
[27] Fix | Delete
}
[28] Fix | Delete
add_action( 'init', __NAMESPACE__ . '\register_block' );
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Image Compare block registration/dependency declaration.
[32] Fix | Delete
*
[33] Fix | Delete
* @param array $attr Array containing the image-compare block attributes.
[34] Fix | Delete
* @param string $content String containing the image-compare block content.
[35] Fix | Delete
*
[36] Fix | Delete
* @return string
[37] Fix | Delete
*/
[38] Fix | Delete
function load_assets( $attr, $content ) {
[39] Fix | Delete
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
[40] Fix | Delete
wp_localize_script(
[41] Fix | Delete
'jetpack-block-' . sanitize_title_with_dashes( Blocks::get_block_feature( __DIR__ ) ),
[42] Fix | Delete
'imageCompareHandle',
[43] Fix | Delete
array(
[44] Fix | Delete
'msg' => __( 'Slide to compare images', 'jetpack' ),
[45] Fix | Delete
)
[46] Fix | Delete
);
[47] Fix | Delete
if ( Blocks::is_amp_request() ) {
[48] Fix | Delete
$content = preg_replace(
[49] Fix | Delete
'#<div class="juxtapose".+?</div>#s',
[50] Fix | Delete
render_amp( $attr ),
[51] Fix | Delete
$content
[52] Fix | Delete
);
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
return $content;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Render image compare block for AMP
[60] Fix | Delete
*
[61] Fix | Delete
* @param array $attr Array containing the image-compare block attributes.
[62] Fix | Delete
*
[63] Fix | Delete
* @return string Markup for amp-image-slider.
[64] Fix | Delete
*/
[65] Fix | Delete
function render_amp( $attr ) {
[66] Fix | Delete
$img_before = $attr['imageBefore'];
[67] Fix | Delete
$img_after = $attr['imageAfter'];
[68] Fix | Delete
[69] Fix | Delete
$width = ! empty( $img_before['width'] ) ? absint( $img_before['width'] ) : 0;
[70] Fix | Delete
$height = ! empty( $img_before['height'] ) ? absint( $img_before['height'] ) : 0;
[71] Fix | Delete
[72] Fix | Delete
// As fallback, give 1:1 aspect ratio.
[73] Fix | Delete
if ( ! $width || ! $height ) {
[74] Fix | Delete
$width = 1;
[75] Fix | Delete
$height = 1;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
return sprintf(
[79] Fix | Delete
'<amp-image-slider layout="responsive" width="%1$s" height="%2$s"> <amp-img id="%3$d" src="%4$s" alt="%5$s" layout="fill"></amp-img> <amp-img id="%6$d" src="%7$s" alt="%8$s" layout="fill"></amp-img></amp-image-slider>',
[80] Fix | Delete
esc_attr( $width ),
[81] Fix | Delete
esc_attr( $height ),
[82] Fix | Delete
absint( $img_before['id'] ?? 0 ),
[83] Fix | Delete
esc_url( $img_before['url'] ?? '' ),
[84] Fix | Delete
esc_attr( $img_before['alt'] ?? '' ),
[85] Fix | Delete
absint( $img_after['id'] ?? 0 ),
[86] Fix | Delete
esc_url( $img_after['url'] ?? '' ),
[87] Fix | Delete
esc_attr( $img_after['alt'] ?? '' )
[88] Fix | Delete
);
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function