sharing-buttons.php
48 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 | use Automattic\Jetpack\Status\Request; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit( 0 ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Registers the block for use in Gutenberg |
| 21 | * This is done via an action so that we can disable |
| 22 | * registration if we need to. |
| 23 | */ |
| 24 | function register_block() { |
| 25 | Blocks::jetpack_register_block( |
| 26 | __DIR__, |
| 27 | array( 'render_callback' => __NAMESPACE__ . '\render_block' ) |
| 28 | ); |
| 29 | } |
| 30 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 31 | |
| 32 | /** |
| 33 | * Sharing Buttons block registration/dependency declaration. |
| 34 | * |
| 35 | * @param array $attr Array containing the Sharing Buttons block attributes. |
| 36 | * @param string $content String containing the Sharing Buttons block content. |
| 37 | * |
| 38 | * @return string |
| 39 | */ |
| 40 | function render_block( $attr, $content ) { |
| 41 | // Render nothing in other contexts than frontend (i.e. feed, emails, API, etc.). |
| 42 | if ( ! Request::is_frontend() ) { |
| 43 | return ''; |
| 44 | } |
| 45 | |
| 46 | return $content; |
| 47 | } |
| 48 |