render.php
54 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Goodreads block render implementation. |
| 4 | * |
| 5 | * Loaded lazily from goodreads.php only when the block is rendered, to keep |
| 6 | * the render body out of the eager front-end PHP/opcache footprint. |
| 7 | * |
| 8 | * @package automattic/jetpack |
| 9 | */ |
| 10 | |
| 11 | namespace Automattic\Jetpack\Extensions\Goodreads; |
| 12 | |
| 13 | use Automattic\Jetpack\Blocks; |
| 14 | use Jetpack_Gutenberg; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit( 0 ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Dynamic rendering of the block. |
| 22 | * |
| 23 | * @param array $attr Array containing the Goodreads block attributes. |
| 24 | * |
| 25 | * @return string |
| 26 | */ |
| 27 | function render_implementation( $attr ) { |
| 28 | Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); |
| 29 | |
| 30 | if ( isset( $attr['id'] ) ) { |
| 31 | if ( isset( $attr['link'] ) ) { |
| 32 | wp_enqueue_script( |
| 33 | 'jetpack-goodreads-' . esc_attr( $attr['id'] ), |
| 34 | esc_url_raw( $attr['link'] ), |
| 35 | array(), |
| 36 | JETPACK__VERSION, |
| 37 | true |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | $id = esc_attr( $attr['id'] ); |
| 42 | } else { |
| 43 | $id = ''; |
| 44 | } |
| 45 | |
| 46 | $classes = esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) ); |
| 47 | |
| 48 | return sprintf( |
| 49 | '<div id="%1$s" class="%2$s"></div>', |
| 50 | $id, |
| 51 | $classes |
| 52 | ); |
| 53 | } |
| 54 |