PluginProbe
The Innovative Form Builder – IvyForms / 0.1.2
The Innovative Form Builder – IvyForms v0.1.2
1.5.1 1.5 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 All 27 releases
ivyforms / backend / src / Controllers / Notification / DeleteNotificationsController.php

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

59 lines 1.6 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\Controllers\Controller;
13 use IvyForms\Common\Sanitizer\Sanitizer;
14 use IvyForms\Services\Notification\NotificationService;
15 use WP_REST_Request;
16 use WP_REST_Response;
17
18 /**
19 * Class DeleteNotificationsController
20 *
21 * @package IvyForms\Controllers\Notification
22 */
23 class DeleteNotificationsController extends Controller
24 {
25 private NotificationService $notificationService;
26
27 public function __construct(NotificationService $notificationService)
28 {
29 $this->notificationService = $notificationService;
30 }
31
32 /**
33 * @param WP_REST_Request $data
34 *
35 * @return WP_REST_Response
36 *
37 * @throws InvalidArgumentException
38 * @throws ForbiddenException
39 */
40 public function handle(WP_REST_Request $data): WP_REST_Response
41 {
42 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
43 $notificationIds = Sanitizer::sanitizeIds($data->get_param('ids'));
44
45 if (empty($notificationIds)) {
46 throw new InvalidArgumentException('Notification IDs are required and must be an array.');
47 }
48
49 foreach ($notificationIds as $id) {
50 $this->notificationService->deleteNotification($id);
51 }
52
53 return new WP_REST_Response([
54 'message' => 'Successfully deleted notifications.',
55 'data' => []
56 ], 200);
57 }
58 }
59