PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.3
Yatra – Travel Booking & Tour Operator Software v3.0.3
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Controllers / NoticeController.php

NoticeController.php in Yatra – Travel Booking & Tour Operator Software 3.0.3, at app/Controllers/NoticeController.php

77 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Controllers;
6
7 use WP_REST_Request;
8 use WP_REST_Response;
9 use WP_REST_Server;
10 use Yatra\Services\NoticeService;
11
12 defined('ABSPATH') || exit;
13
14 final class NoticeController extends BaseController
15 {
16 /**
17 * @var string
18 */
19 protected string $rest_base = 'notices';
20
21 public function check_permission(?\WP_REST_Request $request = null): bool
22 {
23 return current_user_can('manage_options') || current_user_can('manage_yatra');
24 }
25
26 public function register_routes(): void
27 {
28 register_rest_route($this->namespace, '/' . $this->rest_base, [
29 [
30 'methods' => WP_REST_Server::READABLE,
31 'callback' => [$this, 'index'],
32 'permission_callback' => [$this, 'check_permission'],
33 ],
34 ]);
35
36 register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[a-z0-9_\\-]+)/dismiss', [
37 [
38 'methods' => WP_REST_Server::CREATABLE,
39 'callback' => [$this, 'dismiss'],
40 'permission_callback' => [$this, 'check_permission'],
41 'args' => [
42 'id' => [
43 'required' => true,
44 'type' => 'string',
45 ],
46 ],
47 ],
48 ]);
49 }
50
51 public function index(WP_REST_Request $request): WP_REST_Response
52 {
53 return rest_ensure_response([
54 'success' => true,
55 'data' => NoticeService::getActiveNoticesForCurrentUser(),
56 ]);
57 }
58
59 public function dismiss(WP_REST_Request $request): WP_REST_Response
60 {
61 $id = sanitize_key((string) $request->get_param('id'));
62 $result = NoticeService::dismissForCurrentUser($id);
63 if ($result === true) {
64 return rest_ensure_response(['success' => true]);
65 }
66
67 $response = rest_ensure_response([
68 'success' => false,
69 'code' => $result->get_error_code(),
70 'message' => $result->get_error_message(),
71 ]);
72 $response->set_status((int) ($result->get_error_data()['status'] ?? 400));
73 return $response;
74 }
75 }
76
77