Completed
Push — add/google-calendar-block ( b8a4ef...f2fa71 )
by
unknown
06:57
created

google-calendar.php ➔ jetpack_google_calendar_block_load_assets()   B

Complexity

Conditions 8
Paths 48

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 48
nop 1
dl 0
loc 24
rs 8.4444
c 0
b 0
f 0
1
<?php
2
/**
3
 * Google Calendar Block.
4
 *
5
 * @since 8.0.0
6
 *
7
 * @package Jetpack
8
 */
9
10
jetpack_register_block(
11
	'jetpack/google-calendar',
12
	array(
13
		'attributes'           => array(
14
			'url'    => array(
15
				'type' => 'string',
16
			),
17
			'width'  => array(
18
				'type'    => 'integer',
19
				'default' => 800,
20
			),
21
			'height' => array(
22
				'type'    => 'integer',
23
				'default' => 600,
24
			),
25
		),
26
		'render_callback'      => 'jetpack_google_calendar_block_load_assets',
27
		'version_requirements' => array(
28
			'wp'     => '5.4',
29
			'plugin' => '7.2',
30
		),
31
	)
32
);
33
34
/**
35
 * Google Calendar block registration/dependency declaration.
36
 *
37
 * @param array $attr Array containing the Google Calendar block attributes.
38
 * @return string
39
 */
40
function jetpack_google_calendar_block_load_assets( $attr ) {
41
	$width  = isset( $attr['width'] ) ? $attr['width'] : '800';
42
	$height = isset( $attr['height'] ) ? $attr['height'] : '600';
43
	$url    = isset( $attr['url'] ) ? $attr['url'] : '';
44
	$align  = isset( $attr['align'] ) ? 'align' . $attr['align'] : '';
45
46
	if ( empty( $url ) ) {
47
		return;
48
	}
49
50
	if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
51
		return <<<EOT
52
<div class="wp-block-jetpack-google-calendar ${align}">
53
	<amp-iframe src="${url}" frameborder="0" style="border:0" scrolling="no" width="${width}" height="${height}" sandbox="allow-scripts allow-same-origin" layout="responsive"></amp-iframe>
54
</div>
55
EOT;
56
	} else {
57
		return <<<EOT
58
<div class="wp-block-jetpack-google-calendar ${align}">
59
	<iframe src="${url}" frameborder="0" style="border:0" scrolling="no" width="${width}" height="${height}"></iframe>
60
</div>
61
EOT;
62
	}
63
}
64