Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| WPCOM_Block_Editor_NUX | |
0.00% |
0 / 49 |
|
0.00% |
0 / 4 |
56 | |
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 / 29 |
|
0.00% |
0 / 1 |
12 | |||
| register_rest_api | |
0.00% |
0 / 15 |
|
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 | require_once __DIR__ . '/../../utils.php'; |
| 11 | |
| 12 | /** |
| 13 | * Class WPCOM_Block_Editor_NUX |
| 14 | */ |
| 15 | class WPCOM_Block_Editor_NUX { |
| 16 | /** |
| 17 | * Class instance. |
| 18 | * |
| 19 | * @var WPCOM_Block_Editor_NUX |
| 20 | */ |
| 21 | private static $instance = null; |
| 22 | |
| 23 | /** |
| 24 | * WPCOM_Block_Editor_NUX constructor. |
| 25 | */ |
| 26 | public function __construct() { |
| 27 | add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_script_and_style' ), 100 ); |
| 28 | add_action( 'rest_api_init', array( $this, 'register_rest_api' ) ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Creates instance. |
| 33 | * |
| 34 | * @return \Automattic\Jetpack\Jetpack_Mu_Wpcom\NUX\WPCOM_Block_Editor_NUX |
| 35 | */ |
| 36 | public static function init() { |
| 37 | if ( self::$instance === null ) { |
| 38 | self::$instance = new self(); |
| 39 | } |
| 40 | return self::$instance; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Enqueue block editor assets. |
| 45 | */ |
| 46 | public function enqueue_script_and_style() { |
| 47 | $handle = jetpack_mu_wpcom_enqueue_assets( 'wpcom-block-editor-nux', array( 'js', 'css' ) ); |
| 48 | wp_set_script_translations( $handle, 'jetpack-mu-wpcom' ); |
| 49 | |
| 50 | /** |
| 51 | * Enqueue the launchpad options. |
| 52 | */ |
| 53 | $launchpad_options = wp_json_encode( |
| 54 | array( |
| 55 | 'launchpadScreenOption' => get_option( 'launchpad_screen' ), |
| 56 | 'siteUrlOption' => get_option( 'siteurl' ), |
| 57 | 'siteIntentOption' => get_option( 'site_intent' ), |
| 58 | ), |
| 59 | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP |
| 60 | ); |
| 61 | |
| 62 | wp_add_inline_script( |
| 63 | $handle, |
| 64 | "var launchpadOptions = $launchpad_options;", |
| 65 | 'before' |
| 66 | ); |
| 67 | |
| 68 | $site_id = \Jetpack_Options::get_option( 'id' ); |
| 69 | $is_p2_site = str_contains( get_stylesheet(), 'pub/p2' ) || function_exists( '\WPForTeams\is_wpforteams_site' ) && is_wpforteams_site( $site_id ); |
| 70 | |
| 71 | /** |
| 72 | * Enqueue the recommended tags modal options. |
| 73 | */ |
| 74 | $recommended_tags_modal_options = wp_json_encode( |
| 75 | array( |
| 76 | 'isDismissed' => WP_REST_WPCOM_Block_Editor_Recommended_Tags_Modal_Controller::get_wpcom_recommended_tags_modal_dismissed(), |
| 77 | 'isP2' => $is_p2_site, |
| 78 | ), |
| 79 | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP |
| 80 | ); |
| 81 | |
| 82 | wp_add_inline_script( |
| 83 | $handle, |
| 84 | "var recommendedTagsModalOptions = $recommended_tags_modal_options;", |
| 85 | 'before' |
| 86 | ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Register the WPCOM Block Editor NUX endpoints. |
| 91 | */ |
| 92 | public function register_rest_api() { |
| 93 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-nux-status-controller.php'; |
| 94 | $controller = new WP_REST_WPCOM_Block_Editor_NUX_Status_Controller(); |
| 95 | $controller->register_rest_route(); |
| 96 | |
| 97 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-first-post-published-modal-controller.php'; |
| 98 | $first_post_published_modal_controller = new WP_REST_WPCOM_Block_Editor_First_Post_Published_Modal_Controller(); |
| 99 | $first_post_published_modal_controller->register_rest_route(); |
| 100 | |
| 101 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-seller-celebration-modal-controller.php'; |
| 102 | $seller_celebration_modal_controller = new WP_REST_WPCOM_Block_Editor_Seller_Celebration_Modal_Controller(); |
| 103 | $seller_celebration_modal_controller->register_rest_route(); |
| 104 | |
| 105 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-video-celebration-modal-controller.php'; |
| 106 | $video_celebration_modal_controller = new WP_REST_WPCOM_Block_Editor_Video_Celebration_Modal_Controller(); |
| 107 | $video_celebration_modal_controller->register_rest_route(); |
| 108 | |
| 109 | require_once __DIR__ . '/class-wp-rest-wpcom-block-editor-recommended-tags-modal-controller.php'; |
| 110 | $recommended_tags_modal_controller = new WP_REST_WPCOM_Block_Editor_Recommended_Tags_Modal_Controller(); |
| 111 | $recommended_tags_modal_controller->register_rest_route(); |
| 112 | } |
| 113 | } |
| 114 | add_action( 'init', array( __NAMESPACE__ . '\WPCOM_Block_Editor_NUX', 'init' ) ); |