get_error_message()); // log_to_file("wp_ajax_rl_mailwarmer_check_domain_health - Error creating Domain Health Report: " . $report_post_id->get_error_message()); } wp_send_json_success($report_post_id); } catch (Exception $e) { wp_send_json_error($e->getMessage()); // log_to_file("wp_ajax_rl_mailwarmer_check_domain_health - EXCEPTION while creating Domain Health Report: " . $e->getMessage()); } }); add_action('wp_ajax_rl_mailwarmer_update_spf_record', function () { // Verify nonce if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'update_spf_record_nonce')) { wp_send_json_error(__('Invalid nonce', 'rl-mailwarmer')); } // Get input values $post_id = intval($_POST['post_id']); $host = sanitize_text_field($_POST['host']); $action = sanitize_text_field($_POST['action_type']); $all_policy = sanitize_text_field($_POST['all_policy']); $ttl = intval($_POST['ttl']); if (!$post_id || !$host || !$action) { wp_send_json_error(__('Missing required fields', 'rl-mailwarmer')); } // Call the update_spf_record function try { $result = RL_MailWarmer_Domain_Helper::update_spf_record($post_id, $host, $action, $all_policy, $ttl); if ($result) { wp_send_json_success(__('SPF record updated successfully.', 'rl-mailwarmer')); } else { wp_send_json_error(__('Failed to update SPF record.', 'rl-mailwarmer')); } } catch (Exception $e) { wp_send_json_error($e->getMessage()); } }); add_action('wp_ajax_rl_mailwarmer_update_dmarc_record', function () { if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'update_dmarc_record_nonce')) { wp_send_json_error(__('Invalid nonce', 'rl-mailwarmer')); } $post_id = intval($_POST['post_id']); if (!$post_id) { wp_send_json_error(__('Invalid post ID', 'rl-mailwarmer')); } $params = array_filter([ 'p' => sanitize_text_field($_POST['policy']), 'sp' => sanitize_text_field($_POST['sp']), 'pct' => intval($_POST['pct']), 'aspf' => sanitize_text_field($_POST['aspf']), 'adkim' => sanitize_text_field($_POST['adkim']), 'rua' => sanitize_email($_POST['rua']) ? 'mailto:' . sanitize_email($_POST['rua']) : null, 'ruf' => sanitize_email($_POST['ruf']) ? 'mailto:' . sanitize_email($_POST['ruf']) : null, 'fo' => sanitize_text_field($_POST['fo']), 'rf' => sanitize_text_field($_POST['rf']), 'ri' => intval($_POST['ri']), ]); try { $result = RL_MailWarmer_Domain_Helper::update_dmarc_record($post_id, $params); if ($result) { wp_send_json_success(__('DMARC record updated successfully.', 'rl-mailwarmer')); } else { wp_send_json_error(__('Failed to update DMARC record.', 'rl-mailwarmer')); } } catch (Exception $e) { wp_send_json_error($e->getMessage()); } }); add_action('wp_ajax_rl_mailwarmer_update_dkim_record', function () { // Verify nonce if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'update_dkim_record_nonce')) { wp_send_json_error(__('Invalid nonce', 'rl-mailwarmer')); } // Get input values $post_id = intval($_POST['post_id']); $selector = sanitize_text_field($_POST['selector']); $action = sanitize_text_field($_POST['action_type']); $value = sanitize_textarea_field($_POST['value']); $ttl = intval($_POST['ttl']); if (!$post_id || !$selector || !$action) { wp_send_json_error(__('Missing required fields', 'rl-mailwarmer')); } // Call the update_dkim_record function try { $result = RL_MailWarmer_Domain_Helper::update_dkim_record($post_id, $selector, $action, $value, $ttl); if ($result) { wp_send_json_success(__('DKIM record updated successfully.', 'rl-mailwarmer')); } else { wp_send_json_error(__('Failed to update DKIM record.', 'rl-mailwarmer')); } } catch (Exception $e) { wp_send_json_error($e->getMessage()); } }); add_action('wp_ajax_rl_mailwarmer_fix_dns_issues', function () { // Verify nonce if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'fix_deliverability_dns_issues_nonce')) { wp_send_json_error(__('Invalid nonce', 'rl-mailwarmer')); } // Get the domain post ID $post_id = intval($_POST['post_id']); if (!$post_id) { wp_send_json_error(__('Invalid post ID', 'rl-mailwarmer')); } // Call the fix_deliverability_dns_issues function try { $results = RL_MailWarmer_Domain_Helper::fix_deliverability_dns_issues($post_id); wp_send_json_success($results); } catch (Exception $e) { wp_send_json_error($e->getMessage()); } }); add_action('wp_ajax_rl_mailwarmer_create_dns_backup', function () { // Verify nonce if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'create_dns_backup_nonce')) { wp_send_json_error(__('Invalid nonce', 'rl-mailwarmer')); } // Get the domain post ID $post_id = intval($_POST['post_id']); if (!$post_id) { wp_send_json_error(__('Invalid post ID', 'rl-mailwarmer')); } // Call the create_dns_backup function try { $backup_id = RL_MailWarmer_Domain_Helper::create_dns_backup($post_id); if (is_wp_error($backup_id)) { wp_send_json_error($backup_id->get_error_message()); } wp_send_json_success($backup_id); } catch (Exception $e) { wp_send_json_error($e->getMessage()); } });