From f9a6275cba8d9973b04792d42bc52d008a4c5164 Mon Sep 17 00:00:00 2001 From: Kilian Domaratius Date: Thu, 30 Jul 2026 16:45:41 +0200 Subject: [PATCH] Add support for elementor atomic forms --- .../modules/elementor/atomic-widget.html.twig | 22 +++ .../modules/elementor/atomic-widget.php | 157 ++++++++++++++++++ .../modules/elementor/elementor.php | 14 ++ 3 files changed, 193 insertions(+) create mode 100644 friendly-captcha/modules/elementor/atomic-widget.html.twig create mode 100644 friendly-captcha/modules/elementor/atomic-widget.php diff --git a/friendly-captcha/modules/elementor/atomic-widget.html.twig b/friendly-captcha/modules/elementor/atomic-widget.html.twig new file mode 100644 index 0000000..7ca39e0 --- /dev/null +++ b/friendly-captcha/modules/elementor/atomic-widget.html.twig @@ -0,0 +1,22 @@ +{%- set classes = ['frcaptcha-placeholder'] | merge( [ base_styles.base ] ) | join(' ') | trim %} + +{# We render a placeholder instead of the real widget here #} +{# The real widget messed with the Elementor editor #} +
+ Anti-Robot Verification +
+ diff --git a/friendly-captcha/modules/elementor/atomic-widget.php b/friendly-captcha/modules/elementor/atomic-widget.php new file mode 100644 index 0000000..9f7e6d0 --- /dev/null +++ b/friendly-captcha/modules/elementor/atomic-widget.php @@ -0,0 +1,157 @@ +is_configured()) { + return; + } + + try { + // Adds data-interaction-id the solution input after initialization + // Elementor Atomic Forms sends only input fields by selector `input[data-interaction-id]` + $interaction_id = $this->get_interaction_id(); + + $solution = FriendlyCaptcha_Plugin::$instance->get_solution_field_name(); + if(empty($solution)) throw new \Exception("FriendlyCaptcha solution is missing"); + + ob_start(); + ?> +
+ + +
+ __DIR__ . '/atomic-widget.html.twig', + ]; + } + + public function is_spam( bool $is_spam, array $form_fields, array $widget_settings, int $post_id = 0 ): bool { + if ( $is_spam ) { + return true; + } + + $plugin = FriendlyCaptcha_Plugin::$instance; + if (!$plugin->is_configured()) { + return false; + } + + $solution = null; + $fieldName = FriendlyCaptcha_Plugin::$instance->get_solution_field_name(); + foreach ($form_fields as $key => $field) { + if ($field['name'] === $fieldName) { + $solution = $field['value']; + break; + } + } + if (empty($solution)) return true; + + $verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key(), 'elementor'); + + return !$verification["success"]; + } +} diff --git a/friendly-captcha/modules/elementor/elementor.php b/friendly-captcha/modules/elementor/elementor.php index 870f6a8..352f7b6 100644 --- a/friendly-captcha/modules/elementor/elementor.php +++ b/friendly-captcha/modules/elementor/elementor.php @@ -27,5 +27,19 @@ function frcaptcha_elementor_add_form_field($form_fields_registrar) $form_fields_registrar->register(new \Elementor_Form_Friendlycaptcha_Field()); } +function frcaptcha_elementor_add_atomic_widget($widgets_manager): void +{ + $plugin = FriendlyCaptcha_Plugin::$instance; + if (!$plugin->is_configured()) { + return; + } + + require_once(__DIR__ . "/atomic-widget.php"); + $widgets_manager->register(new \Elementor_Friendlycaptcha_Atomic_Widget()); +} + + add_action('elementor/init', 'frcaptcha_elementor_init'); add_action('elementor_pro/forms/fields/register', 'frcaptcha_elementor_add_form_field'); +add_action('elementor/widgets/register', 'frcaptcha_elementor_add_atomic_widget'); +