permanently_dismissed_site_kit_configuration_repository = $permanently_dismissed_site_kit_configuration_repository; $this->capability_helper = $capability_helper; } /** * Registers routes with WordPress. * * @return void */ public function register_routes() { \register_rest_route( self::ROUTE_NAMESPACE, self::ROUTE_PREFIX, [ [ 'methods' => 'POST', 'callback' => [ $this, 'set_site_kit_configuration_permanent_dismissal' ], 'permission_callback' => [ $this, 'check_capabilities' ], 'args' => [ 'is_dismissed' => [ 'required' => true, 'type' => 'bool', 'sanitize_callback' => 'rest_sanitize_boolean', ], ], ], ], ); } /** * Sets whether the Site Kit configuration is permanently dismissed. * * @param WP_REST_Request $request The request object. * * @return WP_REST_Response|WP_Error The success or failure response. */ public function set_site_kit_configuration_permanent_dismissal( WP_REST_Request $request ) { $is_dismissed = $request->get_param( 'is_dismissed' ); try { $result = $this->permanently_dismissed_site_kit_configuration_repository->set_site_kit_configuration_dismissal( $is_dismissed ); } catch ( Exception $exception ) { return new WP_Error( 'wpseo_set_site_kit_configuration_permanent_dismissal_error', $exception->getMessage(), (object) [], ); } return new WP_REST_Response( [ 'success' => $result, ], ( $result ) ? 200 : 400, ); } /** * Checks if the current user has the required capabilities. * * @return bool */ public function check_capabilities() { return $this->capability_helper->current_user_can( 'wpseo_manage_options' ); } }