goodreads.php
54 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Goodreads Block. |
| 4 | * |
| 5 | * @since 13.2 |
| 6 | * |
| 7 | * @package automattic/jetpack |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack\Extensions\Goodreads; |
| 11 | |
| 12 | use Automattic\Jetpack\Blocks; |
| 13 | use Jetpack_Gutenberg; |
| 14 | |
| 15 | /** |
| 16 | * Registers the block for use in Gutenberg. |
| 17 | * This is done via an action so that we can disable |
| 18 | * registration if we need to. |
| 19 | */ |
| 20 | function register_block() { |
| 21 | Blocks::jetpack_register_block( |
| 22 | __DIR__, |
| 23 | array( 'render_callback' => __NAMESPACE__ . '\load_assets' ) |
| 24 | ); |
| 25 | } |
| 26 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 27 | |
| 28 | /** |
| 29 | * Goodreads block registration/dependency declaration. |
| 30 | * |
| 31 | * @param array $attr Array containing the Goodreads block attributes. |
| 32 | * |
| 33 | * @return string |
| 34 | */ |
| 35 | function load_assets( $attr ) { |
| 36 | Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); |
| 37 | |
| 38 | if ( isset( $attr['link'] ) && isset( $attr['id'] ) ) { |
| 39 | wp_enqueue_script( |
| 40 | 'jetpack-goodreads-' . esc_attr( $attr['id'] ), |
| 41 | esc_url_raw( $attr['link'] ), |
| 42 | array(), |
| 43 | JETPACK__VERSION, |
| 44 | true |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | return sprintf( |
| 49 | '<div id="%1$s" class="%2$s"></div>', |
| 50 | esc_attr( $attr['id'] ), |
| 51 | esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) ) |
| 52 | ); |
| 53 | } |
| 54 |