PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 3.0.3
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v3.0.3
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 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 3.0.70 3.0.71 3.0.72 All 35 releases
double-opt-in / compatibility / avada / AvadaFormOptions.class.php

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

321 lines 10.3 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 AvadaFormOptions
10 * Add the OptIn Options to the Avada Form
11 *
12 * @package forge12\contactform7\CF7OptIn
13 */
14 class AvadaFormOptions {
15 /**
16 * Admin constructor.
17 */
18 public function __construct() {
19 add_action( 'admin_init', array( $this, 'addHooks' ) );
20 add_action( 'admin_enqueue_scripts', array( $this, 'addStyles' ) );
21 add_action( 'save_post', array( $this, 'save' ), 20, 1 );
22 add_filter( 'awb_po_get_value', array( $this, 'get_value' ), 10, 2 );
23 }
24
25 public function get_value( $ret, $field_id ) {
26 global $post;
27
28 if ( ! $post || ! isset( $post->ID ) ) {
29 return $ret;
30 }
31
32 $metadata = CF7DoubleOptIn::getInstance()->getParameter( $post->ID );
33
34 foreach ( $metadata as $key => $value ) {
35 $metadata[ 'doubleoptin[' . $key . ']' ] = $value;
36 }
37
38 if ( isset( $metadata[ $field_id ] ) ) {
39 $ret = $metadata[ $field_id ];
40 }
41
42 return $ret;
43 }
44
45 /**
46 * Add the styles for the form
47 */
48 public function addStyles( $hook ) {
49 wp_enqueue_style( 'f12-avada-doubleoptin-admin-avada', plugins_url( 'assets/admin-avada-style.css', __FILE__ ) );
50
51 wp_enqueue_script( 'f12-avada-doubleoptin-templateloader', plugins_url( 'assets/f12-avada-templateloader.js', __FILE__ ), array( 'jquery' ) );
52 wp_localize_script( 'f12-avada-doubleoptin-templateloader', 'templateloader', array(
53 'ajax_url' => admin_url( 'admin-ajax.php' ),
54 'nonce' => wp_create_nonce( 'f12_doi_templateloader' ),
55 'label_placeholder' => __( 'Please wait while we load the template...', 'double-opt-in' )
56 ) );
57 }
58
59 /**
60 * Add the hooks responsible to handle wordpress functions
61 */
62 public function addHooks() {
63 add_filter( 'avada_metabox_tabs', array( $this, 'addPanel' ), 10, 2 );
64 add_filter( 'f12_cf7_doubleoptin_avada_form_panel', array( $this, 'render' ), 10, 1 );
65 add_action( 'wpcf7_save_contact_form', array( $this, 'save' ), 10, 3 );
66 }
67
68 /**
69 * Add a custom panel to the contact form 7 options
70 */
71 public function addPanel( array $panels, $post_type ) {
72 global $post;
73
74 if ( $post && $post->post_type == 'fusion_form' ) {
75 if ( $post_type == 'default' ) {
76 $panels['tabs_names']['f12cf7doubleoptin'] = __( 'Double-Opt-in', 'double-opt-in' );
77 $panels['requested_tabs'][] = 'f12cf7doubleoptin';
78 }
79 }
80
81 return $panels;
82 }
83
84 /**
85 * On Contact Form save store the information in the database
86 *
87 * @param $postID
88 */
89 public function save( $postID ) {
90 if ( ! class_exists( '\Fusion_Data_PostMeta' ) ) {
91 return;
92 }
93
94 if ( ! isset( $_POST[ \Fusion_Data_PostMeta::ROOT ] ) || ! isset( $_POST[ \Fusion_Data_PostMeta::ROOT ]['doubleoptin'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
95 return;
96 }
97
98 $parameter = SanitizeHelper::sanitize_array( $_POST[ \Fusion_Data_PostMeta::ROOT ]['doubleoptin'] );
99 $parameter = array_merge( $parameter, SanitizeHelper::sanitize_array( $_POST[ \Fusion_Data_PostMeta::ROOT ]['_doubleoptin'] ) );
100
101 // load the default parameter
102 $metadata = CF7DoubleOptIn::getInstance()->getParameter( $postID );
103
104 // validated all parameter defined in the default parameter options and sanitize them.
105 foreach ( $metadata as $key => $value ) {
106 if ( isset( $parameter[ $key ] ) ) {
107 if ( $key == 'body' ) {
108 $metadata[ $key ] = $parameter[ $key ];
109 } else if ( $key == 'sender' ) {
110 $metadata[ $key ] = $parameter[ $key ];
111 } else if ( $key == 'page' || $key == 'enable' ) {
112 $metadata[ $key ] = (int) $parameter[ $key ];
113 } else {
114 $metadata[ $key ] = sanitize_text_field( $parameter[ $key ] );
115 }
116 } else if ( $key == 'enable' ) {
117 $metadata[ $key ] = 0;
118 }
119 }
120
121 /**
122 * Adjust the Metadata before saving
123 *
124 * @param array $metadata
125 */
126 $metadata = apply_filters( 'f12_cf7_doubleoptin_metadata_avada', $metadata );
127
128 /**
129 * Adjust the Metadata before saving
130 *
131 * @param array $metadata
132 */
133 $metadata = apply_filters( 'f12_cf7_doubleoptin_save_form', $metadata );
134
135 update_post_meta( $postID, 'f12-cf7-doubleoptin', $metadata );
136 }
137
138 /**
139 * @return array
140 */
141 private function getPages() {
142 $value = array();
143 $pages = get_pages();
144 foreach ( $pages as $page ) {
145 $value[ $page->ID ] = $page->post_title;
146 }
147
148 return $value;
149 }
150
151 /**
152 * @return array
153 */
154 private function getCategories() {
155 $atts = array(
156 'perPage' => - 1,
157 'orderBy' => 'name',
158 'order' => 'ASC'
159 );
160
161 $listOfCategories = Category::get_list( $atts, $numberOfPages );
162
163 $value = array(
164 0 => '---'
165 );
166
167 foreach ( $listOfCategories as $Category /** @var Category $Category */ ) {
168 $value[ $Category->get_id() ] = $Category->get_name();
169 }
170
171 return $value;
172 }
173
174 /**
175 * Show the backend double opt in options
176 *
177 * @param array $tab_data
178 *
179 * @return array
180 */
181 public function render( $tab_data ) {
182 global $post;
183 $metadata = CF7DoubleOptIn::getInstance()->getParameter( $post->ID );
184
185 $checked = '';
186 if ( $metadata['enable'] == 1 ) {
187 $checked = 'checked="checked"';
188 }
189
190 $TemplateList = new HTMLSelect( '_fusion[doubleoptin][template]', array(
191 'blank' => 'blank',
192 'newsletter_en' => 'newsletter_en',
193 'newsletter_en_2' => 'newsletter_en_2',
194 'newsletter_en_3' => 'newsletter_en_3'
195 ), array(
196 'class' => array( 'f12-cf7-templateloader' ),
197 'style' => array( 'display:none;' )
198 ) );
199 $TemplateList->setOptionSelectedByKey( $metadata['template'] );
200
201
202 $fields = [
203 [
204 'id' => 'doubleoptin[enable]',
205 'label' => __( 'Enable', 'double-opt-in' ),
206 'value' => [ 1 => __( 'Enable', 'double-opt-in' ) ],
207 'description' => __( 'Enable this checkbox to activate the Double-Opt-In Mail for this formular.', 'double-opt-in' ) . '</p></div><div class="pyre_field"><p><input type="checkbox" id="pyre_doubleoptin[enable]" name="_fusion[doubleoptin][enable]" value="1" ' . $checked . '>',
208 'default' => 0,
209 'dependency' => '',
210 'type' => 'custom'
211 ],
212 [
213 'id' => 'doubleoptin[category]',
214 'label' => __( 'Category', 'double-opt-in' ),
215 'choices' => $this->getCategories(),
216 'description' => __( 'Select the category for the Opt-In.', 'double-opt-in' ),
217 'default' => 0,
218 'dependency' => '',
219 'type' => 'select'
220 ],
221 [
222 'id' => 'doubleoptin[page]',
223 'label' => __( 'Confirmation Page', 'double-opt-in' ),
224 'choices' => $this->getPages(),
225 'description' => __( 'Select the page that should be displayed after the user clicks on the confirmation link', 'double-opt-in' ),
226 'default' => 0,
227 'dependency' => '',
228 'type' => 'select'
229 ],
230 [
231 'id' => 'doubleoptin[recipient]',
232 'label' => __( 'To', 'double-opt-in' ),
233 'description' => __( 'This field defines who will receive the Double-Opt-In mail. Use the "Field Name" defined for the User E-Mail.', 'double-opt-in' ),
234 'default' => '',
235 'dependency' => '',
236 'type' => 'text'
237 ],
238 [
239 'id' => 'doubleoptin[sender]',
240 'label' => __( 'From E-Mail', 'double-opt-in' ),
241 'choices' => $metadata['sender'],
242 'description' => __( 'This field defines who will sent the mail. You can either enter the e-Mail (e.g.: [email protected]) or use a placeholder (e.g.: [_site_admin_email]).', 'double-opt-in' ),
243 'default' => '',
244 'dependency' => '',
245 'type' => 'text'
246 ],
247 [
248 'id' => 'doubleoptin[sender_name]',
249 'label' => __( 'From Name', 'double-opt-in' ),
250 'choices' => $metadata['sender_name'],
251 'description' => __( 'This field defines the name for outgoing mails.', 'double-opt-in' ),
252 'default' => '',
253 'dependency' => '',
254 'type' => 'text'
255 ],
256 [
257 'id' => 'doubleoptin[subject]',
258 'label' => __( 'Subject', 'double-opt-in' ),
259 'choices' => $metadata['subject'],
260 'description' => __( 'Enter a custom subject for the Double-Opt-In mail (e.g.: Please confirm your registration).', 'double-opt-in' ),
261 'default' => '',
262 'dependency' => '',
263 'type' => 'text'
264 ],
265 [
266 'id' => 'doubleoptin[template]',
267 'label' => __( 'Template', 'double-opt-in' ),
268 'description' => __( 'Pick the Template for your double opt-in Mail.', 'double-opt-in' ) . '</p></div><div class="pyre_field"><p>' . $TemplateList->get(),
269 'default' => 0,
270 'dependency' => '',
271 'type' => 'custom'
272 ],
273 /*[
274 'id' => 'doubleoptin[template]',
275 'label' => __('Template', 'double-opt-in'),
276 'choices' => [
277 'blank' => 'Custom',
278 'newsletter_en' => 'Newsletter 1',
279 'newsletter_en_2' => 'Newsletter 2',
280 'newsletter_en_3' => 'Newsletter 3'
281 ],
282 'description' => __('Pick the Template for your double opt in Mail.', 'double-opt-in'),
283 'default' => 'blank',
284 'dependency' => '',
285 'type' => 'select'
286 ],*/
287 [
288 'id' => 'doubleoptin[body]',
289 'label' => __( 'Message body', 'double-opt-in' ),
290 'choices' => $metadata['body'],
291 'description' => __( 'Enter the Message you want to sent to your customer. Do not forget to add the Double-Opt-In tag ([doubleoptinlink]) e.g.: <pre><code>&lt;a href="[doubleoptinlink]"&gt;Confirm the registration&lt;/a&gt;</code></pre>', 'double-opt-in' ),
292 'default' => '',
293 'dependency' => '',
294 'type' => 'textarea'
295 ],
296 ];
297
298 /**
299 * Used to render settings for Avada
300 *
301 * @param array $fields
302 * @param array $metadata
303 *
304 * @since 3.0.0
305 */
306 $tab_data['f12cf7doubleoptin']['fields'] = apply_filters( 'f12_cf7_formular_settings_after_avada', $fields, $metadata );
307
308 return $tab_data;
309 }
310 }
311 }
312
313 /**
314 * Extra Function to use the Avada From Options
315 */
316
317 namespace {
318 function avada_page_options_tab_f12cf7doubleoptin() {
319 return apply_filters( 'f12_cf7_doubleoptin_avada_form_panel', [] );
320 }
321 }