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 / 2
CRAP
n/a
0 / 0
Automattic\Jetpack\Extensions\VideoPress\register_block
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
Automattic\Jetpack\Extensions\VideoPress\load_assets
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * VideoPress Block.
4 *
5 * @since 11.1.0
6 *
7 * @package automattic/jetpack
8 */
9
10namespace Automattic\Jetpack\Extensions\VideoPress;
11
12use Automattic\Jetpack\Blocks;
13use Automattic\Jetpack\Modules;
14use Jetpack_Gutenberg;
15
16if ( ! defined( 'ABSPATH' ) ) {
17    exit( 0 );
18}
19
20const FEATURE_NAME   = 'videopress-block';
21const FEATURE_FOLDER = 'videopress';
22const BLOCK_NAME     = 'jetpack/' . FEATURE_NAME;
23
24/**
25 * Registers the block for use in Gutenberg
26 * This is done via an action so that we can disable
27 * registration if we need to.
28 */
29function register_block() {
30    /*
31     * The block is available even when the module is not active,
32     * so we can display a nudge to activate the module instead of the block.
33     * However, since non-admins cannot activate modules, we do not display the empty block for them.
34     */
35    if ( ! ( new Modules() )->is_active( 'videopress' ) && ! current_user_can( 'jetpack_activate_modules' ) ) {
36        return;
37    }
38
39    Blocks::jetpack_register_block(
40        BLOCK_NAME,
41        array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
42    );
43}
44add_action( 'init', __NAMESPACE__ . '\register_block' );
45
46/**
47 * VideoPress block registration/dependency declaration.
48 *
49 * @param array  $attrs   Array containing the VideoPress block attributes.
50 * @param string $content String containing the VideoPress block content.
51 *
52 * @return string
53 */
54function load_assets( $attrs, $content ) {
55    // Do not render the block if the module is not active.
56    if ( ! ( new Modules() )->is_active( 'videopress' ) ) {
57        return '';
58    }
59
60    Jetpack_Gutenberg::load_assets_as_required( FEATURE_FOLDER );
61    return $content;
62}