Completed
Push — mailchimp/introduce-shortcode ( 9080cd...aff2fb )
by
unknown
07:44
created

blocks.php ➔ jetpack_tiled_gallery_load_block_assets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Load code specific to Gutenberg blocks which are not tied to a module.
4
 * This file is unusual, and is not an actual `module` as such.
5
 * It is included in ./module-extras.php
6
 *
7
 */
8
9
jetpack_register_block(
10
	'map',
11
	array(
12
		'render_callback' => 'jetpack_map_block_load_assets',
13
	)
14
);
15
16
jetpack_register_block( 'vr' );
17
18
/**
19
 * Map block registration/dependency declaration.
20
 *
21
 * @param array  $attr - Array containing the map block attributes.
22
 * @param string $content - String containing the map block content.
23
 *
24
 * @return string
25
 */
26
function jetpack_map_block_load_assets( $attr, $content ) {
27
	$dependencies = array(
28
		'lodash',
29
		'wp-element',
30
		'wp-i18n',
31
	);
32
33
	$api_key = Jetpack_Options::get_option( 'mapbox_api_key' );
34
35
	Jetpack_Gutenberg::load_assets_as_required( 'map', $dependencies );
36
	return preg_replace( '/<div /', '<div data-api-key="'. esc_attr( $api_key ) .'" ', $content, 1 );
37
}
38