PluginProbe
The Innovative Form Builder – IvyForms / 0.8
The Innovative Form Builder – IvyForms v0.8
1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 1.2 1.3
ivyforms / backend / src / Controllers / Notification / DeleteNotificationController.php

DeleteNotificationController.php in The Innovative Form Builder – IvyForms 0.8, at backend/src/Controllers/Notification/DeleteNotificationController.php

62 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Controllers\Notification;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Common\Exceptions\ForbiddenException;
11 use IvyForms\Common\Exceptions\InvalidArgumentException;
12 use IvyForms\Common\Exceptions\NotFoundException;
13 use IvyForms\Common\Sanitizer\Sanitizer;
14 use IvyForms\Controllers\Controller;
15 use IvyForms\Services\Notification\NotificationService;
16 use IvyForms\Services\Translations\BackendStrings;
17 use WP_REST_Request;
18 use WP_REST_Response;
19
20 /**
21 * Class DeleteNotificationController
22 *
23 * @package IvyForms\Controllers\Notification
24 */
25 class DeleteNotificationController extends Controller
26 {
27 private NotificationService $notificationService;
28
29 public function __construct(NotificationService $notificationService)
30 {
31 $this->notificationService = $notificationService;
32 }
33
34 /**
35 * @param WP_REST_Request $data
36 *
37 * @return WP_REST_Response
38 *
39 * @throws InvalidArgumentException
40 * @throws ForbiddenException
41 */
42 public function handle(WP_REST_Request $data): WP_REST_Response
43 {
44 // Verify the nonce
45 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
46 $notificationId = Sanitizer::sanitizeId($data->get_param('id'));
47
48 if (empty($notificationId)) {
49 throw new InvalidArgumentException(
50 BackendStrings::getExceptionStrings()['notification_id_required']
51 );
52 }
53
54 $this->notificationService->deleteNotification($notificationId);
55
56 return new WP_REST_Response([
57 'message' => BackendStrings::getCommonStrings()['ok'],
58 'data' => []
59 ], 200);
60 }
61 }
62