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