PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.0.4
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.0.4
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / classes / class-cartflows-default-meta.php

class-cartflows-default-meta.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 1.0.4, at classes/class-cartflows-default-meta.php

553 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cartflow default options.
4 *
5 * @package Cartflows
6 */
7
8 /**
9 * Initialization
10 *
11 * @since 1.0.0
12 */
13 class Cartflows_Default_Meta {
14
15
16 /**
17 * Member Variable
18 *
19 * @var instance
20 */
21 private static $instance;
22
23 /**
24 * Member Variable
25 *
26 * @var checkout_fields
27 */
28 private static $checkout_fields = null;
29
30 /**
31 * Member Variable
32 *
33 * @var checkout_fields
34 */
35 private static $thankyou_fields = null;
36
37
38 /**
39 * Member Variable
40 *
41 * @var flow_fields
42 */
43 private static $flow_fields = null;
44
45 /**
46 * Initiator
47 */
48 public static function get_instance() {
49 if ( ! isset( self::$instance ) ) {
50 self::$instance = new self;
51 }
52 return self::$instance;
53 }
54
55 /**
56 * Constructor
57 */
58 public function __construct() {
59
60 }
61
62 /**
63 * Checkout Default fields.
64 *
65 * @param int $post_id post id.
66 * @return array
67 */
68 function get_checkout_fields( $post_id ) {
69
70 if ( null === self::$checkout_fields ) {
71
72 self::$checkout_fields = array(
73 'wcf-field-google-font-url' => array(
74 'default' => '',
75 'sanitize' => 'FILTER_DEFAULT',
76 ),
77 'wcf-checkout-products' => array(
78 'default' => array(),
79 'sanitize' => 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS',
80 ),
81 'wcf-checkout-layout' => array(
82 'default' => 'two-column',
83 'sanitize' => 'FILTER_DEFAULT',
84 ),
85 'wcf-input-font-family' => array(
86 'default' => '',
87 'sanitize' => 'FILTER_DEFAULT',
88 ),
89 'wcf-input-font-weight' => array(
90 'default' => '',
91 'sanitize' => 'FILTER_DEFAULT',
92 ),
93 'wcf-heading-font-family' => array(
94 'default' => '',
95 'sanitize' => 'FILTER_DEFAULT',
96 ),
97 'wcf-heading-font-weight' => array(
98 'default' => '',
99 'sanitize' => 'FILTER_DEFAULT',
100 ),
101 'wcf-base-font-family' => array(
102 'default' => '',
103 'sanitize' => 'FILTER_DEFAULT',
104 ),
105 'wcf-advance-options-fields' => array(
106 'default' => '',
107 'sanitize' => 'FILTER_DEFAULT',
108 ),
109 'wcf-base-font-weight' => array(
110 'default' => '',
111 'sanitize' => 'FILTER_DEFAULT',
112 ),
113 'wcf-button-font-family' => array(
114 'default' => '',
115 'sanitize' => 'FILTER_DEFAULT',
116 ),
117 'wcf-button-font-weight' => array(
118 'default' => '',
119 'sanitize' => 'FILTER_DEFAULT',
120 ),
121 'wcf-primary-color' => array(
122 'default' => '',
123 'sanitize' => 'FILTER_DEFAULT',
124 ),
125 'wcf-heading-color' => array(
126 'default' => '',
127 'sanitize' => 'FILTER_DEFAULT',
128 ),
129 'wcf-section-bg-color' => array(
130 'default' => '',
131 'sanitize' => 'FILTER_DEFAULT',
132 ),
133 'wcf-hl-bg-color' => array(
134 'default' => '',
135 'sanitize' => 'FILTER_DEFAULT',
136 ),
137 'wcf-field-tb-padding' => array(
138 'default' => '',
139 'sanitize' => 'FILTER_DEFAULT',
140 ),
141 'wcf-field-lr-padding' => array(
142 'default' => '',
143 'sanitize' => 'FILTER_DEFAULT',
144 ),
145 'wcf-fields-skins' => array(
146 'default' => '',
147 'sanitize' => 'FILTER_DEFAULT',
148 ),
149 'wcf-input-field-size' => array(
150 'default' => '33px',
151 'sanitize' => 'FILTER_DEFAULT',
152 ),
153 'wcf-field-color' => array(
154 'default' => '',
155 'sanitize' => 'FILTER_DEFAULT',
156 ),
157 'wcf-field-bg-color' => array(
158 'default' => '',
159 'sanitize' => 'FILTER_DEFAULT',
160 ),
161 'wcf-field-border-color' => array(
162 'default' => '',
163 'sanitize' => 'FILTER_DEFAULT',
164 ),
165 'wcf-box-border-color' => array(
166 'default' => '',
167 'sanitize' => 'FILTER_DEFAULT',
168 ),
169 'wcf-field-label-color' => array(
170 'default' => '',
171 'sanitize' => 'FILTER_DEFAULT',
172 ),
173 'wcf-submit-tb-padding' => array(
174 'default' => '',
175 'sanitize' => 'FILTER_DEFAULT',
176 ),
177 'wcf-submit-lr-padding' => array(
178 'default' => '',
179 'sanitize' => 'FILTER_DEFAULT',
180 ),
181 'wcf-input-button-size' => array(
182 'default' => '33px',
183 'sanitize' => 'FILTER_DEFAULT',
184 ),
185 'wcf-submit-color' => array(
186 'default' => '',
187 'sanitize' => 'FILTER_DEFAULT',
188 ),
189 'wcf-submit-hover-color' => array(
190 'default' => '',
191 'sanitize' => 'FILTER_DEFAULT',
192 ),
193 'wcf-submit-bg-color' => array(
194 'default' => '',
195 'sanitize' => 'FILTER_DEFAULT',
196 ),
197 'wcf-submit-bg-hover-color' => array(
198 'default' => '',
199 'sanitize' => 'FILTER_DEFAULT',
200 ),
201 'wcf-submit-border-color' => array(
202 'default' => '',
203 'sanitize' => 'FILTER_DEFAULT',
204 ),
205 'wcf-submit-border-hover-color' => array(
206 'default' => '',
207 'sanitize' => 'FILTER_DEFAULT',
208 ),
209 'wcf-active-tab' => array(
210 'default' => '',
211 'sanitize' => 'FILTER_DEFAULT',
212 ),
213 'wcf-header-logo-image' => array(
214 'default' => '',
215 'sanitize' => 'FILTER_DEFAULT',
216 ),
217 'wcf-header-logo-width' => array(
218 'default' => '',
219 'sanitize' => 'FILTER_DEFAULT',
220 ),
221 );
222
223 self::$checkout_fields = apply_filters( 'cartflows_checkout_meta_options', self::$checkout_fields, $post_id );
224 }
225
226 return self::$checkout_fields;
227 }
228
229 /**
230 * Save Checkout Meta fields.
231 *
232 * @param int $post_id post id.
233 * @return void
234 */
235 function save_checkout_fields( $post_id ) {
236
237 $post_meta = $this->get_checkout_fields( $post_id );
238
239 $this->save_meta_fields( $post_id, $post_meta );
240 }
241
242 /**
243 * Flow Default fields.
244 *
245 * @param int $post_id post id.
246 * @return array
247 */
248 function get_flow_fields( $post_id ) {
249
250 if ( null === self::$flow_fields ) {
251
252 self::$flow_fields = array(
253 'wcf-steps' => array(
254 'default' => array(),
255 'sanitize' => 'FILTER_DEFAULT',
256 ),
257
258 'wcf-testing' => array(
259 'default' => 'yes',
260 'sanitize' => 'FILTER_DEFAULT',
261 ),
262 );
263 }
264
265 return apply_filters( 'cartflows_flow_meta_options', self::$flow_fields );
266 }
267
268 /**
269 * Save Flow Meta fields.
270 *
271 * @param int $post_id post id.
272 * @return void
273 */
274 function save_flow_fields( $post_id ) {
275
276 $post_meta = $this->get_flow_fields( $post_id );
277
278 if ( isset( $post_meta['wcf-steps'] ) ) {
279 unset( $post_meta['wcf-steps'] );
280 }
281
282 $this->save_meta_fields( $post_id, $post_meta );
283 }
284
285 /**
286 * Save Meta fields - Common Function.
287 *
288 * @param int $post_id post id.
289 * @param array $post_meta options to store.
290 * @return void
291 */
292 function save_meta_fields( $post_id, $post_meta ) {
293
294 if ( ! ( $post_id && is_array( $post_meta ) ) ) {
295
296 return;
297 }
298
299 foreach ( $post_meta as $key => $data ) {
300
301 $meta_value = false;
302
303 // Sanitize values.
304 $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT';
305
306 switch ( $sanitize_filter ) {
307
308 case 'FILTER_SANITIZE_STRING':
309 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
310 break;
311
312 case 'FILTER_SANITIZE_URL':
313 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
314 break;
315
316 case 'FILTER_SANITIZE_NUMBER_INT':
317 $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
318 break;
319
320 case 'FILTER_CARTFLOWS_ARRAY':
321 if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
322 $meta_value = array_map( 'sanitize_text_field', $_POST[ $key ] );
323 }
324 break;
325
326 case 'FILTER_CARTFLOWS_CHECKOUT_PRODUCTS':
327 if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
328
329 $i = 0;
330 $q = 0;
331
332 foreach ( $_POST[ $key ] as $p_index => $p_data ) {
333
334 foreach ( $p_data as $i_key => $i_value ) {
335
336 if ( is_array( $i_value ) ) {
337
338 foreach ( $i_value as $q_key => $q_value ) {
339
340 $meta_value[ $i ][ $i_key ][ $q ] = array_map( 'sanitize_text_field', $q_value );
341
342 $q++;
343 }
344 } else {
345 $meta_value[ $i ][ $i_key ] = sanitize_text_field( $i_value );
346 }
347 }
348
349 $i++;
350 }
351 }
352 break;
353
354 default:
355 $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
356 break;
357 }
358
359 if ( false !== $meta_value ) {
360 update_post_meta( $post_id, $key, $meta_value );
361 } else {
362 delete_post_meta( $post_id, $key );
363 }
364 }
365 }
366
367 /**
368 * Get checkout meta.
369 *
370 * @param int $post_id post id.
371 * @param string $key options key.
372 * @param mix $default options default value.
373 * @return string
374 */
375 function get_flow_meta_value( $post_id, $key, $default = false ) {
376
377 $value = $this->get_save_meta( $post_id, $key );
378
379 if ( ! $value ) {
380
381 if ( $default ) {
382
383 $value = $default;
384 } else {
385
386 $fields = $this->get_flow_fields( $post_id );
387
388 if ( isset( $fields[ $key ]['default'] ) ) {
389
390 $value = $fields[ $key ]['default'];
391 }
392 }
393 }
394
395 return $value;
396 }
397
398 /**
399 * Get checkout meta.
400 *
401 * @param int $post_id post id.
402 * @param string $key options key.
403 * @param mix $default options default value.
404 * @return string
405 */
406 function get_checkout_meta_value( $post_id = 0, $key = '', $default = false ) {
407
408 $value = $this->get_save_meta( $post_id, $key );
409
410 if ( ! $value ) {
411
412 if ( $default ) {
413
414 $value = $default;
415 } else {
416
417 $fields = $this->get_checkout_fields( $post_id );
418
419 if ( isset( $fields[ $key ]['default'] ) ) {
420
421 $value = $fields[ $key ]['default'];
422 }
423 }
424 }
425
426 return $value;
427 }
428
429 /**
430 * Get post meta.
431 *
432 * @param int $post_id post id.
433 * @param string $key options key.
434 * @return string
435 */
436 function get_save_meta( $post_id, $key ) {
437
438 $value = get_post_meta( $post_id, $key, true );
439
440 return $value;
441 }
442
443 /**
444 * Thank You Default fields.
445 *
446 * @param int $post_id post id.
447 * @return array
448 */
449 function get_thankyou_fields( $post_id ) {
450
451 if ( null === self::$thankyou_fields ) {
452
453 self::$thankyou_fields = array(
454 'wcf-field-google-font-url' => array(
455 'default' => '',
456 'sanitize' => 'FILTER_DEFAULT',
457 ),
458 'wcf-active-tab' => array(
459 'default' => '',
460 'sanitize' => 'FILTER_DEFAULT',
461 ),
462 'wcf-tq-text-color' => array(
463 'default' => '',
464 'sanitize' => 'FILTER_DEFAULT',
465 ),
466 'wcf-tq-font-family' => array(
467 'default' => '',
468 'sanitize' => 'FILTER_DEFAULT',
469 ),
470 'wcf-tq-heading-color' => array(
471 'default' => '',
472 'sanitize' => 'FILTER_DEFAULT',
473 ),
474 'wcf-tq-heading-font-family' => array(
475 'default' => '',
476 'sanitize' => 'FILTER_DEFAULT',
477 ),
478 'wcf-tq-heading-font-wt' => array(
479 'default' => '',
480 'sanitize' => 'FILTER_DEFAULT',
481 ),
482 'wcf-tq-container-width' => array(
483 'default' => '',
484 'sanitize' => 'FILTER_DEFAULT',
485 ),
486 'wcf-tq-section-bg-color' => array(
487 'default' => '',
488 'sanitize' => 'FILTER_DEFAULT',
489 ),
490 'wcf-tq-advance-options-fields' => array(
491 'default' => '',
492 'sanitize' => 'FILTER_DEFAULT',
493 ),
494 'wcf-show-overview-section' => array(
495 'default' => 'yes',
496 'sanitize' => 'FILTER_DEFAULT',
497 ),
498 'wcf-show-details-section' => array(
499 'default' => 'yes',
500 'sanitize' => 'FILTER_DEFAULT',
501 ),
502 'wcf-show-billing-section' => array(
503 'default' => 'yes',
504 'sanitize' => 'FILTER_DEFAULT',
505 ),
506 'wcf-show-shipping-section' => array(
507 'default' => 'yes',
508 'sanitize' => 'FILTER_DEFAULT',
509 ),
510 );
511
512 }
513
514 return apply_filters( 'cartflows_thankyou_meta_options', self::$thankyou_fields, $post_id );
515 }
516
517 /**
518 * Get Thank you section meta.
519 *
520 * @param int $post_id post id.
521 * @param string $key options key.
522 * @param mix $default options default value.
523 * @return string
524 */
525 function get_thankyou_meta_value( $post_id, $key, $default = false ) {
526
527 $value = $this->get_save_meta( $post_id, $key );
528
529 if ( ! $value ) {
530
531 if ( $default ) {
532
533 $value = $default;
534 } else {
535
536 $fields = $this->get_thankyou_fields( $post_id );
537
538 if ( isset( $fields[ $key ]['default'] ) ) {
539
540 $value = $fields[ $key ]['default'];
541 }
542 }
543 }
544
545 return $value;
546 }
547 }
548
549 /**
550 * Kicking this off by calling 'get_instance()' method
551 */
552 Cartflows_Default_Meta::get_instance();
553