sharing-buttons.php
50 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( __DIR__ ); |
| 20 | } |
| 21 | add_action( 'init', __NAMESPACE__ . '\register_block' ); |
| 22 | |
| 23 | /** |
| 24 | * Add the services list to the block |
| 25 | */ |
| 26 | function add_sharing_buttons_block_data() { |
| 27 | $services = array( |
| 28 | 'print', |
| 29 | 'facebook', |
| 30 | 'linkedin', |
| 31 | 'mail', |
| 32 | 'mastodon', |
| 33 | 'pinterest', |
| 34 | 'pocket', |
| 35 | 'reddit', |
| 36 | 'telegram', |
| 37 | 'tumblr', |
| 38 | 'whatsapp', |
| 39 | 'x', |
| 40 | 'nextdoor', |
| 41 | ); |
| 42 | |
| 43 | wp_add_inline_script( |
| 44 | 'jetpack-block-sharing-button', |
| 45 | 'var jetpack_sharing_buttons_services = ' . wp_json_encode( $services, JSON_HEX_TAG | JSON_HEX_AMP ) . ';', |
| 46 | 'before' |
| 47 | ); |
| 48 | } |
| 49 | add_action( 'enqueue_block_assets', __NAMESPACE__ . '\add_sharing_buttons_block_data' ); |
| 50 |