Current path: home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Admin/Controllers/
?? Go up: /home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Admin
<?php
namespace KS_PAC_DCFH\Admin\Controllers;
use KS_PAC_DCFH\Admin\Dashboard\DashboardSettingsMigration;
use KS_PAC_DCFH\Admin\Setup\PluginActivation;
if (!defined('ABSPATH')) {
exit;
}
class CoreHooksManager
{
public function load(): void
{
add_action('admin_init', [$this, 'maybe_admin_init']);
add_action('wp_mail_failed', [$this, 'maybe_log_email_error']);
add_action('template_redirect', [$this, 'maybe_create_tmp_folder']);
add_action('after_switch_theme', [$this, 'maybe_on_theme_switch']);
}
public function maybe_admin_init(): void
{
if (is_admin()) {
$_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; // phpcs:ignore WordPress.Security.NonceVerification
if (in_array($_page, [
'create_post',
'create_email_template',
'send_email',
'export_as_csv'
], true)) {
ob_start();
}
}
}
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 (str_contains($subject, 'SMTP Configuration Test By Divi Contact Form Helper')) {
$cached_error = get_transient('smtp_integrated_error_message');
if (!$cached_error) {
$error_message = $wp_error->get_error_message('wp_mail_failed');
set_transient('smtp_integrated_error_message', $error_message, 600);
}
}
if (str_contains($subject, 'Email Sending Test By Divi Contact Form Helper')) {
$cached_error = get_transient('email_test_error_message');
if (!$cached_error) {
$error_message = $wp_error->get_error_message('wp_mail_failed');
set_transient('email_test_error_message', $error_message, 600);
}
}
}
}
}
public function maybe_create_tmp_folder(): void
{
if (isset($_GET['dcfh_create_folder']) && sanitize_text_field($_GET['dcfh_create_folder']) === '1') { // phpcs:ignore WordPress.Security.NonceVerification
if (!is_user_logged_in() || !current_user_can('manage_options')) {
wp_die(esc_html__('Unauthorized.', 'divi-contact-form-helper'));
}
if (!isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field($_GET['_wpnonce']), 'create_folder')) {
wp_die(esc_html__('Security check failed.', 'divi-contact-form-helper'));
}
ks_pac_dcfh_app()->file_utils()::create_dir(path_join('pwh-dcfh-uploads', 'tmp'));
$redirect_to = isset($_GET['redirect_to']) ? esc_url_raw($_GET['redirect_to']) : home_url();
wp_safe_redirect($redirect_to);
exit;
}
}
public function maybe_on_theme_switch(): void
{
PluginActivation::ensure_divi_theme_active();
$migrator = new DashboardSettingsMigration();
$migrator->maybe_migrate();
}
}