PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 3.0.72
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v3.0.72
5.12.0 5.13.0 5.13.1 5.11.0 5.10.0 5.9.0 5.8.0 5.8.1 5.7.0 5.6.2 5.6.3 5.6.1 5.6.0 5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 All 47 releases
double-opt-in / compatibility / avada / AvadaFrontend.class.php

AvadaFrontend.class.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 3.0.72, at compatibility/avada/AvadaFrontend.class.php

256 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace forge12\contactform7\CF7DoubleOptIn {
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * Class Frontend
10 * Responsible to handle the frontend of the Double OptIn
11 *
12 * @package forge12\contactform7\CF7DoubleOptIn
13 */
14 class AvadaFrontend extends OptInFrontend {
15 /**
16 * Admin constructor.
17 */
18 public function __construct() {
19 parent::__construct( 'avada' );
20
21 if ( ! isset( $_GET['optin'] ) ) {
22 add_filter( 'fusion_form_send_mail_args', array( $this, 'onSubmit' ), 10, 3 );
23 }
24 }
25
26 /**
27 * Send the default email for the given OptIn. (Original Mail after Opt-In Confirmation)
28 *
29 * @param OptIn $OptIn The OptIn object containing the email content and form ID.
30 *
31 * @return void
32 */
33 public function sendDefaultMail( OptIn $OptIn ): void {
34 /**
35 * Get the Form Data
36 */
37 $formData = maybe_unserialize( $OptIn->get_content() );
38
39 /**
40 * Sanitize the data
41 */
42 $formData = SanitizeHelper::sanitize_array( $formData );
43
44 /**
45 * check if the formdata is available
46 */
47 if ( ! isset( $formData['data'] ) ) {
48 return;
49 }
50
51 /**
52 * Transform the Data to a key=>value string.
53 *
54 * @example
55 * $data = ['e-mail' => '[email protected]', 'subject' => 'Betreff']
56 * to
57 * $output = [email protected]&subject=Betreff
58 */
59 $data = $formData['data'];
60 $formDataString = [];
61 foreach ( $data as $key => $value ) {
62 if ( is_array( $value ) ) {
63 $value = implode( ',', $value );
64 }
65 $formDataString[] = $key . '=' . $value;
66 }
67 $formDataString = implode( "&", $formDataString );
68
69 /**
70 * Reformat them to work with avada submit
71 */
72 $_POST = array(
73 'formData' => $formDataString,
74 'field_labels' => json_encode( $formData['field_labels'] ),
75 'field_types' => json_encode( $formData['field_types'] ),
76 'hidden_field_names' => json_encode( $formData['hidden_field_names'] )
77 );
78
79 $_POST['form_id'] = $OptIn->get_cf_form_id();
80
81 /**
82 * Load the Avada Form Submit Object
83 */
84 require_once( 'AvadaFormSubmit.class.php' );
85
86 $AvadaFormSubmit = new AvadaFormSubmit();
87
88 /**
89 * Submit the form
90 */
91 $AvadaFormSubmit->submit( $OptIn->get_cf_form_id(), [] );
92 }
93
94 /**
95 * On Form Submit add the double optin if enabled
96 *
97 * @param array $parameter
98 * @param int $post_id
99 * @param array $data
100 */
101 public function onSubmit( $form_parameter, $submission_id, $form_data ) {
102 $post_id = isset( $_POST['form_id'] ) ? absint( sanitize_text_field( wp_unslash( $_POST['form_id'] ) ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
103
104 if ( ! $post_id ) {
105 return $form_parameter;
106 }
107
108 $parameter = CF7DoubleOptIn::getInstance()->getParameter( $post_id );
109
110 if ( $this->isOptinEnabled( $post_id ) ) {
111
112 // Get the Post Object
113 $form = get_post( $post_id );
114
115 if ( ! $form ) {
116 return $form_parameter;
117 }
118
119 $form_data['form_parameter'] = $form_parameter;
120
121 if(apply_filters('f12_cf7_doubleoptin_skip_option', false, $post_id, $form_data, $this->type)){
122 /**
123 * Die after sending the form
124 */
125 die( wp_json_encode( [ 'status' => 'error', 'info' => 'opt-in skipped' ] ) );
126 }
127
128 // Get the OptIn Object
129 $OptIn = $this->maybeCreateOptIn( $post_id, do_shortcode( $form->post_content ), $form_data, $form_parameter['attachments'] );
130
131 /**
132 * Skip if OptIn not created
133 */
134 if ( ! $OptIn ) {
135 return $form_parameter;
136 }
137
138 // Add the Form URL
139 $parameter['formUrl'] = $form_data['submission']['source_url'];
140
141 // Get the Body content
142 $body = $parameter['body'];
143
144 // Replace the Placeholders within the body content.
145 $body = $this->addPlaceholders( $body, $OptIn, $parameter );
146
147 /**
148 * Body
149 *
150 * Filters the Body of the OptIn Mail. Allows developers to adjust the content
151 * before transmission.
152 *
153 * @param string $body The content of the OptIn Mail.
154 *
155 * @since 2.3.3
156 */
157 $body = apply_filters( 'f12_cf7_doubleoptin_body', $body );
158
159 /**
160 * Set the OptIn Mail Content to the OptIn Object.
161 */
162 $OptIn->set_mail_optin( $body );
163 $OptIn->save();
164
165 /**
166 * Recipient
167 */
168 $headers = "MIME-Version: 1.0\r\n";
169 $headers .= "Content-type: text/html; charset=UTF-8\r\n";
170
171 /**
172 * OptIn Mail Arguments
173 *
174 * Filters the Arguments for the OptIn Mail. This hook allows developers
175 * to add additional content to the Mail.
176 *
177 * @formatter:off
178 *
179 * @param $args {
180 * @type string $subject The Subject of the OptIn Mail
181 * @type string $body The Body of the OptIn Mail,
182 * @type string $sender The Sender of the OptIn Mail
183 * @type string $recipient The recipient of the OptIn Mail
184 * @type bool $use_html Enable/Disable HTML for the OptIn Mail. Default: true
185 * @type string $additional_headers Additional Header Information for the Mail.
186 * }
187 *
188 * @formatter:on
189 *
190 * @since 2.3.3
191 */
192 $args = apply_filters( 'f12-cf7-doubleoptin-cf7-args', [
193 'subject' => $parameter['subject'],
194 'body' => $body,
195 'sender' => $parameter['sender'],
196 'sender_name' => $parameter['sender_name'],
197 'recipient' => $form_data['data'][ $parameter['recipient'] ],
198 'use_html' => true,
199 'additional_headers' => $headers
200 ] );
201
202 /*
203 * Adjust the header
204 */
205 $args['additional_headers'] .= sprintf( 'From: %s <%s>' . "\r\n", $args['sender_name'], $args['sender'] );
206
207 \wp_mail(
208 $args['recipient'],
209 $args['subject'],
210 $args['body'],
211 $args['additional_headers']
212 );
213
214 /**
215 * Action after the OptIn Mail has been sent.
216 *
217 * Allows other developers to do additional tasks after the OptIn Mail has been submitted.
218 *
219 * @formatter:off
220 *
221 * @param \WPCF7_ContactForm $form The Contact Form 7 Form Object
222 * @param int $formId The Post ID of the CF7 Form.
223 *
224 * @formatter:on
225 *
226 * @since 2.3.3
227 */
228 do_action( 'f12_cf7_doubleoptin_sent', $form, $post_id );
229
230 /**
231 * Die after sending the form
232 */
233 die( wp_json_encode( [ 'status' => 'success', 'info' => 'opt-in send' ] ) );
234 }
235
236 return $form_parameter;
237 }
238
239 /**
240 * Retrieves the recipient value from the given parameters.
241 *
242 * @param string $recipient The recipient parameter.
243 * @param array $formParameter The form parameters.
244 * @param array $postParameter The post parameters.
245 *
246 * @return string The recipient value if it exists in the post parameters, or an empty string if it doesn't.
247 */
248 public function getRecipient( string $recipient, array $formParameter, array $postParameter ): string {
249 if ( ! isset( $postParameter['data'][ $formParameter['recipient'] ] ) ) {
250 return '';
251 }
252
253 return $postParameter['data'][ $formParameter['recipient'] ];
254 }
255 }
256 }