Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
VideoPress_Module
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 load
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Divi 5 VideoPress module.
4 *
5 * @package automattic/jetpack-videopress
6 */
7
8declare( strict_types = 1 );
9
10namespace Automattic\Jetpack\VideoPress\Divi5;
11
12use Automattic\Jetpack\VideoPress\Divi5\Traits\Module_Classnames_Trait;
13use Automattic\Jetpack\VideoPress\Divi5\Traits\Module_Script_Data_Trait;
14use Automattic\Jetpack\VideoPress\Divi5\Traits\Module_Styles_Trait;
15use Automattic\Jetpack\VideoPress\Divi5\Traits\Render_Callback_Trait;
16use ET\Builder\Framework\DependencyManagement\Interfaces\DependencyInterface;
17use ET\Builder\Packages\ModuleLibrary\ModuleRegistration;
18
19if ( ! defined( 'ABSPATH' ) ) {
20    exit( 0 );
21}
22
23/**
24 * Registers and renders the VideoPress module within the Divi 5 framework.
25 *
26 * The `ET\Builder\*` symbols this class relies on only exist while Divi 5 is
27 * active, which is why the class is loaded lazily from hooks that Divi 5 fires.
28 */
29class VideoPress_Module implements DependencyInterface {
30
31    use Render_Callback_Trait;
32    use Module_Classnames_Trait;
33    use Module_Styles_Trait;
34    use Module_Script_Data_Trait;
35
36    /**
37     * Matches a VideoPress URL or GUID and captures the GUID. Kept in sync with
38     * the regex used by the Visual Builder renderer.
39     *
40     * @var string
41     */
42    const VIDEOPRESS_REGEX = '/^(?:(?:http(?:s)?:\/\/)?(?:www\.)?video(?:\.word)?press\.com\/(?:v|embed)\/)?([a-zA-Z\d]+)(?:.*)?/i';
43
44    /**
45     * The module's block name. Must match the `name` field in `module.json`.
46     *
47     * @var string
48     */
49    const MODULE_NAME = 'jetpack/videopress';
50
51    /**
52     * Registers the module with the Divi 5 module library.
53     *
54     * @return void
55     */
56    public function load() {
57        /*
58         * Divi walks its dependency tree more than once per request, and
59         * Divi_5::init() also calls this directly, so guard on the registry to
60         * register exactly once. Registering before `init` matches how Divi
61         * registers its own modules during theme bootstrap.
62         */
63        if ( \WP_Block_Type_Registry::get_instance()->is_registered( self::MODULE_NAME ) ) {
64            return;
65        }
66
67        // Read from build/ (shipped) rather than src/client/ (production-excluded).
68        ModuleRegistration::register_module(
69            dirname( __DIR__, 2 ) . '/build/divi-5/modules/videopress',
70            array(
71                'render_callback' => array( self::class, 'render_callback' ),
72            )
73        );
74    }
75}