Current path: home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Helpers/
?? Go up: /home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app
<?php
namespace KS_PAC_DCFH\Helpers;
use WP_User;
if (!defined('ABSPATH')) {
exit;
}
class WP_Helpers
{
private static $_instance;
public static function instance(): self
{
if (self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}
public static function get_theme_option_name(): string
{
$theme_info = wp_get_theme();
$active_theme = is_child_theme() ? $theme_info->parent()->get('Name') : $theme_info->get('Name');
return 'divi' === strtolower($active_theme) ? 'et_divi' : 'et_extra';
}
public static function is_divi_4131_or_above(): bool
{
$theme = wp_get_theme();
if (!$theme) {
return false;
}
$version = $theme->parent() ? $theme->parent()->get('Version') : $theme->get('Version');
if (version_compare($version, '4.13.1', '>=')) {
return true;
}
return false;
}
public static function get_divi_setting_slug(): string
{
$slug = 'et_divi_options';
if (is_plugin_active('divi-ghoster/divi-ghoster.php')) {
$options = get_option('agsdg_settings');
$slug = 'et_'.$options['theme_slug'].'_options';
}
return $slug;
}
public static function get_author_name($user_id = null): string
{
$user_info = $user_id ? new WP_User($user_id) : wp_get_current_user();
if (!($user_info instanceof WP_User)) {
return 'Unknown Author';
}
$author_name = '';
if (!empty($user_info->first_name)) {
$author_name .= $user_info->first_name;
}
if (!empty($user_info->last_name)) {
if ($author_name) {
$author_name .= ' ';
}
$author_name .= $user_info->last_name;
}
if (empty($author_name)) {
$author_name = $user_info->display_name;
}
return $author_name;
}
public static function get_submitter_name($post_id): string
{
$post_author = __('Visitor', 'divi-contact-form-helper');
if ($post_id > 0) {
$user_data = get_user_by('ID', $post_id);
} else {
$user_data = ks_pac_dcfh_post_meta()::get_contact_email_meta_value($post_id);
}
if (isset($user_data->ID)) {
$post_author = self::get_author_name($user_data->ID);
}
return $post_author;
}
public static function get_pages(): array
{
$pages_list = wp_list_pluck(get_posts(['post_type' => 'page', 'numberposts' => -1]), 'post_title', 'ID');
$pages = array_replace([__('Please Select A Page', 'divi-contact-form-helper')], $pages_list);
if (!empty($pages)) {
return $pages;
}
return [];
}
public static function get_post_types(): array
{
$posts_types = get_post_types(['public' => true]);
unset($posts_types['attachment']);
return $posts_types;
}
public static function datetime($datetime): string
{
if (empty($datetime)) {
return '';
}
$timestamp = strtotime($datetime);
$date_format = et_get_option('pwh_dcfh_entries_date_format');
$date_format = empty($date_format) ? get_option('date_format') : $date_format;
$time_format = et_get_option('pwh_dcfh_entries_time_format');
$date_output = date_i18n($date_format, $timestamp);
if (empty($time_format)) {
return sprintf('%s', $date_output);
}
$time_output = date_i18n($time_format, $timestamp);
return sprintf(__('%1$s at %2$s', 'divi-contact-form-helper'), $date_output, $time_output);
}
public static function get_image_mimes(): array
{
$mimes = wp_get_mime_types();
$image_mimes = [];
foreach ($mimes as $mime) {
if (strpos($mime, 'image/') !== false) {
$image_mimes[] = $mime;
}
}
return $image_mimes;
}
public static function get_get_schedules(): array
{
$schedules = [];
$labels = [
'hourly' => __('Every Hour', 'divi-contact-form-helper'),
'twicedaily' => __('Every 12 Hours', 'divi-contact-form-helper'),
'daily' => __('Every Day', 'divi-contact-form-helper'),
'weekly' => __('Every Week', 'divi-contact-form-helper'),
'monthly' => __('Every Month', 'divi-contact-form-helper'),
];
$wp_schedules = wp_get_schedules();
// Sort Schedules With Intervals DESC
foreach ($wp_schedules as $k => $va) {
$sort_schedules[$k] = $va['interval'];
}
array_multisort($sort_schedules, SORT_DESC, $wp_schedules);
// Get Required Data Fron Schedules
foreach ($wp_schedules as $k => $v) {
if (in_array($k, ['monthly', 'hourly', 'twicedaily', 'daily', 'weekly'], true)) {
$schedules[$k] = $labels[$k] ?? $v['display'];
}
}
return $schedules;
}
public static function get_wp_locale()
{
$locale_arr = explode('_', get_locale());
return $locale_arr[0] ?? 'en';
}
public static function get_wp_allowed_mime_types(): array
{
$allowed_mime_type = [];
foreach (get_allowed_mime_types() as $key => $value) {
if ('css' === $key) {
$allowed_mime_type[$key] = $value;
$allowed_mime_type['htm|html'] = 'text/html';
} elseif ('rtf' === $key) {
$allowed_mime_type[$key] = $value;
$allowed_mime_type['js'] = 'application/javascript';
} else {
$allowed_mime_type[$key] = $value;
}
}
return $allowed_mime_type;
}
}