// === Elementor Form Mail-Routing (auto-deployed) ===
// Flag setzen wenn Elementor-Form verarbeitet wird
add_action('elementor_pro/forms/process', function($record, $ajax_handler) {
global $elementor_form_active;
$elementor_form_active = true;
}, 10, 2);
add_filter('wp_mail', function($args) {
global $elementor_form_active;
// Nur bei Elementor-Forms eingreifen
if (empty($elementor_form_active)) {
return $args;
}
$referer = wp_get_referer();
error_log('=== ELEMENTOR MAIL DEBUG START ===');
error_log('To: ' . (is_array($args['to']) ? implode(', ', $args['to']) : $args['to']));
error_log('Subject: ' . $args['subject']);
error_log('Headers: ' . print_r($args['headers'], true));
error_log('Referer: ' . ($referer ?: 'LEER'));
if (!$referer) {
error_log('ABBRUCH: Kein Referer');
error_log('=== ELEMENTOR MAIL DEBUG ENDE ===');
return $args;
}
// Term aus URL ermitteln
$url_path = trim(parse_url($referer, PHP_URL_PATH), '/');
$slug = basename($url_path);
error_log("URL-Pfad: {$url_path}, Slug: {$slug}");
$term = null;
$taxonomies = get_taxonomies(['public' => true], 'names');
foreach ($taxonomies as $tax) {
$t = get_term_by('slug', $slug, $tax);
if ($t) {
$term = $t;
break;
}
}
if (!$term) {
error_log('Kein Term gefunden - prüfe ob es ein Post/Page ist');
$post_id = url_to_postid($referer);
if ($post_id) {
error_log("Post gefunden: {$post_id}");
// Post-Variante hier falls nötig
} else {
error_log('ABBRUCH: Weder Term noch Post gefunden');
}
error_log('=== ELEMENTOR MAIL DEBUG ENDE ===');
return $args;
}
$term_key = $term->taxonomy . '_' . $term->term_id;
error_log("Term: {$term->name} (Key: {$term_key})");
// ACF-Werte holen
$mailto = get_field('footer_contact_form_mailto.Value', $term_key);
$subject = get_field('footer_contact_form_subject.Content', $term_key);
$bcc = get_field('footer_contact_form_bcc.Value', $term_key);
error_log("ACF mailto: " . ($mailto ?: 'LEER'));
error_log("ACF subject: " . ($subject ?: 'LEER'));
error_log("ACF bcc: " . ($bcc ?: 'LEER'));
if ($mailto) {
$args['to'] = $mailto;
error_log("TO ersetzt");
}
if ($subject) {
$args['subject'] = $subject;
error_log("SUBJECT ersetzt");
}
if ($bcc) {
if (!is_array($args['headers'])) {
$args['headers'] = !empty($args['headers']) ? explode("\n", $args['headers']) : [];
}
$args['headers'] = array_filter($args['headers'], function($h) {
return stripos($h, 'bcc:') === false;
});
$args['headers'][] = 'Bcc: ' . $bcc;
error_log("BCC ersetzt");
}
// Flag zurücksetzen
$elementor_form_active = false;
error_log('=== ELEMENTOR MAIL DEBUG ENDE ===');
return $args;
});
// === Ende Elementor Form Mail-Routing ===
» Kontakt Rechtsanwalt Rischmüller & Seide