Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
71.43% covered (warning)
71.43%
10 / 14
40.00% covered (danger)
40.00%
2 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Divi
71.43% covered (warning)
71.43%
10 / 14
40.00% covered (danger)
40.00%
2 / 5
8.14
0.00% covered (danger)
0.00%
0 / 1
 init
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_instance
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 run
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 on_fb_framework_loaded
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 initialize_extension
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Divi integration for Videopress.
4 *
5 * @package automattic/jetpack-videopress
6 **/
7
8namespace Automattic\Jetpack\VideoPress;
9
10use Automattic\Jetpack\VideoPress\Divi5\Divi_5;
11
12/**
13 * Class Divi
14 **/
15class Divi {
16    /**
17     * The instance.
18     *
19     * @var Divi
20     **/
21    private static $instance = null;
22
23    /**
24     * Running or not.
25     *
26     * @var bool
27     **/
28    private $running = false;
29
30    /**
31     * VideoPress Divi Extension object.
32     *
33     * @var ?\VideoPress_Divi_Extension
34     **/
35    private $vidi_extension;
36
37    /**
38     * Initializes VideoPress/Divi integration.
39     *
40     * Called only once by the Initializer class
41     *
42     * @return self
43     */
44    public static function init() {
45        return self::get_instance()->run();
46    }
47
48    /**
49     * Get the instance.
50     *
51     * @return self
52     */
53    public static function get_instance() {
54        if ( null === self::$instance ) {
55            self::$instance = new self();
56        }
57        return self::$instance;
58    }
59
60    /**
61     * Run the extension.
62     *
63     * @return self
64     */
65    public function run() {
66        if ( $this->running ) {
67            return $this;
68        }
69
70        $this->running = true;
71        add_action( 'divi_extensions_init', array( $this, 'initialize_extension' ) );
72        add_action( 'et_fb_framework_loaded', array( $this, 'on_fb_framework_loaded' ) );
73
74        // Divi 5 integration. These hooks only fire under Divi 5; the legacy
75        // extension above continues to serve Divi 4.
76        Divi_5::init();
77
78        return $this;
79    }
80
81    /**
82     * Fires when the Frontend Builder is loaded.
83     */
84    public function on_fb_framework_loaded() {
85        Jwt_Token_Bridge::enqueue_jwt_token_bridge();
86    }
87
88    /**
89     * Creates the extension's main class instance.
90     */
91    public function initialize_extension() {
92        require_once plugin_dir_path( __FILE__ ) . 'videopress-divi/class-videopress-divi-extension.php';
93        $this->vidi_extension = new \VideoPress_Divi_Extension();
94    }
95}