ai-chat.php
49 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Jetpack AI Chat. |
| 4 | * |
| 5 | * @since 12.1 |
| 6 | * |
| 7 | * @package automattic/jetpack |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack\Extensions\AIChat; |
| 11 | |
| 12 | use Automattic\Jetpack\Blocks; |
| 13 | use Jetpack_Gutenberg; |
| 14 | |
| 15 | const FEATURE_NAME = 'ai-chat'; |
| 16 | const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; |
| 17 | |
| 18 | /** |
| 19 | * Registers our block for use in Gutenberg |
| 20 | * This is done via an action so that we can disable |
| 21 | * registration if we need to. |
| 22 | */ |
| 23 | function register_block() { |
| 24 | Blocks::jetpack_register_block( |
| 25 | BLOCK_NAME, |
| 26 | array( 'render_callback' => __NAMESPACE__ . '\load_assets' ) |
| 27 | ); |
| 28 | } |
| 29 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 30 | |
| 31 | /** |
| 32 | * Jetpack AI Paragraph block registration/dependency declaration. |
| 33 | * |
| 34 | * @param array $attr Array containing the Jetpack AI Chat block attributes. |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | function load_assets( $attr ) { |
| 39 | /* |
| 40 | * Enqueue necessary scripts and styles. |
| 41 | */ |
| 42 | Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); |
| 43 | |
| 44 | return sprintf( |
| 45 | '<div class="%1$s" id="jetpack-ai-chat"></div>', |
| 46 | esc_attr( Blocks::classes( FEATURE_NAME, $attr ) ) |
| 47 | ); |
| 48 | } |
| 49 |