You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

<?php
/**
* Class AMP_WordPress_TV_Embed_Handler
*
* @package AMP
* @since 1.4
*/
/**
* Class AMP_WordPress_TV_Embed_Handler
*
* @since 1.4
*/
class AMP_WordPress_TV_Embed_Handler extends AMP_Base_Embed_Handler {
/**
* Register embed.
*/
public function register_embed() {
add_filter( 'render_block', [ $this, 'filter_rendered_block' ], 10, 2 );
}
/**
* Unregister embed.
*/
public function unregister_embed() {
remove_filter( 'render_block', [ $this, 'filter_rendered_block' ], 10 );
}
/**
* Filters the content of a single block to make it AMP valid.
*
* @param string $block_content The block content about to be appended.
* @param array $block The full block, including name and attributes.
* @return string Filtered block content.
*/
public function filter_rendered_block( $block_content, $block ) {
if ( ! isset( $block['blockName'] ) || 'core-embed/wordpress-tv' !== $block['blockName'] ) {
return $block_content;
}
$modified_block_content = preg_replace( '#<script(?:\s.*?)?>.*?</script>#s', '', $block_content );
return null !== $modified_block_content ? $modified_block_content : $block_content;
}
}