feat(integration): add Simple Basic Contact Form integration#820
Open
faisalahammad wants to merge 1 commit intoibericode:mainfrom
Open
Conversation
- Add MC4WP_Simple_Basic_Contact_Form_Integration class - Hook into scf_filter_contact_form to inject checkbox - Hook into scf_send_email to process subscription - Register class in autoload classmap - Register integration in bootstrap Fixes ibericode#753
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Summary
Adds a new integration with the Simple Basic Contact Form plugin, allowing users to subscribe to Mailchimp lists via an opt-in checkbox on SBCF contact forms.
📋 Issue Reference
Fixes #753
As requested on WordPress.org support.
🔍 Problem Description
Current Behavior
The Simple Basic Contact Form plugin has no Mailchimp integration. Users who rely on SBCF for their contact forms cannot offer Mailchimp newsletter subscriptions through those forms.
Expected Behavior
An opt-in checkbox should appear inside the Simple Basic Contact Form, and when checked, the form submitter's data should be sent to the selected Mailchimp list.
✨ Solution Overview
Approach Taken
Created a new
MC4WP_Simple_Basic_Contact_Form_Integrationclass that follows the exact same pattern used by the existing CF7 and Comment Form integrations. The integration hooks into two SBCF extension points:scf_filter_contact_form(filter) — Injects the MC4WP checkbox HTML into the form before the</form>closing tagscf_send_email(action) — Processes the subscription after the contact form email is successfully sentWhy This Approach
scf_filter_contact_formandscf_send_emailare well-established hooks in the SBCF pluginMC4WP_Field_Guesseron$_POSTdata (same as CF7) to automatically map form fields to Mailchimp merge fieldsAlternatives Considered
scf_custom_fieldshook: Only suitable for adding extra form fields, not for injecting a checkbox with custom behavior. Would require more complex HTML manipulation.scf_filter_contact_formfilter is the intended extension point for modifying form HTML.🔧 Changes Made
Files Modified
integrations/simple-basic-contact-form/class-simple-basic-contact-form.phpautoload.phpintegrations/bootstrap.phpmc4wp_register_integration()Detailed Changes
1. Integration Class (New File)
Key methods:
add_hooks()scf_filter_contact_formfilter andscf_send_emailactionadd_checkbox($form_html)</form>usingstr_ireplace()process($recipient, $topic, $message, $headers, $email)MC4WP_Field_Guesserto extract data, falls back to the$emailaction parameter if EMAIL not found via guesseris_installed()function_exists('simple_contact_form')get_ui_elements()'implicit'— explicit checkbox only (same as CF7)Why this works:
The
scf_send_emailaction fires at line 674 of the SBCF plugin after successful form validation and email delivery. This ensures:$emailis available as a reliable fallback$_POSTdata is still accessible for field guessing2. Autoload Registration
'MC4WP_Registration_Form_Integration' => '/integrations/wp-registration-form/class-registration-form.php', +'MC4WP_Simple_Basic_Contact_Form_Integration' => '/integrations/simple-basic-contact-form/class-simple-basic-contact-form.php', 'MC4WP_Tools' => '/includes/class-tools.php',3. Bootstrap Registration
mc4wp_register_integration('give', 'MC4WP_Give_Integration'); +mc4wp_register_integration('simple-basic-contact-form', 'MC4WP_Simple_Basic_Contact_Form_Integration'); mc4wp_register_integration('custom', 'MC4WP_Custom_Integration', true);🧪 Testing Performed
Automated Testing
✅ All 54 existing tests pass with 175 assertions — no regressions.
Manual Testing
Test Case 1: Integration Visibility
Steps:
Expected: "Simple Basic Contact Form" appears in the integrations list
Actual: ✅ Integration visible with correct name and description
Test Case 2: Checkbox Rendering
Steps:
[simple_contact_form]shortcodeExpected: MC4WP checkbox appears inside the form, before submit
Actual: ✅ Checkbox renders correctly within the form
Test Case 3: Subscription Flow
Steps:
Expected: Email is added to the selected Mailchimp list
Actual: ✅ Subscription processed successfully
Test Case 4: Opt-out Respected
Steps:
Expected: No Mailchimp subscription happens
Actual: ✅ No subscription — form email sent normally
📊 Performance Impact
Analysis: ✅ Negligible impact
str_ireplace()for checkbox injection and$_POSTreading for field guessing are trivial operations🔒 Security Considerations
MC4WP_Field_Guesser, which handles sanitization$this->triggered()from the base class, which properly checks for the checkbox valueMC4WP_Integration::subscribe()method♿ Accessibility
$this->get_checkbox_html()from the base class, which follows the same accessible markup pattern used across all other integrations🌍 Internationalization
$nameand$descriptionfollow the same pattern as existing integrations (English strings, consistent with codebase convention)✅ No breaking changes — This is a purely additive feature. Existing integrations and functionality are completely unaffected.
Screenshots
Plugin build/zip
mailchimp-for-wp-fix-issue-753.zip
✅ PR Checklist
Ready for Review ✨