podcast-player.php
68 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Podcast Player Block. |
| 4 | * |
| 5 | * @since 8.4.0 |
| 6 | * |
| 7 | * @package automattic/jetpack |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack\Extensions\Podcast_Player; |
| 11 | |
| 12 | use Automattic\Jetpack\Blocks; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 0 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Registers the block for use in Gutenberg. This is done via an action so that |
| 20 | * we can disable registration if we need to. |
| 21 | */ |
| 22 | function register_block() { |
| 23 | Blocks::jetpack_register_block( |
| 24 | __DIR__, |
| 25 | array( |
| 26 | 'render_callback' => __NAMESPACE__ . '\render_block', |
| 27 | // Since Gutenberg #31873. |
| 28 | 'style' => 'wp-mediaelement', |
| 29 | 'render_email_callback' => __NAMESPACE__ . '\render_email', |
| 30 | ) |
| 31 | ); |
| 32 | } |
| 33 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 34 | |
| 35 | /** |
| 36 | * Podcast Player block registration/dependency declaration. |
| 37 | * |
| 38 | * The render implementation lives in render.php and is only loaded when the |
| 39 | * block is actually rendered, keeping it out of the eager front-end path. |
| 40 | * |
| 41 | * @param array $attributes Array containing the Podcast Player block attributes. |
| 42 | * @param string $content Fallback content - a direct link to RSS, as rendered by save.js. |
| 43 | * @return string |
| 44 | */ |
| 45 | function render_block( $attributes, $content ) { |
| 46 | require_once __DIR__ . '/render.php'; |
| 47 | return render_block_implementation( $attributes, $content ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Render podcast player block for email. |
| 52 | * |
| 53 | * The render implementation lives in render.php and is only loaded when the |
| 54 | * block is actually rendered, keeping it out of the eager front-end path. |
| 55 | * |
| 56 | * @since 15.0 |
| 57 | * |
| 58 | * @param string $block_content The original block HTML content. |
| 59 | * @param array $parsed_block The parsed block data including attributes. |
| 60 | * @param object $rendering_context Email rendering context. |
| 61 | * |
| 62 | * @return string |
| 63 | */ |
| 64 | function render_email( $block_content, array $parsed_block, $rendering_context ) { |
| 65 | require_once __DIR__ . '/render.php'; |
| 66 | return render_email_implementation( $block_content, $parsed_block, $rendering_context ); |
| 67 | } |
| 68 |