Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.62% covered (warning)
84.62%
11 / 13
50.00% covered (danger)
50.00%
1 / 2
CRAP
n/a
0 / 0
wpcom_videopress_trim_cut_enabled
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
5
wpcom_videopress_init_admin_ui
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
4.03
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 * Enable trim and cut for the Simple-site testing cohort.
23 *
24 * @return bool Whether the current site or user is included in the rollout.
25 */
26function wpcom_videopress_trim_cut_enabled() {
27    if (
28        function_exists( 'wpcom_has_blog_sticker' ) && function_exists( 'get_wpcom_blog_id' )
29        && wpcom_has_blog_sticker( 'videopress-studio-edits', get_wpcom_blog_id() )
30    ) {
31        return true;
32    }
33
34    return function_exists( 'is_automattician' ) && is_automattician( get_current_user_id() );
35}
36
37/**
38 * Initialize the VideoPress Admin UI on WordPress.com Simple sites.
39 *
40 * Guarded on Simple because on Atomic and standalone Jetpack the VideoPress package
41 * already calls Admin_UI::init() from its own Initializer; running it here too would
42 * double-register its hooks. Guarded with class_exists because mu-wpcom does not
43 * composer-require the jetpack-videopress package: the class is provided by the wpcom
44 * platform's bundled Jetpack source on Simple.
45 *
46 * @return void
47 */
48function wpcom_videopress_init_admin_ui() {
49    if ( ! ( new Host() )->is_wpcom_simple() ) {
50        return;
51    }
52
53    add_filter( 'jetpack_videopress_trim_cut', 'wpcom_videopress_trim_cut_enabled' );
54
55    if ( ! class_exists( '\Automattic\Jetpack\VideoPress\Admin_UI' ) ) {
56        return;
57    }
58
59    \Automattic\Jetpack\VideoPress\Admin_UI::init();
60
61    // Emit the JPVIDEOPRESS_INITIAL_STATE boot payload the wp-build dashboard hydrates from.
62    if ( class_exists( '\Automattic\Jetpack\VideoPress\Initial_State' ) ) {
63        \Automattic\Jetpack\VideoPress\Initial_State::init();
64    }
65}
66wpcom_videopress_init_admin_ui();