Current path: home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Admin/Managers/
?? Go up: /home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Admin
<?php
namespace KS_PAC_DCFH\Admin\Managers;
if (!defined('ABSPATH')) {
exit;
}
class EmailTemplateManager
{
private static $_instance;
public static function instance(): self
{
if (self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}
public static function generate_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)); // phpcs:ignore
return $result > 0 && !is_wp_error($result);
}
public static function get_templates_list()
{
$cache_key = 'dcfh_tpl_list_transient';
$cached_data = wp_cache_get($cache_key, 'dcfh_cached');
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 WordPress.DB.DirectDatabaseQuery.DirectQuery
);
$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
);
wp_cache_set($cache_key, $cached_data, 'dcfh_cached', MONTH_IN_SECONDS);
return $cached_data;
}
public static function get_templates_types(): array
{
return [
'general' => __('General', 'divi-contact-form-helper'),
'admin' => __('Admin', 'divi-contact-form-helper'),
'confirmation' => __('Confirmation', 'divi-contact-form-helper'),
'reply_send' => __('Reply/Send Email', 'divi-contact-form-helper'),
'post_clone' => __('Post Clone', 'divi-contact-form-helper'),
];
}
public static function get_template_type_label($label)
{
$templates = self::get_templates_types();
if ('' !== $label && isset($templates[$label])) {
return $templates[$label];
}
return $label;
}
}