__NAMESPACE__ . '\load_assets' ) ); } add_action( 'init', __NAMESPACE__ . '\register_block' ); /** * Image Compare block registration/dependency declaration. * * @param array $attr Array containing the image-compare block attributes. * @param string $content String containing the image-compare block content. * * @return string */ function load_assets( $attr, $content ) { Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { return render_amp( $attr ); } return $content; } /** * Render image compare block for AMP * * @param array $attr Array containing the image-compare block attributes. * * @return string */ function render_amp( $attr ) { $img_before = $attr['imageBefore']; $img_after = $attr['imageAfter']; return sprintf( ' ', ! empty( $img_before['width'] ) ? ' width="' . absint( $img_before['width'] ) . '"' : '', ! empty( $img_before['height'] ) ? ' height="' . absint( $img_before['height'] ) . '"' : '', absint( $img_before['id'] ), esc_url( $img_before['url'] ), esc_attr( $img_before['alt'] ), absint( $img_after['id'] ), esc_url( $img_after['url'] ), esc_attr( $img_after['alt'] ) ); }