?? GreyFile — Mystic File Browser

Current path: home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Helpers/



?? Go up: /home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server

?? Viewing: AdminAlert.php

<?php

namespace KS_PAC_DCFH\Helpers;

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

class AdminAlert
{
    private static $_instance;

    public const NOTICE_FIELD = '_dcfh_temp_admin_notice';

    public static function instance(): self
    {
        if (self::$_instance === null) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    public static function show_message(): void
    {
        $options = get_option(self::NOTICE_FIELD);
        if (!empty($options)) {
            foreach ($options as $type => $messages) {
                $messages = array_filter($messages, 'strlen');
                $messages = array_values($messages);
                echo '<div class="notice ' . esc_attr( $type ) . ' is-dismissible">';
                if (!empty($messages[0]) && count($messages) === 1) {
                    echo sprintf('<p>%s</p>', esc_html($messages[0]));
                } elseif (count($messages) > 1) {
                    echo '<ul>';
                    foreach ($messages as $message) {
                        echo sprintf('<li>%s</li>', esc_html($message));
                    }
                    echo '</ul>';
                }
                echo '</div>';
            }
            delete_option(self::NOTICE_FIELD);
        }
    }

    public static function success(string $message): void
    {
        self::save($message, 'notice-success');
    }

    public static function error(string $message): void
    {
        self::save($message, 'notice-error');
    }

    private static function save(string $message, string $notice_level): void
    {
        $options = get_option(self::NOTICE_FIELD);
        if (!is_array($options)) {
            $options = [];
        }
        $options[$notice_level][] = $message;
        update_option(self::NOTICE_FIELD, $options, 'no');
    }
}



??

??