Mautic Consent for Elementor
WordPress plugin that injects a marketing-consent checkbox into all Elementor Pro forms and syncs opt-ins to Mautic via OAuth2 API.
by Marcin Wilczyński · github.com/mbridge-pl-agency/mautic-consent-for-elementor · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/mbridge-pl-agency/mautic-consent-for-elementor/archive/refs/heads/main.zipA WordPress plugin that automatically injects a marketing-consent checkbox into every Elementor Pro form on your site and syncs opt-ins to Mautic via OAuth2 API.
What it does
When a visitor submits an Elementor form with the consent checkbox ticked, the plugin:
- Creates or updates a contact in Mautic — search-then-PATCH-or-POST flow, no duplicates by email
- Adds the contact to a configured segment — your "Newsletter Subscribers" or whatever you set up
- Tags them with the source form name — e.g.
wp-form-contact, so marketers can segment by entry point - Records GDPR consent fields — timestamp, source (form name + page URL), IP — stored as custom contact fields in Mautic for audit purposes
If Mautic is offline, slow, or returns an error, the form submission proceeds normally. Fail-open by design — Mautic outage never blocks user from sending the form.
Why this plugin
Elementor Pro forms have no built-in marketing-consent checkbox. Adding one manually to each form is tedious, error-prone, and easy to forget on new forms. This plugin:
- Adds the checkbox automatically to every form — no per-form configuration
- Lets you disable it on specific forms (e.g. HR contact, complaint forms) from the admin
- Lets you edit the consent text in one place (with a
<a>link to your privacy policy) - Lets you add custom CSS for visual tweaks
- Validates your Mautic setup with a one-click "Test connection" button (verifies OAuth + that all 4 required custom fields exist)
- Runs in English by default, i18n-ready for translations (textdomain
mautic-consent-for-elementor)
Status
v0.1.0 — initial release. 49 unit tests passing. Production-hardened: defensive try/catch on every WordPress hook so any internal failure cannot break Elementor form rendering or submission.
Tested against PHP 8.1+, WordPress 6.4+, Elementor Pro 3.20+, Mautic 4.x and 5.x.
Setup overview
On the Mautic side:
- Enable the API: Settings → Configuration → API Settings
- Create OAuth2 credentials: Settings → API Credentials → New
- Create a segment for newsletter subscribers (note its ID)
- Create 4 required custom contact fields:
elementor_consent(Yes/No)elementor_consent_date(Datetime)elementor_consent_source(Text, length 255 — default 64 is too short)elementor_consent_ip(Text, length 64)
On the WordPress side:
- Upload the plugin zip via Plugins → Add New → Upload Plugin
- Activate
- Settings → Mautic Consent → fill in URL, credentials, segment ID
- Click "Test connection and Mautic fields" — verifies OAuth and that the 4 custom fields exist
- Edit the consent checkbox text in the Consent text tab
- Optional: add custom CSS in the Style tab
- Optional: disable the checkbox on specific forms in the Forms tab
The plugin's Help / Setup tab walks admins through this in-app — useful for handing the plugin off to non-developers.
Double Opt-In
Handled entirely on the Mautic side via Campaigns. The plugin writes the contact + initial consent record; Mautic Campaigns handle the confirmation email, tracking the click, and updating contact state. No plugin code changes needed for DOI.
Building a distribution zip
For deployment to production WordPress sites without Composer:
composer install --no-dev --optimize-autoloader
cd ..
zip -r mautic-consent-for-elementor.zip mautic-consent-for-elementor \
-x 'mautic-consent-for-elementor/.phpunit.cache/*' \
-x 'mautic-consent-for-elementor/tests/*' \
-x 'mautic-consent-for-elementor/composer.lock' \
-x 'mautic-consent-for-elementor/phpunit.xml.dist'
Note: clone the repo into a folder named mautic-consent-for-elementor/ for the zip command to produce the correct paths. WordPress expects the plugin folder name to match the slug.
Development
composer install
vendor/bin/phpunit
Requires PHP 8.1+, Composer 2.
Tests use PHPUnit 10 with brain/monkey for mocking WordPress functions — no full WordPress install needed for the test suite.
Manual E2E checklist
Run through this on a real WP+Elementor+Mautic stack before each release:
- Happy path: Submit a form with the consent checkbox ticked → verify in Mautic: contact created, in segment, tagged
wp-form-<slug>, all 4 consent fields populated. - Update path: Submit again with same email → verify: contact updated (PATCH), tag NOT duplicated, fields refreshed, segment membership unchanged.
- No consent: Submit without ticking → verify: NO API call to Mautic (check Logs tab — no row).
- Mautic offline: Stop Mautic, submit with consent → verify: form submission still succeeds for the user, error logged in admin → Logs tab.
- Optimized Markup: Toggle Elementor Settings → Features → Optimized DOM. Re-test happy path.
- Per-form toggle: Disable a specific form in the Forms tab → reload page with that form → verify checkbox absent. Other forms still show checkbox.
- Constants override: Add
define('WPME_MAUTIC_CLIENT_SECRET', '...')towp-config.php→ verify: secret field in admin is disabled with a notice; Test Connection still works. - Test Connection — missing fields: Delete one of the four custom fields in Mautic → click Test Connection → verify error message lists the missing alias.
Architecture
Single plugin folder, PHP 8.1+, namespaced under WPME\ (PSR-4 autoload from includes/). Component classes:
Plugin— singleton bootstrap; registers WP hooks; defensive try/catch on every callbackActivator— creates thewpme_logstable on activationLogger— masks email + writes towpme_logs+ prunes to 100 rowsFieldMapper— pure conversion of Elementor fields → Mautic contact body (id-convention aliases)MauticClient— OAuth2 client_credentials with transient token cache, search/create/update/segment add, validate setupFormScanner— walks_elementor_dataJSON to discover form widgets, transient cachedFormInjector— regex injection of consent checkbox HTML; handles standard markup and Elementor's "Optimized Markup" mode; usespreg_replace_callbackto avoid PCRE$NcorruptionSettings— read-only access towp_optionswithWPME_MAUTIC_CLIENT_ID/SECRETconstants overrideSubmissionHandler— orchestrator running inelementor_pro/forms/new_record; reads consent from$_POST, builds payload with 4 RODO fields, fail-open via try/catchAdmin\Admin+Admin\SettingsPage— 6-tab admin UI (Mautic / Consent text / Style / Forms / Logs / Help) + Test Connection AJAX
License
GPL-2.0-or-later