?? GreyFile — Mystic File Browser

Current path: home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Admin/Handlers/



?? Go up: /home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Admin

?? Viewing: Email_Template_Handler.php

<?php

namespace KS_PAC_DCFH\Admin\Handlers;

class Email_Template_Handler
{
    private static $_instance;

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

        return self::$_instance;
    }

    public static function set_template_id($string): string
    {
        return '_pwh_dcfh_email_tpl_'.sanitize_key($string);
    }

    public static function is_template_exist($option_name): bool
    {
        global $wpdb;
        $result = (int)$wpdb->get_var($wpdb->prepare("SELECT COUNT(1) FROM $wpdb->options WHERE option_name LIKE %s ", $option_name)); // db call ok; no-cache ok

        return $result > 0 && !is_wp_error($result);
    }

    public static function get_templates()
    {
        $key = 'dcfh_tpl_list_transient';
        $cached_data = get_transient($key);
        if (false !== $cached_data) {

            return $cached_data;
        }
        global $wpdb;
        $results = $wpdb->get_results($wpdb->prepare("SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE %s", '%_pwh_dcfh_email_tpl_%')); // phpcs:ignore
        $cached_data = [];
        foreach ($results as $row) {
            $options = maybe_unserialize($row->option_value);
            if ($options !== false) {
                $cached_data[$row->option_name] = $options;
            }
        }
        array_multisort(
            array_map('strtotime', array_column($cached_data, 'created_at')),
            SORT_DESC,
            $cached_data
        );
        set_transient($key, $cached_data, MONTH_IN_SECONDS);

        return $cached_data;
    }

    public static function get_template_type_label($label)
    {
        $templates = ks_pac_dcfh_constant()::get_templates_types();
        if ('' !== $label && isset($templates[$label])) {
            return $templates[$label];
        }

        return $label;
    }
}


??

??