get_route(), '/contact-form-7/') !== false) {\n $form_id = $request->get_param('_wpcf7');\n if ($form_id) {\n $form = wpcf7_contact_form($form_id);\n if ($form) {\n $tags = $form->scan_form_tags();\n foreach ($tags as $tag) {\n // Fill empty radio buttons with their default value so CF7 doesn't throw "An undefined value was submitted"\n if ($tag->type === 'radio' && empty($_POST[$tag->name]) && !empty($tag->values)) {\n $_POST[$tag->name] = ((array) $tag->values)[0];\n }\n }\n }\n }\n }\n return $result;\n}, 10, 3);\n\n// 2. Trigger n8n webhook\nadd_action('wpcf7_submit', 'jcp_trigger_n8n_webhook', 10, 2);\nadd_action('wpcf7_before_send_mail', 'jcp_trigger_n8n_webhook', 10, 2);\nadd_action('wpcf7_mail_sent', 'jcp_trigger_n8n_webhook', 10, 1);\n\nfunction jcp_trigger_n8n_webhook($form = null, $arg2 = null) {\n static $sent = [];\n if (!$form || !is_a($form, 'WPCF7_ContactForm') || isset($sent[$form->id()])) return;\n $sent[$form->id()] = true;\n\n $sub = WPCF7_Submission::get_instance();\n $data = $sub ? $sub->get_posted_data() : $_POST;\n $url = $sub ? $sub->get_meta('url') : (wp_get_referer() ?: home_url($_SERVER['REQUEST_URI']));\n $clean = [];\n\n // Чистимо дані від wpcf7 та масивів\n foreach ($data as $k => $v) {\n if (strpos($k, '_wpcf7') !== 0) $clean[$k] = is_array($v) ? implode(', ', $v) : $v;\n }\n\n // Видалення полів з неактивних гілок (Regex-оптимізація)\n $html = $form->prop('form');\n $branch = 'br-0';\n if (preg_match('/data-step-type=["\']splitter["\'].*?\[radio\s+([^\s\]]+)\s+.*?("(?:[^"\\\\]|\\\\.)*"(?:\s+"(?:[^"\\\\]|\\\\.)*")*)/is', $html, $m)) {\n preg_match_all('/"((?:[^"\\\\]|\\\\.)*)"/', $m[2], $opts);\n if (isset($clean[$m[1]]) && ($idx = array_search($clean[$m[1]], $opts[1] ?? [])) !== false) {\n $branch = 'br-' . $idx;\n }\n }\n\n if (preg_match_all('/class=[\"\'][^\"\']*?branch-group\s+(br-\d+)[^\"\']*?[\"\'](.*?)?(?=
\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435:<\/p>\n<\/span><\/div>\n