Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
6 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
wpcom_videopress_init_admin_ui
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
4.05
1<?php
2/**
3 * Boots the modernized Jetpack VideoPress dashboard on WordPress.com Simple sites.
4 *
5 * On Simple sites the standalone Jetpack plugin's bootstrap (load-jetpack.php) never
6 * runs, so the VideoPress package's Admin_UI is never initialized. Mirroring the
7 * Newsletter Settings integration, this feature initializes Admin_UI — and its React
8 * initial-state payload — on Simple only. The menu item itself is registered
9 * separately from wpcom-admin-menu.php, once the Jetpack parent menu exists.
10 *
11 * Atomic/WoA and the standalone plugin are unaffected: there the VideoPress package
12 * initializes Admin_UI through its own Initializer, and the Host::is_wpcom_simple()
13 * gate below keeps this feature from running (and double-registering hooks) on those
14 * hosts.
15 *
16 * @package automattic/jetpack-mu-wpcom
17 */
18
19use Automattic\Jetpack\Status\Host;
20
21/**
22 * Initialize the VideoPress Admin UI on WordPress.com Simple sites.
23 *
24 * Guarded on Simple because on Atomic and standalone Jetpack the VideoPress package
25 * already calls Admin_UI::init() from its own Initializer; running it here too would
26 * double-register its hooks. Guarded with class_exists because mu-wpcom does not
27 * composer-require the jetpack-videopress package: the class is provided by the wpcom
28 * platform's bundled Jetpack source on Simple.
29 *
30 * @return void
31 */
32function wpcom_videopress_init_admin_ui() {
33    if ( ! ( new Host() )->is_wpcom_simple() ) {
34        return;
35    }
36
37    if ( ! class_exists( '\Automattic\Jetpack\VideoPress\Admin_UI' ) ) {
38        return;
39    }
40
41    \Automattic\Jetpack\VideoPress\Admin_UI::init();
42
43    // Emit the JPVIDEOPRESS_INITIAL_STATE boot payload the wp-build dashboard hydrates from.
44    if ( class_exists( '\Automattic\Jetpack\VideoPress\Initial_State' ) ) {
45        \Automattic\Jetpack\VideoPress\Initial_State::init();
46    }
47}
48wpcom_videopress_init_admin_ui();