Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
38.46% |
5 / 13 |
|
0.00% |
0 / 2 |
CRAP | n/a |
0 / 0 |
|
| wpcom_videopress_modernized_dashboard_enabled | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
5.39 | |||
| wpcom_videopress_init_admin_ui | |
25.00% |
2 / 8 |
|
0.00% |
0 / 1 |
10.75 | |||
| 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 | |
| 19 | use Automattic\Jetpack\Status\Host; |
| 20 | |
| 21 | /** |
| 22 | * Whether the modernized VideoPress dashboard is rolled out to this Simple |
| 23 | * site and user (VIDP-285). |
| 24 | * |
| 25 | * The whole admin UI keys off Admin_UI::is_modernized() — menu registration |
| 26 | * (add_wp_admin_submenu bails without it), the wp-build asset load, and the |
| 27 | * boot payload — so this is the Simple staged-rollout switch: off by default, |
| 28 | * on for CFT testers via the blog sticker, and always on for Automatticians. |
| 29 | * UI-only by design: the REST surface (wpcom/v2 routes, attachment query |
| 30 | * filters, the server-side token mint) stays registered regardless, so the |
| 31 | * API contract doesn't flap with the flag. |
| 32 | * |
| 33 | * @return bool Whether the modernized dashboard should be enabled. |
| 34 | */ |
| 35 | function wpcom_videopress_modernized_dashboard_enabled() { |
| 36 | if ( |
| 37 | function_exists( 'wpcom_has_blog_sticker' ) && function_exists( 'get_wpcom_blog_id' ) |
| 38 | && wpcom_has_blog_sticker( 'videopress-modernized-dashboard', get_wpcom_blog_id() ) |
| 39 | ) { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | return function_exists( 'is_automattician' ) && is_automattician( get_current_user_id() ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Initialize the VideoPress Admin UI on WordPress.com Simple sites. |
| 48 | * |
| 49 | * Guarded on Simple because on Atomic and standalone Jetpack the VideoPress package |
| 50 | * already calls Admin_UI::init() from its own Initializer; running it here too would |
| 51 | * double-register its hooks. Guarded with class_exists because mu-wpcom does not |
| 52 | * composer-require the jetpack-videopress package: the class is provided by the wpcom |
| 53 | * platform's bundled Jetpack source on Simple. |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | function wpcom_videopress_init_admin_ui() { |
| 58 | if ( ! ( new Host() )->is_wpcom_simple() ) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * VIDP-285: staged rollout. Registered on Simple only, so self-hosted and |
| 64 | * Atomic keep the filter's default (enabled). The callbacks that consult |
| 65 | * Admin_UI::is_modernized() run at admin_menu time, well after this |
| 66 | * plugins_loaded-time registration. |
| 67 | */ |
| 68 | add_filter( 'rsm_jetpack_ui_modernization_videopress', 'wpcom_videopress_modernized_dashboard_enabled' ); |
| 69 | |
| 70 | if ( ! class_exists( '\Automattic\Jetpack\VideoPress\Admin_UI' ) ) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | // @phan-suppress-next-line PhanUndeclaredClassMethod -- class_exists guarded above; provided by the sibling autoloader (bundled Jetpack on Simple). |
| 75 | \Automattic\Jetpack\VideoPress\Admin_UI::init(); |
| 76 | |
| 77 | // Emit the JPVIDEOPRESS_INITIAL_STATE boot payload the wp-build dashboard hydrates from. |
| 78 | if ( class_exists( '\Automattic\Jetpack\VideoPress\Initial_State' ) ) { |
| 79 | // @phan-suppress-next-line PhanUndeclaredClassMethod -- class_exists guarded above; provided by the sibling autoloader (bundled Jetpack on Simple). |
| 80 | \Automattic\Jetpack\VideoPress\Initial_State::init(); |
| 81 | } |
| 82 | } |
| 83 | wpcom_videopress_init_admin_ui(); |