PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
jetpack / jetpack_vendor / automattic / jetpack-videopress / src / class-block-replacement.php

class-block-replacement.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3, at jetpack_vendor/automattic/jetpack-videopress/src/class-block-replacement.php

57 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Media block replacement class.
4 *
5 * @package automattic/jetpack-videopress
6 **/
7
8 namespace Automattic\Jetpack\VideoPress;
9
10 /**
11 * Class Block_Replacement
12 **/
13 class Block_Replacement {
14 /**
15 * Whether the class has been initiated.
16 *
17 * @var bool
18 */
19 private static $initiated = false;
20
21 /**
22 * Initialize replacement.
23 */
24 public static function init() {
25 if ( self::$initiated ) {
26 return;
27 }
28 add_filter( 'render_block', array( self::class, 'replace_media_text_with_videopress' ), 10, 2 );
29 }
30
31 /**
32 * Replace video in Media & Text block with Videopress shortcode.
33 *
34 * @param string $block_content The block content.
35 * @param array $block The block.
36 * @return string
37 */
38 public static function replace_media_text_with_videopress( $block_content, $block ) {
39 if ( isset( $block['blockName'] ) && $block['blockName'] === 'core/media-text' ) {
40
41 // Make sure we have a $post_id that could be valid; if we don't, then video_get_info_by_blogpostid()
42 // will fail, so there's no point in calling it.
43 $post_id = isset( $block['attrs']['mediaId'] ) ? (int) $block['attrs']['mediaId'] : 0;
44 if ( $post_id <= 0 ) {
45 return $block_content;
46 }
47
48 $video_info = video_get_info_by_blogpostid( get_current_blog_id(), $post_id );
49 if ( $video_info && $video_info->guid ) {
50 $videopress_shortcode = sprintf( '[videopress %s]', esc_attr( $video_info->guid ) );
51 $block_content = preg_replace( '/<video.*?<\/video>/is', do_shortcode( $videopress_shortcode ), $block_content );
52 }
53 }
54 return $block_content;
55 }
56 }
57