Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
'MC4WP_Queue' => '/includes/class-queue.php',
'MC4WP_Queue_Job' => '/includes/class-queue-job.php',
'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',
'MC4WP_Upgrade_Routines' => '/includes/admin/class-upgrade-routines.php',
'MC4WP_User_Integration' => '/includes/integrations/class-user-integration.php',
Expand Down
1 change: 1 addition & 0 deletions integrations/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function mc4wp_admin_after_integration_settings(MC4WP_Integration $integration,
mc4wp_register_integration('memberpress', 'MC4WP_MemberPress_Integration');
mc4wp_register_integration('affiliatewp', 'MC4WP_AffiliateWP_Integration');
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);
mc4wp_register_integration('woocommerce', 'MC4WP_WooCommerce_Integration');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

defined('ABSPATH') or exit;

/**
* Class MC4WP_Simple_Basic_Contact_Form_Integration
*
* Integrates Mailchimp for WordPress with the Simple Basic Contact Form plugin.
*
* @since 4.9.0
* @ignore
*/
class MC4WP_Simple_Basic_Contact_Form_Integration extends MC4WP_Integration
{
/**
* @var string
*/
public $name = 'Simple Basic Contact Form';

/**
* @var string
*/
public $description = 'Subscribes people from Simple Basic Contact Form forms.';

/**
* Add hooks
*/
public function add_hooks()
{
add_filter('scf_filter_contact_form', [ $this, 'add_checkbox' ], 20);
add_action('scf_send_email', [ $this, 'process' ], 10, 5);
}

/**
* Adds the MC4WP checkbox to the Simple Basic Contact Form HTML.
*
* Inserts the checkbox before the closing </form> tag so it appears
* inside the form, just before the submit area.
*
* @param string $form_html The full contact form HTML.
* @return string Modified form HTML with the checkbox injected.
*/
public function add_checkbox($form_html)
{
// do not add a checkbox when integration is implicit
if ($this->options['implicit']) {
return $form_html;
}

$checkbox_html = $this->get_checkbox_html();

// insert the checkbox just before the closing </form> tag
$form_html = str_ireplace('</form>', $checkbox_html . '</form>', $form_html);

return $form_html;
}

/**
* Process the form submission and subscribe the user if the checkbox was checked.
*
* Fires on the `scf_send_email` action after the contact form email is sent.
*
* @param string $recipient The email recipient.
* @param string $topic The email subject.
* @param string $message The email message body.
* @param string $headers The email headers.
* @param string $email The sender's email address (form submitter).
*
* @return bool
*/
public function process($recipient, $topic, $message, $headers, $email)
{
// was sign-up checkbox checked?
if (! $this->triggered()) {
return false;
}

$parser = new MC4WP_Field_Guesser($this->get_data());
$data = $parser->combine([ 'guessed', 'namespaced' ]);

// use the email from the action parameter if not found via field guesser
if (empty($data['EMAIL']) && ! empty($email)) {
$data['EMAIL'] = $email;
}

// do nothing if no email was found
if (empty($data['EMAIL'])) {
$this->get_log()->warning(sprintf('%s > Unable to find EMAIL field.', $this->name));
return false;
}

return $this->subscribe($data);
}

/**
* Are the required dependencies for this integration installed?
*
* @return bool
*/
public function is_installed()
{
return function_exists('simple_contact_form');
}

/**
* Returns the UI elements to show on the settings page.
*
* Removes 'implicit' since this integration uses an explicit checkbox approach.
*
* @since 4.9.0
* @return array
*/
public function get_ui_elements()
{
return array_diff(parent::get_ui_elements(), [ 'implicit' ]);
}
}