Current path: home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Admin/Pages/
?? Go up: /home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Admin
<?php
namespace KS_PAC_DCFH\Admin\Pages;
if (!defined('ABSPATH')) {
exit;
}
class Page_Epanel_Settings
{
private $wp_mail_failed;
public function init(): void
{
add_action('admin_init', [$this, 'maybe_admin_hooks']);
add_action('admin_menu', [$this, 'maybe_add_menu_links']);
add_filter('et_epanel_tab_names', [$this, 'maybe_register_tab']);
add_filter('et_epanel_layout_data', [$this, 'maybe_register_content']);
}
public function maybe_add_menu_links(): void
{
global $submenu;
if (current_user_can('manage_options')) {
$menu_page = 'edit.php?post_type=pwh_dcfh';
// phpcs:disable
$submenu[$menu_page][] = [
__('SMTP Integration', 'divi-contact-form-helper'),
'edit_pages',
esc_url(admin_url('admin.php?page=et_divi_options#wrap-pwh-dcfh-epanel'))
];
$submenu[$menu_page][] = [
__('Automations', 'divi-contact-form-helper'),
'edit_pages',
esc_url(admin_url('admin.php?page=et_divi_options#wrap-pwh-dcfh-epanel'))
];
// phpcs:enable
}
}
public function maybe_admin_hooks(): void
{
add_action('wp_mail_failed', [$this, 'maybe_log_email_error']);
add_action('wp_ajax_process_smtp_test', [$this, 'maybe_process_smtp_test']);
add_action('wp_ajax_test_mail_delivery', [$this, 'maybe_proces_email_test']);
$this->process_admin_actions();
}
public function maybe_register_tab($tabs): array
{
return array_merge($tabs, ['pwh-dcfh-epanel' => __('Divi Contact Form Helper', 'divi-contact-form-helper')]);
}
public function maybe_register_content($options)
{
$options[] = [
'name' => 'wrap-pwh-dcfh-epanel',
'type' => 'contenttab-wrapstart',
];
$options[] = [
'type' => 'subnavtab-start',
];
$options[] = [
'name' => 'pwh-dcfh-tab-miscellaneous',
'type' => 'subnav-tab',
'desc' => __('Miscellaneous', 'divi-contact-form-helper')
];
$options[] = [
'name' => 'pwh-dcfh-tab-smtp',
'type' => 'subnav-tab',
'desc' => __('SMTP Integration', 'divi-contact-form-helper')
];
$options[] = [
'name' => 'pwh-dcfh-tab-spam-protection',
'type' => 'subnav-tab',
'desc' => __('Spam Protection', 'divi-contact-form-helper')
];
$options[] = [
'name' => 'pwh-dcfh-tab-cron-jobs',
'type' => 'subnav-tab',
'desc' => __('Automations', 'divi-contact-form-helper')
];
$options[] = [
'name' => 'pwh-dcfh-tab-labels',
'type' => 'subnav-tab',
'desc' => __('Custom Text', 'divi-contact-form-helper')
];
$options[] = [
'name' => 'pwh-dcfh-tab-user-permissions',
'type' => 'subnav-tab',
'desc' => __('User Permissions', 'divi-contact-form-helper')
];
$options[] = [
'name' => 'pwh-dcfh-tab-logs',
'type' => 'subnav-tab',
'desc' => __('Logs', 'divi-contact-form-helper')
];
$options[] = [
'type' => 'subnavtab-end',
];
$options = $this->misc_content($options);
$options = $this->smtp_content($options);
$options = $this->spam_protection_content($options);
$options = $this->cronjobs_content($options);
$options = $this->custom_text_content($options);
$options = $this->permissions_content($options);
$options = $this->logs_content($options);
$options[] = [
'name' => 'wrap-pwh-dcfh-epanel',
'type' => 'contenttab-wrapend',
];
return $options;
}
private function misc_content($options)
{
$options[] = [
'name' => 'pwh-dcfh-tab-miscellaneous',
'type' => 'subcontent-start',
];
$options[] = [
'name' => __('Enable Contact Forms Stats', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_stats_enabled',
'type' => 'checkbox',
'desc' => __('Choose to show contact form data stats widget on admin dashboard.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('Enable Sent Email Logs', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_enable_sent_email_log',
'type' => 'checkbox',
'desc' => __('Choose to log email sent history to submitter from send email page.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('Enable Clone Logs', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_enable_clone_log',
'type' => 'checkbox',
'desc' => __('Choose to log clone history of contact form data to other post types.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('Remove Plugin Data When Uninstalled', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_delete_plugin_data',
'type' => 'checkbox',
'desc' => __('This setting will remove all plugin data and saved settings when you uninstall the plugin. Please use this setting carefully with the understanding that if you enable the setting you will lose all saved settings if you uninstall the plugin.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('Allowed MIME Types', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_custom_mimes_types',
'type' => 'textarea',
'desc' => __('Enter any MIME types that you want to enabled on your WordPress site.', 'divi-contact-form-helper'),
'std' => 'psd|image/vnd.adobe.photoshop,rar|application/x-rar',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Optional Entry List Columns', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_entry_list_columns',
'type' => 'text',
'desc' => __('Enter any field ID from the contact form(s) which will be added as additional columns in the list of entries. You can add multiple IDs as needed separated by commas.', 'divi-contact-form-helper'),
'std' => 'name',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Entries Date Format', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_entries_date_format',
'type' => 'text',
'desc' => __('Enter a custom date format for the contact form entries using your preferred PHP parameters.', 'divi-contact-form-helper'),
'std' => 'Y/m/d',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Entries Time Format', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_entries_time_format',
'type' => 'text',
'desc' => __('Enter a custom time format for the contact form entries using your preferred PHP parameters.', 'divi-contact-form-helper'),
'std' => 'h:i:sa',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Merge Tag Date Format', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_mergetag_date_format',
'type' => 'text',
'desc' => __('Enter a custom date format for the contact form message merge tags using your preferred PHP parameters.', 'divi-contact-form-helper'),
'std' => 'Y-m-d',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Merge Tag Time Format', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_mergetag_time_format',
'type' => 'text',
'desc' => __('Enter a custom time format for the contact form message merge tags using your preferred PHP parameters.', 'divi-contact-form-helper'),
'std' => 'h:i:sa',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('All Fields Merge Tag Behavior', 'divi-contact-form-helper'),
'desc' => __('Choose whether the %%dcfh_all_fields%% merge tag should show all form field labels in the message even for fields with no value entered by the user, or if it should only show form fields that have a value entered.', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_all_fields_merge_tag_behavior',
'type' => 'select',
'options' => [
'show_all' => __('Show All Form Fields', 'divi-contact-form-helper'),
'show_filled_only' => __('Only Show Form Fields With Value', 'divi-contact-form-helper'),
],
'et_save_values' => true,
'std' => 'show_all',
];
$options[] = [
'name' => __('Clear ICS Cached Data', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_clear_ics_cache',
'type' => 'callback_function',
'function_name' => function () {
$cache_clear_url = add_query_arg([
'page' => 'et_divi_options',
'action' => 'clear_ics_cache',
'_wpnonce' => wp_create_nonce(__FILE__),
], admin_url());
?>
<a href="<?php echo esc_url($cache_clear_url); ?>" class="et-button">
<?php esc_html_e('Clear Cache', 'divi-contact-form-helper'); ?>
</a>
<?php
},
'desc' => '',
];
$options[] = [
'name' => __('Load Resources From CDN', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_load_resources_from_cdn',
'type' => 'checkbox',
'desc' => __('This setting will load external required libraries from CDN or directlry from plugin directory', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => 'pwh-dcfh-tab-miscellaneous',
'type' => 'subcontent-end',
];
return $options;
}
private function smtp_content($options)
{
$options[] = [
'name' => 'pwh-dcfh-tab-smtp',
'type' => 'subcontent-start',
];
$options[] = [
'name' => __('Enable SMTP Settings', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_enabled',
'type' => 'checkbox2',
'desc' => __('Choose to use SMTP configuration when sending emails WordPress must utilise a legitimate SMTP provider.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('SMTP Host', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_host',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('This is the SMTP host address provided by your hosting company.', 'divi-contact-form-helper'),
'std' => '',
];
$options[] = [
'name' => __('SMTP From Email', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_from_email',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('This is the email address which will be used to send all WordPress emails.', 'divi-contact-form-helper'),
'std' => get_bloginfo('admin_email'),
];
$options[] = [
'name' => __('SMTP From Name', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_from_name',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('This name will be used to send emails. We recommend using your website’s title as from name.', 'divi-contact-form-helper'),
'std' => get_bloginfo('name'),
];
$options[] = [
'name' => __('Encryption', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_encryption',
'type' => 'select',
'options' => [
'none' => __('None', 'divi-contact-form-helper'),
'ssl' => __('SSL', 'divi-contact-form-helper'),
'tls' => __('TLS', 'divi-contact-form-helper'),
],
'et_save_values' => true,
'desc' => __('The encryption method used by your mail server to send emails. Usually it is TLS.', 'divi-contact-form-helper'),
'std' => 'none',
];
$options[] = [
'name' => __('SMTP Port', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_port',
'type' => 'text',
'validation_type' => 'number',
'desc' => __('This is the port used by outgoing mail server.', 'divi-contact-form-helper'),
'std' => '25',
];
$options[] = [
'name' => __('Auto TLS', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_autotls',
'type' => 'checkbox2',
'desc' => __('By default, TLS encryption is automatically used if the server supports it (recommended). In some cases, due to server misconfigurations, this can cause issues and may need to be disabled.',
'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('Authentication', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_authentication',
'type' => 'checkbox2',
'desc' => __('Email senders (clients) must have permission to use the email server in order to use SMTP authentication. Outgoing messages can only be sent by authorised users.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('SMTP Username', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_username',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('This is usually the email address you are using to send emails.', 'divi-contact-form-helper'),
'std' => '',
];
$options[] = [
'name' => __('SMTP Password', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_smtp_password',
'type' => 'password',
'validation_type' => 'nohtml',
'desc' => __('This is the password for the email account you are using to send emails.', 'divi-contact-form-helper'),
'std' => '',
];
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_smtp_test',
'type' => 'callback_function',
'function_name' => function () {
?>
<button type="button" id="pwh-dcfh-smtp-button" class="et-button pwh-dcfh-smtp-button">
<?php esc_html_e('Check SMTP Integration Working', 'divi-contact-form-helper'); ?>
</button><p id="pwh-dcfh-smtp-response" class="pwh-dcfh-smtp-response"></p>
<?php
},
'desc' => '',
];
$options[] = [
'name' => __('Test Email Sending', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_test_mail_delivery',
'type' => 'callback_function',
'function_name' => function () {
?>
<div id="pwh-dcfh-test-mail-container" class="pwh-dcfh-test-mail-container">
<hr>
<p><?php esc_html_e('If you\'re uncertain if your website is properly sending emails, you can verify it using our built-in email sending test tool. Simply enter your email address in the field below and click "Send Email." If the default email sending functionality of your site is working correctly, you will receive a test email in your inbox!', 'divi-contact-form-helper'); ?></p>
<p><?php esc_html_e('Please note that while this test verifies basic functionality, it\'s essential to configure SMTP settings to ensure consistent email delivery. Unlike the test email, which is sent via "wp_mail" and uses plan text and is not associated with SMTP, emails from contact forms usually contain more advanced input values, header information, or attachments. It\'s important to understand that mail servers enforce their own security protocols, making SMTP crucial for reliable email delivery and gaining approval from mail servers. Don\'t forget to set up SMTP for a dedicated server to guarantee optimal mail delivery."Send Email." If the default email sending functionality of your site is working correctly, you will receive a test email in your inbox!', 'divi-contact-form-helper'); ?></p>
<input title="<?php esc_html_e('Email Address', 'divi-contact-form-helper'); ?>" type="email" name="email_address" placeholder="<?php esc_attr_e('Email Address', 'divi-contact-form-helper'); ?>">
<button type="button" id="phw_dcfh_test_mail_btn" class="et-button">
<?php esc_html_e('Send Email', 'divi-contact-form-helper'); ?>
</button>
<p class="mail_delivery_log"></p>
</div>
<?php
},
'desc' => '',
];
$options[] = [
'name' => 'pwh-dcfh-tab-smtp',
'type' => 'subcontent-end',
];
return $options;
}
private function spam_protection_content($options)
{
$options[] = [
'name' => 'pwh-dcfh-tab-spam-protection',
'type' => 'subcontent-start',
];
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_1',
'type' => 'callback_function',
'function_name' => function () {
echo sprintf('<h1>%s</h1>', __('Blacklist Settings', 'divi-contact-form-helper')); // phpcs:ignore
},
'desc' => '',
];
$options[] = [
'name' => __('Blacklisted Email Addresses', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_blacklisted_emails',
'type' => 'textarea',
'desc' => __('Enter specific email addresses to ignore form submissions that include these addresses. Separate multiple email addresses with a comma.', 'divi-contact-form-helper'),
'std' => '',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Blacklisted Email Address Domains', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_blacklisted_email_domains',
'type' => 'textarea',
'desc' => __('Enter specific email domains (e.g., @domain.com) to ignore form submissions from email addresses using these domains. Separate multiple domains with a comma.', 'divi-contact-form-helper'),
'std' => '',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Blacklisted Keywords', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_blacklisted_keywords',
'type' => 'textarea',
'desc' => __('Enter keywords to ignore form submissions that include any of these words in the email address, subject, or message text. Separate multiple keywords with a comma.', 'divi-contact-form-helper'),
'std' => '',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_2',
'type' => 'callback_function',
'function_name' => function () {
echo sprintf('<h1>%s</h1>', __('Google reCAPTCHA V2 Settings', 'divi-contact-form-helper')); // phpcs:ignore
},
'desc' => '',
];
$options[] = [
'name' => __('Google reCAPTCHA V2 Site Key', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_googlerecaptcha_v2_sitekey',
'type' => 'password',
'desc' => __('Enter your Google reCAPTCHA V2 Site Key to integrate with this site. Remember to enable the setting in the Contact Form module to activate Google reCAPTCHA V2 as needed.', 'divi-contact-form-helper'),// TODO ADD IT
'std' => '',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Google reCAPTCHA V2 Secret Key', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_googlerecaptcha_v2_secretkey',
'type' => 'password',
'desc' => __('Enter your Google reCAPTCHA V2 Secret Key to integrate with this site. Remember to enable the setting in the Contact Form module to activate Google reCAPTCHA V2 as needed.', 'divi-contact-form-helper'),
'std' => '',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Completely Disable Google reCAPTCHA V3', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_disable_google_recaptcha',
'type' => 'checkbox2',
'desc' => __('Enable this setting to completely prevent Google reCAPTCHA from loading Google fonts on the site. This is necessary for GDPR compliance even if you have the invisible Google reCAPTCHA V3 option disabled in the Divi Contact Form module.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_3',
'type' => 'callback_function',
'function_name' => function () {
echo sprintf('<h1>%s</h1>', __('Cloudflare Turnstile Settings', 'divi-contact-form-helper')); // phpcs:ignore
},
'desc' => '',
];
$options[] = [
'name' => __('Turnstile Site Key', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_turnstile_sitekey',
'type' => 'password',
'desc' => __('Enter your Cloudflare Turnstile Site Key to integrate with this site. Remember to enable the setting in the Contact Form module to activate Cloudflare Turnstile as needed.', 'divi-contact-form-helper'),
'std' => '',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => __('Turnstile Secret Key', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_turnstile_secretkey',
'type' => 'password',
'desc' => __('Enter your Cloudflare Turnstile Secret Key to integrate with this site. Remember to enable the setting in the Contact Form module to activate Cloudflare Turnstile as needed.', 'divi-contact-form-helper'),
'std' => '',
'validation_type' => 'nohtml'
];
$options[] = [
'name' => 'pwh-dcfh-tab-spam-protection',
'type' => 'subcontent-end',
];
return $options;
}
private function cronjobs_content($options)
{
$messages = get_option('pwh_dcfh_entries_auto_backup_status');
$options[] = [
'name' => 'pwh-dcfh-tab-cron-jobs',
'type' => 'subcontent-start',
];
$options[] = [
'name' => __('Auto Entries Backup', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_backup_enabled',
'type' => 'checkbox2',
'desc' => __('Choose to create an automatic backup of your contact form data.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('Backup Email Address', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_backup_email',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter the email address where you want to receive the auto backup file. The default is the site administrator email address.', 'divi-contact-form-helper'),
'std' => get_bloginfo('admin_email'),
];
$options[] = [
'name' => __('Backup Schedule', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_backup_schedule',
'type' => 'select',
'options' => [
'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'),
],
'et_save_values' => true,
'desc' => __('Select the desired frequency schedule for the auto backup.', 'divi-contact-form-helper'),
'std' => 'weekly',
];
if (!empty($messages)) {
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_1',
'type' => 'callback_function',
'function_name' => function () use ($messages) {
$status = $messages['sent'] ? __('Sent', 'divi-contact-form-helper') : __('Failed', 'divi-contact-form-helper');
$output = '<h1>'.__('Entries Backup Status', 'divi-contact-form-helper').'</h1>';
$output .= '<ul style="display: flex !important; flex-direction: column;">';
$output .= '<li><b>'.__('Status:', 'divi-contact-form-helper').'</b> '.$status.'</li>';
$output .= '<li><b>'.__('Date:', 'divi-contact-form-helper').'</b> '.date_i18n(get_option('date_format').' '.get_option('time_format'), $messages['datetime']).'</li>';
$output .= '<li><b>'.__('Details:', 'divi-contact-form-helper').'</b> '.esc_html($messages['message']).'</li>';
$output .= '</ul>';
echo wp_kses_post($output);
},
'desc' => '',
];
}
$options[] = [
'name' => __('Auto Delete Entries', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_delete_entries_enabled',
'type' => 'checkbox2',
'desc' => __('Choose to automatically delete the contact form entries after a specific number of days.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => __('Delete Entries Type', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_delete_entries_status',
'type' => 'checkbox_list',
'usefor' => 'custom',
'index' => -1,
'desc' => __('Choose which type of entries should be automatically deleted after the selected number of days.', 'divi-contact-form-helper'),
'options' => [
'published' => __('Read', 'divi-contact-form-helper'),
'draft' => __('Unread', 'divi-contact-form-helper'),
'trash' => __('Trash', 'divi-contact-form-helper'),
],
'default' => ['published' => 'on', 'trash' => 'on'],
'validation_type' => 'on_off_array',
'et_save_values' => true,
];
$options[] = [
'name' => __('Delete Entries After Number Of Days', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_delete_entries_schedule',
'type' => 'text',
'validation_type' => 'number',
'desc' => __('Enter the number of days after the entries are received to when they should be automatically deleted.', 'divi-contact-form-helper'),
'std' => '',
];
$options[] = [
'name' => 'pwh-dcfh-tab-cron-jobs',
'type' => 'subcontent-end',
];
return $options;
}
private function custom_text_content($options)
{
$options[] = [
'name' => 'pwh-dcfh-tab-labels',
'type' => 'subcontent-start',
];
$options[] = [
'name' => __('Enable Multilingual Languages', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_multilingual_enabled',
'type' => 'checkbox2',
'desc' => __('Enable this setting to hide the custom text fields and use the WordPress language files instead to translate any custom text added by our settings. ', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_1',
'type' => 'callback_function',
'function_name' => function () {
echo sprintf('<h1>%s</h1>', __('File Upload Custom Labels', 'divi-contact-form-helper')); // phpcs:ignore
},
'desc' => '',
];
$options[] = [
'name' => __('Upload File Button Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_file_upload_btn_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for upload file button.', 'divi-contact-form-helper'),
'std' => 'Choose Files',
];
$options[] = [
'name' => __('Accepted File Types Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_accepted_file_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for accepted file types.', 'divi-contact-form-helper'),
'std' => 'Accepted file types:',
];
$options[] = [
'name' => __('Max File Size Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_max_filesize_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for max file size.', 'divi-contact-form-helper'),
'std' => 'Max. file size:',
];
$options[] = [
'name' => __('No Files Chosen Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_chosen_file_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for no file chosen.', 'divi-contact-form-helper'),
'std' => 'No Files Chosen',
];
$options[] = [
'name' => __('Number Of Chosen Files Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_selected_files_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for selected files.', 'divi-contact-form-helper'),
'std' => '{chosen_files_count} file{_s_} selected',
];
$options[] = [
'name' => __('Uploading Files Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_uploading_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text while uploading files.', 'divi-contact-form-helper'),
'std' => '{percentage} uploaded your files, please wait for the system to continue.',
];
$options[] = [
'name' => __('File Already Attached Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_already_attached_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for files already attached.', 'divi-contact-form-helper'),
'std' => 'File {filename} has already attached. Please choose another file.',
];
$options[] = [
'name' => __('File Size Warning Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_allow_filesize_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for maximum allow file size.', 'divi-contact-form-helper'),
'std' => 'File {filename} not uploaded. Maximum file size {allowed_filesize}.',
];
$options[] = [
'name' => __('Number Of Allowed Files Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_x_files_allow_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for allow to upload only number of files.', 'divi-contact-form-helper'),
'std' => 'Only {allowed_files} files are allowed to upload.',
];
$options[] = [
'name' => __('Remove File Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_remove_file_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for remove file.', 'divi-contact-form-helper'),
'std' => 'Are you sure you want to remove {filename}?',
];
$options[] = [
'name' => __('Delete File Icon Hover Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_delete_file_icon_hover_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for delete file icon hover text.', 'divi-contact-form-helper'),
'std' => 'Remove an attachment',
];
$options[] = [
'name' => __('Not Allowed To Upload', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_security_reason_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for file type not allowed to upload.', 'divi-contact-form-helper'),
'std' => 'File {filename} has failed to upload. Sorry, this file type is not permitted for security reasons.',
];
$options[] = [
'name' => __('Filesize To Upload', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_allowedfilesize_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for max file size allowed to upload.', 'divi-contact-form-helper'),
'std' => 'File {filename} not uploaded. Maximum file size {filesize}',
];
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_2',
'type' => 'callback_function',
'function_name' => function () {
echo sprintf('<h1>%s</h1>', __('Signature Pad Custom Labels', 'divi-contact-form-helper')); // phpcs:ignore
},
'desc' => '',
];
$options[] = [
'name' => __('Empty Signature Pad Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_siganture_empty_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for empty signature pad alert message.', 'divi-contact-form-helper'),
'std' => 'The signature pad is empty. Please sign it and then save.',
];
$options[] = [
'name' => __('Before Save Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_siganture_before_save_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for save alert message.', 'divi-contact-form-helper'),
'std' => 'Are you sure you want to save the signature?',
];
$options[] = [
'name' => __('Save Message Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_siganture_save_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for save message.', 'divi-contact-form-helper'),
'std' => 'The signature has been saved successfully!',
];
$options[] = [
'name' => __('Delete Message Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_siganture_delete_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for delete message.', 'divi-contact-form-helper'),
'std' => 'The signature has been deleted successfully!',
];
$options[] = [
'name' => __('Save Button Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_siganture_save_btn_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for the save button.', 'divi-contact-form-helper'),
'std' => 'Save',
];
$options[] = [
'name' => __('Clear Button Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_siganture_clear_btn_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for the clear button.', 'divi-contact-form-helper'),
'std' => 'Clear',
];
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_2',
'type' => 'callback_function',
'function_name' => function () {
echo sprintf('<h1>%s</h1>', __('Contact Form Module Custom Labels', 'divi-contact-form-helper')); // phpcs:ignore
},
'desc' => '',
];
$options[] = [
'name' => __('Required Fields Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_fill_message_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for required field message.', 'divi-contact-form-helper'),
'std' => 'Please fill in the following fields:',
];
$options[] = [
'name' => __('Field Error Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_fix_message_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for the field error message.', 'divi-contact-form-helper'),
'std' => 'Please fix the following errors:',
];
$options[] = [
'name' => __('Required Captcha Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_required_captcha_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for required captcha message.', 'divi-contact-form-helper'),
'std' => 'Please complete the CAPTCHA.',
];
$options[] = [
'name' => __('Wrong Captcha Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_wrong_captcha_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for wrong captcha message.', 'divi-contact-form-helper'),
'std' => 'There was a problem with the captcha verification.',
];
$options[] = [
'name' => __('Invalid Email Text', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_invalid_email_text',
'type' => 'text',
'validation_type' => 'nohtml',
'desc' => __('Enter custom text for invalid email message.', 'divi-contact-form-helper'),
'std' => 'Please enter a valid email address.',
];
$options[] = [
'name' => 'pwh-dcfh-tab-labels',
'type' => 'subcontent-end',
];
return $options;
}
private function permissions_content($options)
{
$options[] = [
'name' => 'pwh-dcfh-tab-user-permissions',
'type' => 'subcontent-start',
];
$roles = get_editable_roles();
$excluded_roles = ['administrator', 'subscriber'];
foreach ($roles as $key => $role) {
// Skip excluded roles
if (in_array($key, $excluded_roles, true)) {
continue;
}
$options[] = [
'type' => 'checkbox_list',
'id' => "pwh_dcfh_permission_$key",
'name' => sprintf('%s Permissions', $role['name']),
'desc' => __('Set specific permissions for each user role to manage access to contact form entries, take action on entries, and export entries to CSV.', 'divi-contact-form-helper'),
'index' => -1,
'options' => ['access_entries' => __('Access Entries', 'divi-contact-form-helper'), 'entry_actions' => __('Entry Actions', 'divi-contact-form-helper'), 'export_csv' => __('Export CSV', 'divi-contact-form-helper')],
'default' => ['post' => 'on'],
'validation_type' => 'on_off_array',
'et_save_values' => true,
'usefor' => 'custom',
];
}
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_1',
'type' => 'callback_function',
'function_name' => function () {
$sections = [
[
'title' => 'Access Entries Capabilities',
'items' => ['View Entries', 'Read Entry', 'View Form Details']
],
[
'title' => 'Entry Actions Capabilities',
'items' => [
'Delete Entry Permanently', 'Move Entry To Trash', 'Mark Entry as Read', 'Mark Entry as Unread', 'Mark As Spam',
'Reply/Send Email Of Entry', 'Create Email Template', 'View Email Templates', 'Create Post From Entry'
]
],
[
'title' => 'Export CSV Capabilities',
'items' => ['Export Entries As CSV']
]
];
foreach ($sections as $section) {
printf('<b>%s</b>', esc_html($section['title']));
echo '<ul>';
foreach ($section['items'] as $item) {
printf('<li>%s</li>', esc_html($item));
}
echo '</ul>';
}
},
'desc' => '',
];
$options[] = [
'name' => 'pwh-dcfh-tab-user-permissions',
'type' => 'subcontent-end',
];
return $options;
}
private function logs_content($options)
{
$options[] = [
'name' => 'pwh-dcfh-tab-logs',
'type' => 'subcontent-start',
];
$options[] = [
'name' => __('Enable Contact Form Entry Logging', 'divi-contact-form-helper'),
'id' => 'pwh_dcfh_logs_enabled',
'type' => 'checkbox',
'desc' => __('Enable this setting to start logging all entries submitted through Divi Contact Forms on your site. The logs will capture key form data, such as names, contact information, diagnosis details, and messages. Each log entry is timestamped and securely stored. These logs are useful for troubleshooting, reviewing submissions, monitoring form performance, and retrieving user data. Once logging is enabled, all form entries will be recorded and displayed. You can download all entries or copy the most recent log entries as needed.', 'divi-contact-form-helper'),
'std' => 'off',
];
$options[] = [
'name' => '',
'id' => 'pwh_dcfh_divider_1',
'type' => 'callback_function',
'function_name' => function () {
$et_ = et_();
$file_path = realpath(WP_CONTENT_DIR.'/divi_contact_form.log');
$max_size = 5 * 1024 * 1024; // 5MB in bytes
if ($et_->WPFS()->exists($file_path) && $et_->WPFS()->is_readable($file_path)) {
$bytes = $et_->WPFS()->size($file_path);
$units = ['bytes', 'KB', 'MB', 'GB', 'TB'];
$power = $bytes > 0 ? floor(log($bytes, 1024)) : 0;
$file_size = round($bytes / (1024 ** $power), 2).' '.$units[$power];
if ($bytes > $max_size) {
echo '<p style="font-size: 15px;color: #B82132;font-weight:600;padding-bottom: 10px;">'.esc_html__('The file size exceeds the 5MB limit for direct download. This is likely due to the server\'s settings for file size and execution time. To ensure smooth processing, we recommend downloading the file directly. Thank you for your understanding!', 'divi-contact-form-helper').'</p>';
} else {
$file_content = $et_->WPFS()->get_contents($file_path);
$log_content = '';
$lines = explode("\n", $file_content);
$log_count = 1;
foreach ($lines as $line) {
if (preg_match('/^\[(.*?)]/', $line, $matches)) {
$timestamp = date_i18n('Y-m-d H:i:sa', strtotime($matches[1]));
$log_content .= "\n------ Entry#$log_count Timestamp: $timestamp ------\n";
$log_count++;
} elseif (trim($line) === '') {
continue;
} else {
$log_content .= "$line\n";
}
}
if (!empty($log_content)) {
printf('<textarea id="et_logs_display" class="et__logs_display">%s</textarea>', esc_html(trim($log_content)));
}
}
echo '<div class="et__logs_meta">';
if ($bytes > $max_size) {
printf(
'<a href="%s" onclick="return confirm(\'%s\');">%s</a>',
esc_url(add_query_arg([
'page' => 'et_divi_options',
'action' => 'download_delete_log',
'_wpnonce' => wp_create_nonce(__FILE__),
], admin_url())),
esc_js(__('Warning: The log file will be deleted after it is downloaded. This action cannot be undone. Do you want to proceed?', 'divi-contact-form-helper')),
sprintf(__('Download File & Delete File (%s)', 'divi-contact-form-helper'), esc_html($file_size))
);
} else {
// Download Log File Button
printf(
'<a href="%s" download>%s</a>',
esc_url(content_url('divi_contact_form.log')),
sprintf(__('Download Log File (%s)', 'divi-contact-form-helper'), esc_html($file_size))
);
// Copy Recent Log Entries Button
printf(
'<a href="#" class="copy_debug_log">%s</a>',
esc_html__('Copy Logs', 'divi-contact-form-helper')
);
}
// Delete Log File Button
printf(
'<a href="%s" onclick="return confirm(\'%s\');">%s</a>',
esc_url(add_query_arg([
'page' => 'et_divi_options',
'action' => 'delete_log_file',
'_wpnonce' => wp_create_nonce(__FILE__),
], admin_url())),
esc_js(__('Are you sure you want to delete the log file? This action cannot be undone.', 'divi-contact-form-helper')),
esc_html__('Delete Log File', 'divi-contact-form-helper')
);
echo '</div>';
} else {
printf(
'<p>%s</p>',
esc_html__('No contact form entry logs found.', 'divi-contact-form-helper')
);
}
},
'desc' => '',
];
$options[] = [
'name' => 'pwh-dcfh-tab-logs',
'type' => 'subcontent-end',
];
return $options;
}
public function maybe_log_email_error($wp_error): void
{
if (isset($wp_error->errors['wp_mail_failed'])) {
$args = $wp_error->get_error_data('wp_mail_failed');
if (isset($args['subject'])) {
$subject = $args['subject'];
if (
strpos($subject, 'SMTP Integrated') === 0 ||
strpos($subject, 'Email Sending Test By Divi Contact Form Helper') === 0
) {
$this->wp_mail_failed = $wp_error->get_error_message('wp_mail_failed');
}
}
}
}
public function maybe_process_smtp_test(): void
{
if (!empty($_REQUEST['_wpnonce'])) {
$_wpnonce = sanitize_text_field($_REQUEST['_wpnonce']);
if (wp_verify_nonce($_wpnonce, 'admin-ajax-nonce')) {
$smtp_settings = get_option('et_divi');
if (isset($smtp_settings['pwh_dcfh_smtp_enabled'])) {
$errors = [];
if ('on' !== trim($smtp_settings['pwh_dcfh_smtp_enabled'])) {
$errors[] = __('Please save changes.', 'divi-contact-form-helper');
}
if ('' === trim($smtp_settings['pwh_dcfh_smtp_host'])) {
$errors[] = __('SMTP Host required.', 'divi-contact-form-helper');
}
if (('on' === trim($smtp_settings['pwh_dcfh_smtp_authentication'])) && '' === trim($smtp_settings['pwh_dcfh_smtp_username']) && '' === trim($smtp_settings['pwh_dcfh_smtp_password'])) {
$errors[] = __('SMTP Username & Password required.', 'divi-contact-form-helper');
}
if (!empty($errors)) {
$smtp_settings['pwh_dcfh_smtp_enabled'] = false;
update_option('et_divi', $smtp_settings);
wp_send_json_error(implode('<br>', $errors));
}
if (empty($errors)) {
$admin_email = get_bloginfo('admin_email');
$blog_name = get_bloginfo('name');
if (wp_mail($admin_email, __('SMTP Integrated', 'divi-contact-form-helper'), sprintf(__('Congrats, SMTP has been integrated on your site %s successfully!', 'divi-contact-form-helper'), $blog_name))) {
wp_send_json_success(sprintf(__('Test email is sent at %s successfully! Please check your inbox to make sure it was delivered.', 'divi-contact-form-helper'), $admin_email));
} else {
$failed_reason = $this->wp_mail_failed;
if (!empty($failed_reason)) {
wp_send_json_error(make_clickable($failed_reason));
}
}
}
}
}
}
}
public function maybe_proces_email_test(): void
{
// Check if nonce is set and verified
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['nonce']), 'admin-ajax-nonce')) {
wp_send_json_error([
'errorCode' => 'unknown',
'message' => __('Security check failed. Please refresh and try again.', 'divi-contact-form-helper'),
], 400);
}
// Get email address from POST data
$to = isset($_POST['email_address']) ? sanitize_email($_POST['email_address']) : '';
// Validate email address
if (empty($to)) {
wp_send_json_error(__('Email Address is required.', 'divi-contact-form-helper'));
} elseif (!is_email($to)) {
wp_send_json_error(__('A valid email address must be given.', 'divi-contact-form-helper'));
}
// Email subject
$subject = esc_html('Email Sending Test By Divi Contact Form Helper');
// Email content
$message = "This is a test message sent by Divi Contact Form Helper to determine if email sending is configured properly on your WordPress website if you received this email in your inbox, congratulations, the mail sending function is working!";
if (wp_mail($to, $subject, $message)) {
wp_send_json_success(sprintf(__('Test email is sent at %s successfully! Please check your inbox to make sure it was delivered.', 'divi-contact-form-helper'), $to));
} else {
wp_send_json_error($this->wp_mail_failed);
}
}
private function process_admin_actions(): void
{
if (isset($_GET['action'], $_GET['_wpnonce'], $_GET['page']) && 'et_divi_options' === $_GET['page']) {
$action = sanitize_text_field($_GET['action']);
$nonce = sanitize_text_field($_GET['_wpnonce']);
$et_ = et_();
if ($action === 'clear_ics_cache' && wp_verify_nonce($nonce, __FILE__)) {
$transients = [
'calendar.google.com',
'outlook.live.com',
];
foreach ($transients as $transient) {
delete_transient(md5($transient));
}
wp_safe_redirect(remove_query_arg(['action', '_wpnonce']));
exit;
}
if ($action === 'delete_log_file' && wp_verify_nonce($nonce, __FILE__)) {
$file_path = realpath(WP_CONTENT_DIR.'/divi_contact_form.log');
$et_->WPFS()->delete($file_path);
wp_safe_redirect(remove_query_arg(['action', '_wpnonce']));
exit;
}
if ($action === 'download_delete_log' && wp_verify_nonce($nonce, __FILE__)) {
$file_path = realpath(WP_CONTENT_DIR.'/divi_contact_form.log');
$new_filename = "divi_contact_form_".gmdate('Y-m-d_H-i-s').".log";
if ($et_->WPFS()->exists($file_path)) {
$file_path = realpath(WP_CONTENT_DIR.'/divi_contact_form.log');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$new_filename.'"');
header('Content-Length: '.filesize($file_path));
readfile($file_path); // phpcs:ignore
$et_->WPFS()->delete($file_path);
wp_safe_redirect(remove_query_arg(['action', '_wpnonce']));
exit;
}
}
}
}
}