# metricool/2.1.1/app/Features/AdminNotices/AdminNoticesController.php

Metricool – Social media and site statistics, version 2.1.1. 68 lines.

- Page: https://pluginprobe.com/plugins/metricool/2.1.1/code/app/Features/AdminNotices/AdminNoticesController.php
- Raw: https://pluginprobe.com/plugins/metricool/2.1.1/raw/app/Features/AdminNotices/AdminNoticesController.php
- Modified: 2026-08-20T14:08:30+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.1.1/code/app/Features/AdminNotices/AdminNoticesController.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Metricool\Features\AdminNotices;

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

use Metricool\Interfaces\FeatureInterface;
use Metricool\Support\Helpers\Storages\EnvironmentConfig;

class AdminNoticesController implements FeatureInterface
{
    private EnvironmentConfig $env;
    private AdminNoticesEndpoints $endpoints;
    private AdminNoticesRepository $repository;

    public function __construct(EnvironmentConfig $env, AdminNoticesEndpoints $endpoints, AdminNoticesRepository $repository)
    {
        $this->env = $env;
        $this->endpoints = $endpoints;
        $this->repository = $repository;
    }

    public function register(): void
    {
        add_action('admin_init', [$this, 'renderNotices']);

        $this->endpoints->register();
    }

    /**
     * Render all admin notices that should be displayed
     */
    public function renderNotices(): void
    {
        $notices = $this->repository->getShouldBeDisplayed();

        if (count($notices) === 0) {
            return;
        }

        add_action('admin_enqueue_scripts', [$this, 'enqueueScripts']);

        add_action('admin_notices', static function () use ($notices) {
            foreach ($notices as $notice) {
                $notice->render();
            }
        });
    }

    /**
     * Enqueue the javascript for the admin notices
     */
    public function enqueueScripts(): void
    {
        wp_enqueue_script(
            'metricool-admin-notice',
            $this->env->getUrl('plugin.assets_url') . 'js/admin-notice.js',
            [],
            $this->env->getString('plugin.version'),
            true
        );
    }
}

```
