Completed
Push — kraftbj-patch-2 ( b56d75 )
by
unknown
06:26
created

rating-star.php ➔ amp_add_inline_css()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
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
namespace Automattic\Jetpack\Extensions\Rating_Star;
11
12
use Jetpack_Gutenberg;
13
14
const FEATURE_NAME = 'rating-star';
15
const BLOCK_NAME   = 'jetpack/' . FEATURE_NAME;
16
17
// Load generic function definitions.
18
require_once __DIR__ . '/rating-meta.php';
19
20
/**
21
 * Registers the block for use in Gutenberg
22
 * This is done via an action so that we can disable
23
 * registration if we need to.
24
 */
25
function register_block() {
26
	jetpack_register_block(
27
		BLOCK_NAME,
28
		array(
29
			'render_callback' => __NAMESPACE__ . '\render_block',
30
			'attributes'      => array(
31
				'rating'      => array(
32
					'type'    => 'number',
33
					'default' => 1,
34
				),
35
				'maxRating'   => array(
36
					'type'    => 'number',
37
					'default' => 5,
38
				),
39
				'color'       => array(
40
					'type' => 'string',
41
				),
42
				'ratingStyle' => array(
43
					'type'    => 'string',
44
					'default' => 'star',
45
				),
46
				'className'   => array(
47
					'type' => 'string',
48
				),
49
				'align'       => array(
50
					'type'    => 'string',
51
					'default' => 'left',
52
				),
53
			),
54
		)
55
	);
56
}
57
add_action( 'init', __NAMESPACE__ . '\register_block' );
58
59
/**
60
 * Dynamic rendering of the block.
61
 *
62
 * @param array $attributes Array containing the block attributes.
63
 *
64
 * @return string
65
 */
66
function render_block( $attributes ) {
67
	// Tell Jetpack to load the assets registered via jetpack_register_block.
68
	Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME );
69
70
	return jetpack_rating_meta_render_block( $attributes );
71
}
72
73
/**
74
 * The following filter is added only to support the old 0.6.2 version of the AMP plugin.
75
 * This entire section can be removed once we're on version a newer version.
76
 * Confirmed that version 1.4.1 (or presumably newer) does not need this filter.
77
 */
78
function amp_add_inline_css() {
79
	echo '.wp-block-jetpack-rating-star span { display: none; }';
80
}
81
add_action( 'amp_post_template_css', __NAMESPACE__ . '\amp_add_inline_css', 11 );
82
83