# yatra/3.0.4/app/Controllers/NoticeController.php

Yatra – Travel Booking &amp; Tour Operator Software, version 3.0.4. 77 lines.

- Page: https://pluginprobe.com/plugins/yatra/3.0.4/code/app/Controllers/NoticeController.php
- Raw: https://pluginprobe.com/plugins/yatra/3.0.4/raw/app/Controllers/NoticeController.php
- Modified: 2026-04-16T07:54:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/yatra/3.0.4/code/app/Controllers/NoticeController.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Yatra\Controllers;

use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
use Yatra\Services\NoticeService;

defined('ABSPATH') || exit;

final class NoticeController extends BaseController
{
    /**
     * @var string
     */
    protected string $rest_base = 'notices';

    public function check_permission(?\WP_REST_Request $request = null): bool
    {
        return current_user_can('manage_options') || current_user_can('manage_yatra');
    }

    public function register_routes(): void
    {
        register_rest_route($this->namespace, '/' . $this->rest_base, [
            [
                'methods' => WP_REST_Server::READABLE,
                'callback' => [$this, 'index'],
                'permission_callback' => [$this, 'check_permission'],
            ],
        ]);

        register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[a-z0-9_\\-]+)/dismiss', [
            [
                'methods' => WP_REST_Server::CREATABLE,
                'callback' => [$this, 'dismiss'],
                'permission_callback' => [$this, 'check_permission'],
                'args' => [
                    'id' => [
                        'required' => true,
                        'type' => 'string',
                    ],
                ],
            ],
        ]);
    }

    public function index(WP_REST_Request $request): WP_REST_Response
    {
        return rest_ensure_response([
            'success' => true,
            'data' => NoticeService::getActiveNoticesForCurrentUser(),
        ]);
    }

    public function dismiss(WP_REST_Request $request): WP_REST_Response
    {
        $id = sanitize_key((string) $request->get_param('id'));
        $result = NoticeService::dismissForCurrentUser($id);
        if ($result === true) {
            return rest_ensure_response(['success' => true]);
        }

        $response = rest_ensure_response([
            'success' => false,
            'code' => $result->get_error_code(),
            'message' => $result->get_error_message(),
        ]);
        $response->set_status((int) ($result->get_error_data()['status'] ?? 400));
        return $response;
    }
}


```
