like.php
52 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Like Block. |
| 4 | * |
| 5 | * @since 12.9 |
| 6 | * |
| 7 | * @package automattic/jetpack |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack\Extensions\Like; |
| 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( |
| 24 | 'api_version' => 3, |
| 25 | 'render_callback' => __NAMESPACE__ . '\render_block', |
| 26 | ) |
| 27 | ); |
| 28 | } |
| 29 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 30 | |
| 31 | /** |
| 32 | * Like block render function. |
| 33 | * |
| 34 | * @param array $attr Array containing the Like block attributes. |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | function render_block( $attr ) { |
| 39 | /* |
| 40 | * Enqueue necessary scripts and styles. |
| 41 | */ |
| 42 | Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); |
| 43 | |
| 44 | $output = 'This is where the like button will go.'; |
| 45 | |
| 46 | return sprintf( |
| 47 | '<div class="%1$s">%2$s</div>', |
| 48 | esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) ), |
| 49 | $output |
| 50 | ); |
| 51 | } |
| 52 |