get_content() ); /** * Sanitize the Data */ $_POST = SanitizeHelper::sanitize_array( $data ); /** * Prepare the Contact Form */ $ContactForm = \WPCF7_ContactForm::get_instance( $OptIn->get_cf_form_id() ); /** * Prepare the Submission Instance */ $submission = \WPCF7_Submission::get_instance( $ContactForm ); } /** * On Form Submit add the double optin if enabled * * @param $form \WPCF7_ContactForm * @param bool * @param $submission \WPCF7_Submission */ public function onSubmit( $form, &$abort, $submission ) { $parameter = CF7DoubleOptIn::getInstance()->getParameter( $form->id() ); if ( $this->isOptinEnabled( $form->id() ) ) { // Remove Contact Form 7 DB hook to ensure the optin mail is not saved remove_action( 'wpcf7_before_send_mail', 'cfdb7_before_send_mail' ); // Get the OptIn Object $OptIn = $this->maybeCreateOptIn( $form->id(), $form->form_html(), $submission->get_posted_data(), $submission->uploaded_files() ); /** * Skip if OptIn not created */ if ( ! $OptIn ) { return; } // Add the Form URL to the parameters $parameter['formUrl'] = $submission->get_meta( 'url' ); // Get the Body content $body = $parameter['body']; // Replace the Placeholders within the body content. $body = $this->addPlaceholders( $body, $OptIn, $parameter ); /** * Body * * Filters the Body of the OptIn Mail. Allows developers to adjust the content * before transmission. * * @param string $body The content of the OptIn Mail. * * @since 2.3.3 */ $body = apply_filters( 'f12_cf7_doubleoptin_body', $body ); /** * Set the OptIn Mail Content to the OptIn Object. */ $OptIn->set_mail_optin( $body ); $OptIn->save(); /** * Recipient */ $additional_headers = ''; /** * OptIn Mail Arguments * * Filters the Arguments for the OptIn Mail. This hook allows developers * to add additional content to the Mail. * * @formatter:off * * @param $args { * @type string $subject The Subject of the OptIn Mail * @type string $body The Body of the OptIn Mail, * @type string $sender The Sender of the OptIn Mail * @type string $recipient The recipient of the OptIn Mail * @type bool $use_html Enable/Disable HTML for the OptIn Mail. Default: true * @type string $additional_headers Additional Header Information for the Mail. * } * * @formatter:on * * @since 2.3.3 */ $args = apply_filters( 'f12-cf7-doubleoptin-cf7-args', [ 'subject' => $parameter['subject'], 'body' => $body, 'sender' => $parameter['sender'], 'sender_name' => $parameter['sender_name'], 'recipient' => $parameter['recipient'], 'use_html' => true, 'additional_headers' => $additional_headers ] ); /** * Set the Header */ if ( ! empty( $parameter['sender_name'] ) ) { $args['additional_headers'] .= 'From: ' . $args['sender_name'] . ' <' . $args['sender'] . '>'; } // Prepare the Opt-In Mail \WPCF7_Mail::send( $args, 'mail' ); // Skip all mails following add_filter( 'wpcf7_skip_mail', '__return_true' ); /** * Action after the OptIn Mail has been sent. * * Allows other developers to do additional tasks after the OptIn Mail has been submitted. * * @formatter:off * * @param \WPCF7_ContactForm $form The Contact Form 7 Form Object * @param int $formId The Post ID of the CF7 Form. * * @formatter:on * * @since 2.3.3 */ do_action( 'f12_cf7_doubleoptin_sent', $form, $form->id() ); } else if ( isset( $_GET['optin'] ) ) { /** * Add Files / Attachments to the OptIn Mail. */ $hash = sanitize_text_field( $_GET['optin'] ); /** * Get the OptIn Object */ $OptIn = OptIn::get_by_hash( $hash ); /** * Skip if the OptIn has not been found. */ if ( null == $OptIn ) { return; } /** * Get the Files from the OptIn Object */ $files = maybe_unserialize( $OptIn->get_files() ); /** * Skip if no files has been found */ if ( empty( $files ) ) { return; } /** * Loop through all attachments/files. */ foreach ( $files as $file ) { /** * Skip file if the name is empty */ if ( ! empty( $file ) ) { continue; } /** * Enable / Disable the OptIn Mail Attachment for Mail 1. * * Allows Developers to Enable/Disable Mail attachments dynamically. * * @param bool $status Either add attachments (true) or not (false). Default: true * @param OptIn $OptIn The OptIn Object. * * @since 2.3.3 */ if ( apply_filters( 'f12_cf7_doubleoptin_files_mail_1', true, $OptIn ) ) { $submission->add_extra_attachments( $file ); } /** * Enable / Disable the OptIn Mail Attachment for Mail 2. * * Allows Developers to Enable/Disable Mail attachments dynamically. * * @param bool $status Either add attachments (true) or not (false). Default: true * @param OptIn $OptIn The OptIn Object. * * @since 2.3.3 */ if ( apply_filters( 'f12_cf7_doubleoptin_files_mail_2', true, $OptIn ) ) { $submission->add_extra_attachments( $file, 'mail_2' ); } } } } } }