Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
CRAP
n/a
0 / 0
Automattic\Jetpack\Extensions\Goodreads\register_block
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
Automattic\Jetpack\Extensions\Goodreads\load_assets
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * Goodreads Block.
4 *
5 * @since 13.2
6 *
7 * @package automattic/jetpack
8 */
9
10namespace Automattic\Jetpack\Extensions\Goodreads;
11
12use Automattic\Jetpack\Blocks;
13use Jetpack_Gutenberg;
14
15if ( ! defined( 'ABSPATH' ) ) {
16    exit( 0 );
17}
18
19/**
20 * Registers the block for use in Gutenberg.
21 * This is done via an action so that we can disable
22 * registration if we need to.
23 */
24function register_block() {
25    Blocks::jetpack_register_block(
26        __DIR__,
27        array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
28    );
29}
30add_action( 'init', __NAMESPACE__ . '\register_block' );
31
32/**
33 * Goodreads block registration/dependency declaration.
34 *
35 * @param array $attr    Array containing the Goodreads block attributes.
36 *
37 * @return string
38 */
39function load_assets( $attr ) {
40    Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
41
42    if ( isset( $attr['id'] ) ) {
43        if ( isset( $attr['link'] ) ) {
44            wp_enqueue_script(
45                'jetpack-goodreads-' . esc_attr( $attr['id'] ),
46                esc_url_raw( $attr['link'] ),
47                array(),
48                JETPACK__VERSION,
49                true
50            );
51        }
52
53        $id = esc_attr( $attr['id'] );
54    } else {
55        $id = '';
56    }
57
58    $classes = esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ) );
59
60    return sprintf(
61        '<div id="%1$s" class="%2$s"></div>',
62        $id,
63        $classes
64    );
65}