sharing-buttons.php
42 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Sharing Buttons Block. |
| 4 | * |
| 5 | * @since 11.x |
| 6 | * |
| 7 | * @package automattic/jetpack |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack\Extensions\Sharing_Buttons; |
| 11 | |
| 12 | use Automattic\Jetpack\Blocks; |
| 13 | /** |
| 14 | * Registers the block for use in Gutenberg |
| 15 | * This is done via an action so that we can disable |
| 16 | * registration if we need to. |
| 17 | */ |
| 18 | function register_block() { |
| 19 | Blocks::jetpack_register_block( |
| 20 | __DIR__, |
| 21 | array( 'render_callback' => __NAMESPACE__ . '\render_block' ) |
| 22 | ); |
| 23 | } |
| 24 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 25 | |
| 26 | /** |
| 27 | * Sharing Buttons block registration/dependency declaration. |
| 28 | * |
| 29 | * @param array $attr Array containing the Sharing Buttons block attributes. |
| 30 | * @param string $content String containing the Sharing Buttons block content. |
| 31 | * |
| 32 | * @return string |
| 33 | */ |
| 34 | function render_block( $attr, $content ) { |
| 35 | // Render nothing in other contexts than frontend (i.e. feed, emails, API, etc.). |
| 36 | if ( ! jetpack_is_frontend() ) { |
| 37 | return ''; |
| 38 | } |
| 39 | |
| 40 | return $content; |
| 41 | } |
| 42 |