| 1 |
<?php |
| 2 |
/** |
| 3 |
* Map block. |
| 4 |
* |
| 5 |
* @since 6.8.0 |
| 6 |
* |
| 7 |
* @package Jetpack |
| 8 |
*/ |
| 9 |
|
| 10 |
jetpack_register_block( |
| 11 |
'jetpack/map', |
| 12 |
array( |
| 13 |
'render_callback' => 'jetpack_map_block_load_assets', |
| 14 |
) |
| 15 |
); |
| 16 |
|
| 17 |
/** |
| 18 |
* Map block registration/dependency declaration. |
| 19 |
* |
| 20 |
* @param array $attr Array containing the map block attributes. |
| 21 |
* @param string $content String containing the map block content. |
| 22 |
* |
| 23 |
* @return string |
| 24 |
*/ |
| 25 |
function jetpack_map_block_load_assets( $attr, $content ) { |
| 26 |
$dependencies = array( |
| 27 |
'lodash', |
| 28 |
'wp-element', |
| 29 |
'wp-i18n', |
| 30 |
); |
| 31 |
|
| 32 |
$api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); |
| 33 |
|
| 34 |
Jetpack_Gutenberg::load_assets_as_required( 'map', $dependencies ); |
| 35 |
|
| 36 |
return preg_replace( '/<div /', '<div data-api-key="' . esc_attr( $api_key ) . '" ', $content, 1 ); |
| 37 |
} |
| 38 |
|