| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
|
| 5 |
use Forge12\Shared\Logger; |
| 6 |
use Fusion_Builder_Form_Helper; |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
if (class_exists('\Fusion_Form_Submit')) { |
| 13 |
/** |
| 14 |
* Class Frontend |
| 15 |
* Responsible to handle the frontend of the Double OptIn |
| 16 |
* |
| 17 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 18 |
*/ |
| 19 |
class AvadaFormSubmit extends \Fusion_Form_Submit |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Proces nonce, recaptcha and similar checks. |
| 23 |
* Dies if checks fail. |
| 24 |
* |
| 25 |
* @access protected |
| 26 |
* @since 3.1.1 |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
protected function pre_process_form_submit() { |
| 30 |
$logger = Logger::getInstance(); |
| 31 |
|
| 32 |
$logger->debug( 'Pre process form submit started', [ |
| 33 |
'plugin' => 'double-opt-in', |
| 34 |
'class' => __CLASS__, |
| 35 |
'method' => __METHOD__, |
| 36 |
] ); |
| 37 |
|
| 38 |
// Verify the form submission nonce. |
| 39 |
// check_ajax_referer( 'fusion_form_nonce', 'fusion_form_nonce' ); |
| 40 |
|
| 41 |
// If we are in demo mode, just pretend it has sent. |
| 42 |
if ( apply_filters( 'fusion_form_demo_mode', false ) ) { |
| 43 |
$logger->info( 'Demo mode active, returning demo success response', [ |
| 44 |
'plugin' => 'double-opt-in', |
| 45 |
] ); |
| 46 |
die( wp_json_encode( $this->get_results_from_message( 'success', 'demo' ) ) ); |
| 47 |
} |
| 48 |
|
| 49 |
// Check reCAPTCHA response and die if error. |
| 50 |
$logger->debug( 'Checking reCAPTCHA response', [ |
| 51 |
'plugin' => 'double-opt-in', |
| 52 |
] ); |
| 53 |
|
| 54 |
$this->check_recaptcha_response(); |
| 55 |
|
| 56 |
$logger->debug( 'Pre process form submit finished', [ |
| 57 |
'plugin' => 'double-opt-in', |
| 58 |
] ); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
/** |
| 63 |
* Ajax callback for 'send to email' submission type. |
| 64 |
* |
| 65 |
* @access public |
| 66 |
* @return void |
| 67 |
* @since 3.1 |
| 68 |
*/ |
| 69 |
public function submit( $formID, $sendmail_args ) { |
| 70 |
$logger = Logger::getInstance(); |
| 71 |
|
| 72 |
$logger->debug( 'Form submission started', [ |
| 73 |
'plugin' => 'double-opt-in', |
| 74 |
'class' => __CLASS__, |
| 75 |
'method' => __METHOD__, |
| 76 |
'form_id' => $formID, |
| 77 |
'args' => $sendmail_args, |
| 78 |
] ); |
| 79 |
|
| 80 |
$this->pre_process_form_submit(); |
| 81 |
|
| 82 |
// Checks nonce, recaptcha and similar. Dies if checks fail. |
| 83 |
$data = $this->get_submit_data(); |
| 84 |
$logger->debug( 'Form data retrieved', [ |
| 85 |
'plugin' => 'double-opt-in', |
| 86 |
'form_id' => $formID, |
| 87 |
] ); |
| 88 |
|
| 89 |
$form_meta = Fusion_Builder_Form_Helper::fusion_form_get_form_meta( $formID ); |
| 90 |
$actions = $form_meta['form_actions'] ?? []; |
| 91 |
|
| 92 |
if ( ! empty( $actions ) ) { |
| 93 |
foreach ( $actions as $action ) { |
| 94 |
if ( $action === 'email' ) { |
| 95 |
$logger->debug( 'Processing deprecated email action', [ |
| 96 |
'plugin' => 'double-opt-in', |
| 97 |
'form_id' => $formID, |
| 98 |
] ); |
| 99 |
|
| 100 |
$sendmail = $this->submit_form_to_email( $data ); |
| 101 |
|
| 102 |
if ( $sendmail ) { |
| 103 |
$logger->info( 'Email action executed successfully', [ |
| 104 |
'plugin' => 'double-opt-in', |
| 105 |
'form_id' => $formID, |
| 106 |
] ); |
| 107 |
$fusion_forms = new \Fusion_Form_DB_Forms(); |
| 108 |
$fusion_forms->increment_submissions_count( $formID ); |
| 109 |
} else { |
| 110 |
$logger->warning( 'Email action failed', [ |
| 111 |
'plugin' => 'double-opt-in', |
| 112 |
'form_id' => $formID, |
| 113 |
] ); |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
$sendmail = $this->handle_form_notifications( $data, $formID ); |
| 120 |
|
| 121 |
if ( $sendmail ) { |
| 122 |
$logger->info( 'Form notifications handled successfully', [ |
| 123 |
'plugin' => 'double-opt-in', |
| 124 |
'form_id' => $formID, |
| 125 |
] ); |
| 126 |
|
| 127 |
$fusion_forms = new \Fusion_Form_DB_Forms(); |
| 128 |
$fusion_forms->increment_submissions_count( $formID ); |
| 129 |
|
| 130 |
return true; |
| 131 |
} |
| 132 |
|
| 133 |
$logger->warning( 'Form submission failed', [ |
| 134 |
'plugin' => 'double-opt-in', |
| 135 |
'form_id' => $formID, |
| 136 |
] ); |
| 137 |
|
| 138 |
return false; |
| 139 |
} |
| 140 |
|
| 141 |
} |
| 142 |
} |
| 143 |
} |