Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 70 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| WPCOM_Block_Editor_NUX | |
0.00% |
0 / 68 |
|
0.00% |
0 / 5 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| init | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| enqueue_script_and_style | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
12 | |||
| is_coming_soon | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| register_rest_api | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WPCOM Block Editor NUX file. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Jetpack_Mu_Wpcom\NUX; |
| 9 | |
| 10 | use Automattic\Jetpack\Status; |
| 11 | |
| 12 | require_once __DIR__ . '/../../utils.php'; |
| 13 | |
| 14 | /** |
| 15 | * Class WPCOM_Block_Editor_NUX |
| 16 | */ |
| 17 | class WPCOM_Block_Editor_NUX { |
| 18 | /** |
| 19 | * Class instance. |
| 20 | * |
| 21 | * @var WPCOM_Block_Editor_NUX |
| 22 | */ |
| 23 | private static $instance = null; |
| 24 | |
| 25 | /** |
| 26 | * WPCOM_Block_Editor_NUX constructor. |
| 27 | */ |
| 28 | public function __construct() { |
| 29 | add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_script_and_style' ), 100 ); |
| 30 | add_action( 'rest_api_init', array( $this, 'register_rest_api' ) ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Creates instance. |
| 35 | * |
| 36 | * @return \Automattic\Jetpack\Jetpack_Mu_Wpcom\NUX\WPCOM_Block_Editor_NUX |
| 37 | */ |
| 38 | public static function init() { |
| 39 | if ( self::$instance === null ) { |
| 40 | self::$instance = new self(); |
| 41 | } |
| 42 | return self::$instance; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Enqueue block editor assets. |
| 47 | */ |
| 48 | public function enqueue_script_and_style() { |
| 49 | $handle = jetpack_mu_wpcom_enqueue_assets( 'wpcom-block-editor-nux', array( 'js', 'css' ) ); |
| 50 | wp_set_script_translations( $handle, 'jetpack-mu-wpcom' ); |
| 51 | |
| 52 | /** |
| 53 | * Enqueue the launchpad options. |
| 54 | */ |
| 55 | $launchpad_options = wp_json_encode( |
| 56 | array( |
| 57 | 'launchpadScreenOption' => get_option( 'launchpad_screen' ), |
| 58 | 'siteUrlOption' => get_option( 'siteurl' ), |
| 59 | 'siteIntentOption' => get_option( 'site_intent' ), |
| 60 | ), |
| 61 | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP |
| 62 | ); |
| 63 | |
| 64 | wp_add_inline_script( |
| 65 | $handle, |
| 66 | "var launchpadOptions = $launchpad_options;", |
| 67 | 'before' |
| 68 | ); |
| 69 | |
| 70 | $site_id = \Jetpack_Options::get_option( 'id' ); |
| 71 | $is_p2_site = str_contains( get_stylesheet(), 'pub/p2' ) || function_exists( '\WPForTeams\is_wpforteams_site' ) && is_wpforteams_site( $site_id ); |
| 72 | |
| 73 | /** |
| 74 | * Enqueue the recommended tags modal options. |
| 75 | */ |
| 76 | $recommended_tags_modal_options = wp_json_encode( |
| 77 | array( |
| 78 | 'isDismissed' => WP_REST_WPCOM_Block_Editor_Recommended_Tags_Modal_Controller::get_wpcom_recommended_tags_modal_dismissed(), |
| 79 | 'isP2' => $is_p2_site, |
| 80 | ), |
| 81 | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP |
| 82 | ); |
| 83 | |
| 84 | wp_add_inline_script( |
| 85 | $handle, |
| 86 | "var recommendedTagsModalOptions = $recommended_tags_modal_options;", |
| 87 | 'before' |
| 88 | ); |
| 89 | |
| 90 | /** |
| 91 | * Enqueue the site visibility panel options. |
| 92 | */ |
| 93 | $site_visibility_panel_options = wp_json_encode( |
| 94 | array( |
| 95 | 'isComingSoon' => self::is_coming_soon(), |
| 96 | 'canChangeVisibility' => current_user_can( 'manage_options' ), |
| 97 | 'settingsUrl' => admin_url( 'options-reading.php' ), |
| 98 | ), |
| 99 | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP |
| 100 | ); |
| 101 | |
| 102 | wp_add_inline_script( |
| 103 | $handle, |
| 104 | "var siteVisibilityPanelOptions = $site_visibility_panel_options;", |
| 105 | 'before' |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Whether the site is Coming Soon. |
| 111 | * |
| 112 | * Status finds the WordPress.com global and the public Coming Soon option, but on Atomic the |
| 113 | * equivalent function is namespaced by wpcomsh, which is where the legacy private-site flavor |
| 114 | * of Coming Soon lives. |
| 115 | * |
| 116 | * @return bool |
| 117 | */ |
| 118 | private static function is_coming_soon() { |
| 119 | if ( ( new Status() )->is_coming_soon() ) { |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | // @phan-suppress-next-line PhanUndeclaredFunction -- Only called where wpcomsh defines it. |
| 124 | return function_exists( '\Private_Site\site_is_coming_soon' ) && \Private_Site\site_is_coming_soon(); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Register the WPCOM Block Editor NUX endpoints. |
| 129 | */ |
| 130 | public function register_rest_api() { |
| 131 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-nux-status-controller.php'; |
| 132 | $controller = new WP_REST_WPCOM_Block_Editor_NUX_Status_Controller(); |
| 133 | $controller->register_rest_route(); |
| 134 | |
| 135 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-first-post-published-modal-controller.php'; |
| 136 | $first_post_published_modal_controller = new WP_REST_WPCOM_Block_Editor_First_Post_Published_Modal_Controller(); |
| 137 | $first_post_published_modal_controller->register_rest_route(); |
| 138 | |
| 139 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-seller-celebration-modal-controller.php'; |
| 140 | $seller_celebration_modal_controller = new WP_REST_WPCOM_Block_Editor_Seller_Celebration_Modal_Controller(); |
| 141 | $seller_celebration_modal_controller->register_rest_route(); |
| 142 | |
| 143 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-video-celebration-modal-controller.php'; |
| 144 | $video_celebration_modal_controller = new WP_REST_WPCOM_Block_Editor_Video_Celebration_Modal_Controller(); |
| 145 | $video_celebration_modal_controller->register_rest_route(); |
| 146 | |
| 147 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-recommended-tags-modal-controller.php'; |
| 148 | $recommended_tags_modal_controller = new WP_REST_WPCOM_Block_Editor_Recommended_Tags_Modal_Controller(); |
| 149 | $recommended_tags_modal_controller->register_rest_route(); |
| 150 | |
| 151 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-four-for-four-controller.php'; |
| 152 | $four_for_four_controller = new WP_REST_WPCOM_Block_Editor_Four_For_Four_Controller(); |
| 153 | $four_for_four_controller->register_rest_route(); |
| 154 | } |
| 155 | } |
| 156 | add_action( 'init', array( __NAMESPACE__ . '\WPCOM_Block_Editor_NUX', 'init' ) ); |