Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
CRAP
n/a
0 / 0
Automattic\Jetpack\Extensions\Rating_Star\register_block
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
Automattic\Jetpack\Extensions\Rating_Star\render_block
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
Automattic\Jetpack\Extensions\Rating_Star\amp_add_inline_css
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * Star Rating Block.
4 *
5 * @since 8.0.0
6 *
7 * @package automattic/jetpack
8 */
9
10namespace Automattic\Jetpack\Extensions\Rating_Star;
11
12use Automattic\Jetpack\Blocks;
13use Jetpack_Gutenberg;
14
15if ( ! defined( 'ABSPATH' ) ) {
16    exit( 0 );
17}
18
19// Load generic function definitions.
20require_once __DIR__ . '/rating-meta.php';
21
22/**
23 * Registers the block for use in Gutenberg
24 * This is done via an action so that we can disable
25 * registration if we need to.
26 */
27function register_block() {
28    Blocks::jetpack_register_block(
29        __DIR__,
30        array(
31            'render_callback' => __NAMESPACE__ . '\render_block',
32        )
33    );
34}
35add_action( 'init', __NAMESPACE__ . '\register_block' );
36
37/**
38 * Dynamic rendering of the block.
39 *
40 * @param array $attributes Array containing the block attributes.
41 *
42 * @return string
43 */
44function render_block( $attributes ) {
45    // Tell Jetpack to load the assets registered via jetpack_register_block.
46    Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
47
48    return jetpack_rating_meta_render_block( $attributes );
49}
50
51/**
52 * Older versions of AMP (0.6.2) are unable to render the markup, so we hide it
53 * Newer versions of AMP (1.4.1+) seem OK, but need the screen-reader text hidden
54 */
55function amp_add_inline_css() {
56    if ( defined( 'AMP__VERSION' ) && version_compare( AMP__VERSION, '1.4.1', '>=' ) ) {
57        echo '.wp-block-jetpack-rating-star span.screen-reader-text { border: 0; clip-path: inset(50%); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; word-wrap: normal; }';
58    } else {
59        echo '.wp-block-jetpack-rating-star span:not([aria-hidden="true"]) { display: none; }';
60    }
61}
62add_action( 'amp_post_template_css', __NAMESPACE__ . '\amp_add_inline_css', 11 );