Completed
Push — add/single-product-backup-butt... ( 3efc2e...208dd4 )
by Jeremy
10:52 queued 04:50
created

rating-star.php ➔ jetpack_rating_star_render_block()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Star Rating Block.
4
 *
5
 * @since 8.0.0
6
 *
7
 * @package Jetpack
8
 */
9
10
// Load generic function definitions.
11
require_once __DIR__ . '/rating-meta.php';
12
13
/**
14
 * Dynamic rendering of the block.
15
 *
16
 * @param array $attributes Array containing the block attributes.
17
 *
18
 * @return string
19
 */
20
function jetpack_rating_star_render_block( $attributes ) {
21
	// Tell Jetpack to load the assets registered via jetpack_register_block.
22
	Jetpack_Gutenberg::load_assets_as_required( 'rating-star' );
23
24
	return jetpack_rating_meta_render_block( $attributes );
25
}
26
27
/**
28
 * The following filter is added only to support the old 0.6.2 version of the AMP plugin.
29
 * This entire section can be removed once we're on version a newer version.
30
 * Confirmed that version 1.4.1 (or presumably newer) does not need this filter.
31
 */
32
function jetpack_rating_star_amp_add_inline_css() {
33
	echo '.wp-block-jetpack-rating-star span { display: none; }';
34
}
35
add_action( 'amp_post_template_css', 'jetpack_rating_star_amp_add_inline_css', 11 );
36
37
jetpack_register_block(
38
	'jetpack/rating-star',
39
	array(
40
		'render_callback' => 'jetpack_rating_star_render_block',
41
		'attributes'      => array(
42
			'rating'      => array(
43
				'type'    => 'number',
44
				'default' => 1,
45
			),
46
			'maxRating'   => array(
47
				'type'    => 'number',
48
				'default' => 5,
49
			),
50
			'color'       => array(
51
				'type' => 'string',
52
			),
53
			'ratingStyle' => array(
54
				'type'    => 'string',
55
				'default' => 'star',
56
			),
57
			'className'   => array(
58
				'type' => 'string',
59
			),
60
			'align'       => array(
61
				'type'    => 'string',
62
				'default' => 'left',
63
			),
64
		),
65
	)
66
);
67