# acymailing/11.0.0/back/Controllers/Configuration/Subscription.php

AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress, version 11.0.0. 122 lines.

- Page: https://pluginprobe.com/plugins/acymailing/11.0.0/code/back/Controllers/Configuration/Subscription.php
- Raw: https://pluginprobe.com/plugins/acymailing/11.0.0/raw/back/Controllers/Configuration/Subscription.php
- Modified: 2026-08-03T10:18:54+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/acymailing/11.0.0/code/back/Controllers/Configuration/Subscription.php#L10-L20`.

```php
<?php

namespace AcyMailing\Controllers\Configuration;

use AcyMailing\Controllers\DashboardController;
use AcyMailing\Helpers\HeaderHelper;

trait Subscription
{
    public function removeNotification(): void
    {
        wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');

        $whichNotification = acym_getVar('string', 'id');

        if ($whichNotification !== '0' && empty($whichNotification)) {
            acym_sendAjaxResponse(acym_translation('ACYM_NOTIFICATION_NOT_FOUND'), [], false);
        }

        $notifications = json_decode($this->config->get('notifications', '[]'), true) ?? [];
        $dashboardNotifications = json_decode($this->config->get('dashboard_notif', '[]'), true) ?? [];

        if ('all' === $whichNotification) {
            $notifications = [];
        } else {
            $notifications = array_values(array_filter($notifications, fn($notif) => !isset($notif['id']) || $notif['id'] !== $whichNotification));

            $dashboardNotifications = array_values(array_filter($dashboardNotifications, fn($notif) => !isset($notif['name']) || $notif['name'] !== $whichNotification));

            if (is_numeric($whichNotification)) {
                $notifications = array_values(array_filter($notifications, fn($notif, $key) => $key != $whichNotification, ARRAY_FILTER_USE_BOTH));
            }
        }

        $this->config->saveConfig(['notifications' => json_encode($notifications)]);
        $this->config->saveConfig(['dashboard_notif' => json_encode($dashboardNotifications)], false);

        $headerHelper = new HeaderHelper();
        $dashboardController = new DashboardController();

        $data = [
            'notifications' => $dashboardNotifications,
        ];
        $dashboardController->getDashboardNotifications($data);


        ob_start();
        $headerHelper->displayNotificationCenterInner($notifications);
        $notificationCenter = ob_get_clean();

        acym_sendAjaxResponse(
            '',
            [
                'headerHtml' => $notificationCenter,
                'dashboardHtml' => $data['dashboardNotifications'],
            ]
        );
    }

    public function markNotificationRead(): void
    {
        wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');

        $which = acym_getVar('string', 'id');

        $notifications = json_decode($this->config->get('notifications', '[]'), true);
        if (empty($notifications)) {
            acym_sendAjaxResponse('', []);
        }

        if (empty($which)) {
            foreach ($notifications as $key => $notification) {
                $notifications[$key]['read'] = true;
            }
        } else {
            foreach ($notifications as $key => $notification) {
                if ($notification['id'] != $which) continue;
                $notifications[$key]['read'] = true;
            }
        }


        $this->config->saveConfig(['notifications' => json_encode($notifications)]);

        acym_sendAjaxResponse('', []);
    }

    public function addNotification(): void
    {
        wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');

        $message = acym_getVar('string', 'message');
        $level = acym_getVar('string', 'level');

        if (empty($message) || empty($level)) {
            acym_sendAjaxResponse(acym_translation('ACYM_ERROR'), [], false);
        }

        $headerHelper = new HeaderHelper();

        $newNotification = new \stdClass();
        $newNotification->message = $message;
        $newNotification->level = $level;
        $newNotification->read = false;
        $newNotification->date = time();

        $headerHelper->addNotification($newNotification);

        ob_start();
        $headerHelper->displayNotificationCenter();
        $notificationCenter = ob_get_clean();

        acym_sendAjaxResponse('', ['notificationCenter' => $notificationCenter]);
    }

    private function loadSurveyAnswers(array &$data): void
    {
        $surveyTexts = $this->config->get('unsub_survey', '{}');
        $data['surveyAnswers'] = json_decode($surveyTexts, true);
    }
}

```
