# metricool/2.0.2/app/Features/Notifications/NotificationsEndpoints.php

Metricool – Social media and site statistics, version 2.0.2. 62 lines.

- Page: https://pluginprobe.com/plugins/metricool/2.0.2/code/app/Features/Notifications/NotificationsEndpoints.php
- Raw: https://pluginprobe.com/plugins/metricool/2.0.2/raw/app/Features/Notifications/NotificationsEndpoints.php
- Modified: 2026-06-11T08:45:10+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/metricool/2.0.2/code/app/Features/Notifications/NotificationsEndpoints.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Metricool\Features\Notifications;

if (!defined('ABSPATH')) {
    exit;
}

use Metricool\Traits\HasRestAccess;
use Metricool\Traits\HasAllowlistControl;

class NotificationsEndpoints
{
    use HasRestAccess;
    use HasAllowlistControl;

    private NotificationsService $service;

    public function __construct(NotificationsService $service)
    {
        $this->service = $service;
    }

    public function register(): void
    {
        add_filter('metricool_rest_routes', [$this, 'addNotificationRoutes']);
    }

    /**
     * Add the Notification routes to the REST API.
     */
    public function addNotificationRoutes(array $routes): array
    {
        if ($this->adminAccessAllowed() === false) {
            return $routes;
        }

        $routes['get_notices'] = [
            'methods' => \WP_REST_Server::READABLE,
            'callback' => [$this, 'getNoticesCallback'],
        ];

        return $routes;
    }

    /**
     * Return current Notices as a WP_REST_Response.
     */
    public function getNoticesCallback(\WP_REST_Request $request): \WP_REST_Response
    {
        $allNoticesAsArray = array_map(function ($notice) {
            return $notice->toArray();
        }, $this->service->getAllNotices());

        return $this->sendHttpResponse(
            array_values($allNoticesAsArray) // Keys should be removed
        );
    }
}

```
