Astra_Gutenberg::add_iframe_wrapper( string $block_content, array $block )

Add iframe wrapper for videos.


Description


Parameters

$block_content

(string) (Required) Rendered block content.

$block

(array) (Required) Block object.


Return

(string) Filtered block content.


Source

File: inc/compatibility/class-astra-gutenberg.php

	public function add_iframe_wrapper( $block_content, $block ) {
		$yt_wrapper_with_inner_iframe_regex = '/(ast-oembed-container)/';

		if ( isset( $block['blockName'] ) && 'core/embed' !== $block['blockName'] && 'core/youtube' !== $block['blockName'] ) {
			return $block_content;
		}

		/** @psalm-suppress PossiblyUndefinedStringArrayOffset */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
		if ( ( ! empty( $block['blockName'] ) && ( 'core/embed' === $block['blockName'] || 'core/youtube' === $block['blockName'] ) ) && ! empty( $block['attrs'] ) && empty( $block['attrs']['url'] ) ) {
			return $block_content;
		}

		if ( 1 === preg_match( $yt_wrapper_with_inner_iframe_regex, $block_content ) ) {
			return $block_content;
		}

		$video_url     = ! empty( $block['attrs']['url'] ) ? esc_url( $block['attrs']['url'] ) : '';
		$replace_regex = '/<div\s+class="wp-block-embed__wrapper">(.*?)<\/div>/s';

		$updated_content = preg_replace_callback(
			$replace_regex,
			/**
			 * Add iframe wrapper for videos.
			 *
			 * @param  array $matches Matches.
			 * @return mixed          Updated content.
			 */
			function ( $matches ) use ( $video_url, $block_content, $block ) {
				return Astra_After_Setup_Theme::get_instance()->responsive_oembed_wrapper( '', $video_url, array(), true );
			},
			$block_content
		);

		return $updated_content;
	}

Changelog

Changelog
Version Description
4.4.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.