Completed
Push — update/tiled-gallery-wp-blob ( b03b77...213493 )
by Bernhard
06:53
created

blocks.php ➔ jetpack_tiled_gallery_load_block_assets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 10
rs 9.9332
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
 * Tiled Gallery block. Depends on the Photon module.
20
 *
21
 * @since 6.9.0
22
*/
23
if ( class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) {
24
	jetpack_register_block(
25
		'tiled-gallery',
26
		array(
27
			'render_callback' => 'jetpack_tiled_gallery_load_block_assets',
28
		)
29
	);
30
31
	/**
32
	 * Tiled gallery block registration/dependency declaration.
33
	 *
34
	 * @param array  $attr - Array containing the block attributes.
35
	 * @param string $content - String containing the block content.
36
	 *
37
	 * @return string
38
	 */
39
	function jetpack_tiled_gallery_load_block_assets( $attr, $content ) {
40
		$dependencies = array(
41
			'lodash',
42
			'wp-blob',
43
			'wp-i18n',
44
			'wp-token-list',
45
		);
46
		Jetpack_Gutenberg::load_assets_as_required( 'tiled-gallery', $dependencies );
47
		return $content;
48
	}
49
}
50
51
/**
52
 * Map block registration/dependency declaration.
53
 *
54
 * @param array  $attr - Array containing the map block attributes.
55
 * @param string $content - String containing the map block content.
56
 *
57
 * @return string
58
 */
59
function jetpack_map_block_load_assets( $attr, $content ) {
60
	$dependencies = array(
61
		'lodash',
62
		'wp-element',
63
		'wp-i18n',
64
	);
65
66
	$api_key = Jetpack_Options::get_option( 'mapbox_api_key' );
67
68
	Jetpack_Gutenberg::load_assets_as_required( 'map', $dependencies );
69
	return preg_replace( '/<div /', '<div data-api-key="'. esc_attr( $api_key ) .'" ', $content, 1 );
70
}
71