Completed
Push — update/mailchimp-ui-changes ( f4a7d6...e71283 )
by
unknown
11:27
created

map.php ➔ jetpack_map_block_load_assets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Map block.
4
 *
5
 * @since 6.8.0
6
 *
7
 * @package Jetpack
8
 */
9
10
register_block_type(
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