Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| WP_REST_WPCOM_Block_Editor_Video_Celebration_Modal_Controller | |
0.00% |
0 / 48 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| register_rest_route | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
2 | |||
| permission_callback | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| has_seen_video_celebration_modal | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| set_has_seen_video_celebration_modal | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WP_REST_WPCOM_Block_Editor_Video_Celebration_Modal_Controller file. |
| 4 | * |
| 5 | * @package Aautomattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Jetpack_Mu_Wpcom\NUX; |
| 9 | |
| 10 | /** |
| 11 | * Class WP_REST_WPCOM_Block_Editor_Video_Celebration_Modal_Controller. |
| 12 | */ |
| 13 | class WP_REST_WPCOM_Block_Editor_Video_Celebration_Modal_Controller extends \WP_REST_Controller { |
| 14 | /** |
| 15 | * WP_REST_WPCOM_Block_Editor_Video_Celebration_Modal_Controller constructor. |
| 16 | */ |
| 17 | public function __construct() { |
| 18 | $this->namespace = 'wpcom/v2'; |
| 19 | $this->rest_base = 'block-editor/has-seen-video-celebration-modal'; |
| 20 | $this->wpcom_is_site_specific_endpoint = true; |
| 21 | $this->wpcom_is_wpcom_only_endpoint = true; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Register available routes. |
| 26 | */ |
| 27 | public function register_rest_route() { |
| 28 | register_rest_route( |
| 29 | $this->namespace, |
| 30 | $this->rest_base, |
| 31 | array( |
| 32 | array( |
| 33 | 'methods' => \WP_REST_Server::READABLE, |
| 34 | 'callback' => array( $this, 'has_seen_video_celebration_modal' ), |
| 35 | 'permission_callback' => array( $this, 'permission_callback' ), |
| 36 | ), |
| 37 | ) |
| 38 | ); |
| 39 | register_rest_route( |
| 40 | $this->namespace, |
| 41 | $this->rest_base, |
| 42 | array( |
| 43 | array( |
| 44 | 'methods' => \WP_REST_Server::EDITABLE, |
| 45 | 'callback' => array( $this, 'set_has_seen_video_celebration_modal' ), |
| 46 | 'permission_callback' => array( $this, 'permission_callback' ), |
| 47 | 'args' => array( |
| 48 | 'has_seen_video_celebration_modal' => array( |
| 49 | 'required' => true, |
| 50 | 'type' => 'boolean', |
| 51 | ), |
| 52 | ), |
| 53 | ), |
| 54 | ) |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Callback to determine whether the request can proceed. |
| 60 | * |
| 61 | * @return boolean |
| 62 | */ |
| 63 | public function permission_callback() { |
| 64 | return current_user_can( 'read' ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Whether the site has displayed the video upload celebration modal. |
| 69 | * |
| 70 | * @return \WP_REST_Response |
| 71 | */ |
| 72 | public function has_seen_video_celebration_modal() { |
| 73 | // See D69932-code and apps/editing-toolkit/editing-toolkit-plugin/wpcom-block-editor-nux/class-wp-rest-wpcom-block-editor-first-post-published-modal-controller.php. |
| 74 | if ( defined( 'IS_ATOMIC' ) && IS_ATOMIC ) { |
| 75 | return rest_ensure_response( |
| 76 | array( |
| 77 | 'has_seen_video_celebration_modal' => true, |
| 78 | ) |
| 79 | ); |
| 80 | } |
| 81 | $has_seen_video_celebration_modal = (bool) get_option( 'has_seen_video_celebration_modal', false ); |
| 82 | |
| 83 | return rest_ensure_response( |
| 84 | array( |
| 85 | 'has_seen_video_celebration_modal' => $has_seen_video_celebration_modal, |
| 86 | ) |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Update the option for whether the user has seen the video upload celebration modal. |
| 92 | * |
| 93 | * @param \WP_REST_Request $request Request object. |
| 94 | * @return \WP_REST_Response |
| 95 | */ |
| 96 | public function set_has_seen_video_celebration_modal( $request ) { |
| 97 | $params = $request->get_json_params(); |
| 98 | update_option( 'has_seen_video_celebration_modal', $params['has_seen_video_celebration_modal'] ); |
| 99 | return rest_ensure_response( array( 'has_seen_video_celebration_modal' => $params['has_seen_video_celebration_modal'] ) ); |
| 100 | } |
| 101 | } |