HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/gutenmate/lib/photoswipe/photoswipe.php
<?php

add_action( 'init', 'gtm_register_asset_photoswipe' );
function gtm_register_asset_photoswipe() {
	wp_enqueue_script( 'gutenmate-photoswipe', GTM_LIB_URL . 'photoswipe/dist/gutenmate-photoswipe.js', [], GTM_VERSION, true );
	wp_enqueue_style( 'gutenmate-photoswipe', GTM_LIB_URL . 'photoswipe/dist/gutenmate-photoswipe.css', [], GTM_VERSION );
	wp_style_add_data( 'gutenmate-photoswipe', 'rtl', 'replace' );

	wp_localize_script( 'gutenmate-photoswipe', 'gtm_photoswipe_options', apply_filters( 'gtm_photoswipe_options', [] ) );
}

/**
 * Apply required html for running photoswipe
 */
add_filter( 'render_block', 'gtm_apply_photoswipe_html', 10, 2 );
function gtm_apply_photoswipe_html( $block_content, $block ) {
	if ( $block['blockName'] === 'gtm/post-featured-image' ) {
		$post_thumbnail_id = get_post_thumbnail_id();

		if ( ! empty( $post_thumbnail_id ) ) {
			$attachment = wp_get_attachment_image_src( $post_thumbnail_id, 'full' );

			if ( $attachment ) {
				$width  = $attachment[1];
				$height = $attachment[2];

				$block_content = str_replace( '<a ', sprintf( '<a data-pswp-width="%s" data-pswp-height="%s" ', esc_attr( $width ), esc_attr( $height ) ), $block_content );
			}
		}

	} else if ( $block['blockName'] === 'core/image' ) {
		if ( ! empty( $block['attrs']['id'] ) ) {
			$attachment = wp_get_attachment_image_src( $block['attrs']['id'], 'full' );

			if ( $attachment ) {
				$width  = $attachment[1];
				$height = $attachment[2];

				$block_content = str_replace( '<a ', sprintf( '<a data-pswp-width="%s" data-pswp-height="%s" ', esc_attr( $width ), esc_attr( $height ) ), $block_content );
			}
		}

	} else if ( $block['blockName'] === 'core/media-text' ) {
		if ( ! empty( $block['attrs']['mediaId'] ) ) {
			$attachment = wp_get_attachment_image_src( $block['attrs']['mediaId'], 'full' );

			if ( $attachment ) {
				$width  = $attachment[1];
				$height = $attachment[2];

				$block_content = str_replace( 'wp-block-media-text__media"><a ', sprintf( 'wp-block-media-text__media"><a data-pswp-width="%s" data-pswp-height="%s" ', esc_attr( $width ), esc_attr( $height ) ), $block_content );
			}
		}
	}

	return $block_content;
}