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;
}
global $scf_options;
$checkbox_html = $this->get_checkbox_html();
if (($scf_options['scf_gdpr_position'] ?? '') === 'before_submit') {
$form_html = str_replace('
', $checkbox_html . PHP_EOL . '
', $form_html);
} else {
$form_html = str_replace('', $checkbox_html . PHP_EOL . '', $form_html);
}
// insert the checkbox just before the closing tag
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']);
}
}