AudioBlock.php
9 months ago
MediaHubBlock.php
9 months ago
PopupBlock.php
10 months ago
PopupMediaBlock.php
7 months ago
PopupTriggerBlock.php
10 months ago
ReusableEditBlock.php
9 months ago
ReusableVideoBlock.php
2 weeks ago
SelfHostedBlock.php
9 months ago
VimeoBlock.php
9 months ago
YouTubeBlock.php
9 months ago
ReusableVideoBlock.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Reusable Video Block Class |
| 4 | * |
| 5 | * @package PrestoPlayer\Blocks |
| 6 | */ |
| 7 | |
| 8 | namespace PrestoPlayer\Blocks; |
| 9 | |
| 10 | use PrestoPlayer\Models\ReusableVideo; |
| 11 | |
| 12 | /** |
| 13 | * Reusable Video Block |
| 14 | */ |
| 15 | class ReusableVideoBlock { |
| 16 | /** |
| 17 | * Block name |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | protected $name = 'reusable-display'; |
| 22 | |
| 23 | /** |
| 24 | * Register Block |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public function register() { |
| 29 | add_action( 'init', array( $this, 'registerBlockType' ) ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Register the block type |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public function registerBlockType() { |
| 38 | register_block_type( |
| 39 | "presto-player/$this->name", |
| 40 | // @phpstan-ignore-next-line -- WP stubs follow core's docblock typing api_version as string, but WP_Block_Type::$api_version is int. |
| 41 | array( |
| 42 | 'api_version' => 3, |
| 43 | 'render_callback' => array( $this, 'html' ), |
| 44 | ) |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Dynamic block output |
| 50 | * |
| 51 | * @param array $attributes Block attributes. |
| 52 | * |
| 53 | * @return string |
| 54 | */ |
| 55 | public function html( $attributes ) { |
| 56 | // create reusable video block instance. |
| 57 | $block = new ReusableVideo( $attributes['id'] ?? '' ); |
| 58 | |
| 59 | // avoid override here, so that inner block id is not replaced. |
| 60 | unset( $attributes['id'] ); |
| 61 | |
| 62 | // render block. |
| 63 | return $block->renderBlock( $attributes ); |
| 64 | } |
| 65 | } |
| 66 |