PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.0
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-functions.php

class-cartflows-functions.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.1.0, at classes/class-cartflows-functions.php

766 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Functions.
4 *
5 * @package CARTFLOWS
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Fatal error mb_strpos fallback.
14 *
15 * @param string $string string where to find.
16 * @param string $search string to search.
17 * @since 1.0.0
18 */
19 function wcf_mb_strpos( $string, $search ) {
20
21 if ( function_exists( 'mb_strpos' ) ) {
22 return mb_strpos( $string, $search, 0, 'utf-8' );
23 } else {
24 return strpos( $string, $search );
25 }
26 }
27
28 /**
29 * Check if cartflows pro activated.
30 *
31 * @since 1.0.0
32 */
33 function _is_cartflows_pro() {
34
35 if ( defined( 'CARTFLOWS_PRO_FILE' ) ) {
36 return true;
37 }
38
39 return false;
40 }
41
42 /**
43 * Check if cartflows pro's license is been activated.
44 *
45 * @since 1.11.8
46 */
47 function _is_cartflows_pro_license_activated() {
48
49 if ( _is_cartflows_pro() && class_exists( 'CartFlows_Pro_Licence' ) ) {
50 return CartFlows_Pro_Licence::get_instance()->activate_status;
51 }
52
53 return false;
54 }
55
56 /**
57 * Returns pro version number.
58 *
59 * @param int $version version number.
60 * @since 1.0.0
61 */
62 function _is_cartflows_pro_ver_less_than( $version ) {
63
64 if ( defined( 'CARTFLOWS_PRO_VER' ) && version_compare( CARTFLOWS_PRO_VER, $version, '<' ) ) {
65 return true;
66 }
67
68 return false;
69 }
70
71 /**
72 * Returns step id.
73 *
74 * @since 1.0.0
75 */
76 function _get_wcf_post_id() {
77
78 global $post;
79
80 if ( isset( $post->ID ) ) {
81 return $post->ID;
82 }
83
84 return 0;
85 }
86
87 /**
88 * Returns step id.
89 *
90 * @since 1.0.0
91 */
92 function _get_wcf_step_id() {
93
94 if ( wcf()->utils->is_step_post_type() ) {
95
96 global $post;
97
98 return $post->ID;
99 }
100
101 return false;
102 }
103
104 /**
105 * Check if it is a landing page?
106 *
107 * @since 1.0.0
108 */
109 function _is_wcf_landing_type() {
110
111 if ( wcf()->utils->is_step_post_type() ) {
112
113 global $post;
114
115 if ( 'landing' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
116
117 return true;
118 }
119 }
120
121 return false;
122 }
123
124 /**
125 * Returns landing id.
126 *
127 * @since 1.0.0
128 */
129 function _get_wcf_landing_id() {
130
131 if ( _is_wcf_landing_type() ) {
132
133 global $post;
134
135 return $post->ID;
136 }
137
138 return false;
139 }
140
141 /**
142 * Is custom checkout?
143 *
144 * @param int $checkout_id checkout ID.
145 * @since 1.0.0
146 */
147 function _is_wcf_meta_custom_checkout( $checkout_id ) {
148
149 $is_custom = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-custom-checkout-fields' );
150
151 if ( 'yes' === $is_custom ) {
152
153 return true;
154 }
155
156 return false;
157 }
158
159 /**
160 * Check if page is cartflow checkout.
161 *
162 * @since 1.0.0
163 * @return bool
164 */
165 function _is_wcf_checkout_type() {
166
167 if ( wcf()->utils->is_step_post_type() ) {
168
169 global $post;
170
171 if ( 'checkout' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
172
173 return true;
174 }
175 }
176
177 return false;
178 }
179
180 /**
181 * Check if AJAX call is in progress.
182 *
183 * @since 1.0.0
184 * @return bool
185 */
186 function _is_wcf_doing_checkout_ajax() {
187
188 //phpcs:disable WordPress.Security.NonceVerification
189 if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) {
190
191 if ( ( isset( $_GET['wc-ajax'] ) && isset( $_POST['_wcf_checkout_id'] ) ) || isset( $_GET['wcf_checkout_id'] )
192 ) {
193 return true;
194 }
195 }
196 //phpcs:enable WordPress.Security.NonceVerification
197
198 return false;
199 }
200
201 /**
202 * Check if optin AJAX call is in progress.
203 *
204 * @since 1.0.0
205 * @return bool
206 */
207 function _is_wcf_doing_optin_ajax() {
208
209 //phpcs:disable WordPress.Security.NonceVerification
210 if ( wp_doing_ajax() || isset( $_GET['wc-ajax'] ) ) {
211
212 if ( isset( $_GET['wc-ajax'] ) &&
213 isset( $_POST['_wcf_optin_id'] )
214 ) {
215 return true;
216 }
217 }
218 //phpcs:enable WordPress.Security.NonceVerification
219
220 return false;
221 }
222
223 /**
224 * Returns checkout ID.
225 *
226 * @since 1.0.0
227 * @return int/bool
228 */
229 function _get_wcf_checkout_id() {
230
231 if ( _is_wcf_checkout_type() ) {
232
233 global $post;
234
235 return $post->ID;
236 }
237
238 return false;
239 }
240
241 /**
242 * Check if it is checkout shortcode.
243 *
244 * @since 1.0.0
245 * @return bool
246 */
247 function _is_wcf_checkout_shortcode() {
248
249 global $post;
250
251 if ( ! empty( $post ) && has_shortcode( $post->post_content, 'cartflows_checkout' ) ) {
252
253 return true;
254 }
255
256 return false;
257 }
258
259 /**
260 * Check if it is checkout shortcode.
261 *
262 * @since 1.0.0
263 * @param string $content shortcode content.
264 * @return bool
265 */
266 function _get_wcf_checkout_id_from_shortcode( $content = '' ) {
267
268 $checkout_id = 0;
269
270 if ( ! empty( $content ) ) {
271
272 $regex_pattern = get_shortcode_regex( array( 'cartflows_checkout' ) );
273
274 preg_match( '/' . $regex_pattern . '/s', $content, $regex_matches );
275
276 if ( ! empty( $regex_matches ) ) {
277
278 if ( 'cartflows_checkout' == $regex_matches[2] ) {
279
280 $attribure_str = str_replace( ' ', '&', trim( $regex_matches[3] ) );
281 $attribure_str = str_replace( '"', '', $attribure_str );
282
283 $attributes = wp_parse_args( $attribure_str );
284
285 if ( isset( $attributes['id'] ) ) {
286 $checkout_id = $attributes['id'];
287 }
288 }
289 }
290 }
291
292 return $checkout_id;
293 }
294
295 /**
296 * Check if post type is upsell.
297 *
298 * @since 1.0.0
299 * @return bool
300 */
301 function _is_wcf_upsell_type() {
302
303 if ( wcf()->utils->is_step_post_type() ) {
304
305 global $post;
306
307 if ( 'upsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
308
309 return true;
310 }
311 }
312
313 return false;
314 }
315
316 /**
317 * Returns upsell ID.
318 *
319 * @since 1.0.0
320 * @return int/bool
321 */
322 function _get_wcf_upsell_id() {
323
324 if ( _is_wcf_upsell_type() ) {
325
326 global $post;
327
328 return $post->ID;
329 }
330
331 return false;
332 }
333
334 /**
335 * Check if post is of type downsell.
336 *
337 * @since 1.0.0
338 * @return int/bool
339 */
340 function _is_wcf_downsell_type() {
341
342 if ( wcf()->utils->is_step_post_type() ) {
343
344 global $post;
345
346 if ( 'downsell' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
347
348 return true;
349 }
350 }
351
352 return false;
353 }
354
355 /**
356 * Get downsell page ID.
357 *
358 * @since 1.0.0
359 * @return int/bool
360 */
361 function _get_wcf_downsell_id() {
362
363 if ( _is_wcf_downsell_type() ) {
364
365 global $post;
366
367 return $post->ID;
368 }
369
370 return false;
371 }
372
373 /**
374 * Check if page is of thank you type.
375 *
376 * @since 1.0.0
377 * @return int/bool
378 */
379 function _is_wcf_thankyou_type() {
380
381 if ( wcf()->utils->is_step_post_type() ) {
382
383 global $post;
384
385 if ( 'thankyou' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
386
387 return true;
388 }
389 }
390
391 return false;
392 }
393
394 /**
395 * Get thank you page ID.
396 *
397 * @since 1.0.0
398 * @return int/bool
399 */
400 function _get_wcf_thankyou_id() {
401
402 if ( _is_wcf_thankyou_type() ) {
403
404 global $post;
405
406 return $post->ID;
407 }
408
409 return false;
410 }
411
412
413 /**
414 * Check if post type is upsell.
415 *
416 * @since 1.0.0
417 * @return bool
418 */
419 function _is_wcf_base_offer_type() {
420
421 $result = false;
422
423 if ( wcf()->utils->is_step_post_type() ) {
424
425 global $post;
426
427 $step_type = get_post_meta( $post->ID, 'wcf-step-type', true );
428
429 if ( 'upsell' === $step_type || 'downsell' === $step_type ) {
430
431 $result = true;
432 }
433 }
434
435 return apply_filters( 'cartflows_is_offer_type', $result );
436 }
437
438 /**
439 * Returns upsell ID.
440 *
441 * @since 1.0.0
442 * @return int/bool
443 */
444 function _get_wcf_base_offer_id() {
445
446 if ( _is_wcf_base_offer_type() ) {
447
448 global $post;
449
450 return $post->ID;
451 }
452
453 return false;
454 }
455
456 /**
457 * Check if page is of optin type.
458 *
459 * @since 1.0.0
460 * @return int/bool
461 */
462 function _is_wcf_optin_type() {
463
464 if ( wcf()->utils->is_step_post_type() ) {
465
466 global $post;
467
468 if ( 'optin' === get_post_meta( $post->ID, 'wcf-step-type', true ) ) {
469
470 return true;
471 }
472 }
473
474 return false;
475 }
476
477 /**
478 * Get optin page ID.
479 *
480 * @since 1.0.0
481 * @return int/bool
482 */
483 function _get_wcf_optin_id() {
484
485 if ( _is_wcf_optin_type() ) {
486
487 global $post;
488
489 return $post->ID;
490 }
491
492 return false;
493 }
494
495 /**
496 * Define a constant if it is not already defined.
497 *
498 * @since 3.0.0
499 * @param string $name Constant name.
500 * @param mixed $value Value.
501 */
502 function wcf_maybe_define_constant( $name, $value ) {
503 if ( ! defined( $name ) ) {
504 define( $name, $value );
505 }
506 }
507
508
509 if ( ! function_exists( 'wp_body_open' ) ) {
510 /**
511 * Fire the wp_body_open action.
512 *
513 * Added for backwards compatibility to support WordPress versions prior to 5.2.0.
514 */
515 function wp_body_open() {
516 /**
517 * Triggered after the opening <body> tag.
518 */
519 do_action( 'wp_body_open' );
520 }
521 }
522
523 /**
524 * Check if type is optin by id.
525 *
526 * @param int $post_id post id.
527 *
528 * @return int/bool
529 * @since 1.0.0
530 */
531 function _wcf_check_is_optin_by_id( $post_id ) {
532
533 if ( 'optin' === get_post_meta( $post_id, 'wcf-step-type', true ) ) {
534
535 return true;
536 }
537
538 return false;
539 }
540
541 /**
542 * Supported Page Template
543 *
544 * @param string $page_template current page template.
545 *
546 * @return int/bool
547 * @since 1.5.7
548 */
549 function _wcf_supported_template( $page_template ) {
550
551 if ( in_array( $page_template, array( 'cartflows-default', 'cartflows-canvas', 'instant-checkout' ), true ) ) {
552
553 return true;
554 }
555
556 return false;
557 }
558
559 /**
560 * Display design Metabox Notice.
561 *
562 * @return string
563 * @since 1.6.15
564 */
565 function wcf_get_page_builder_notice() {
566
567 $notice = '';
568 $page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
569
570 $supported_page_builders = array( 'elementor', 'beaver-builder' );
571
572 $page_builder_data = array(
573 'elementor' => array(
574 'name' => 'Elementor',
575 'doc' => 'https://cartflows.com/docs/elementor-widgets-of-cartflows/?utm_source=dashboard&utm_medium=free-cartflows&utm_campaign=docs',
576 ),
577 'beaver-builder' => array(
578 'name' => 'Beaver Builder',
579 'doc' => 'https://cartflows.com/docs/beaver-builder-modules-of-cartflows/?utm_source=dashboard&utm_medium=free-cartflows&utm_campaign=docs',
580 ),
581 'gutenberg' => array(
582 'name' => 'Gutenebrg',
583 'doc' => 'https://cartflows.com/docs/cartflows-gutenberg-blocks/?utm_source=dashboard&utm_medium=free-cartflows&utm_campaign=docs',
584 ),
585 );
586
587 if ( isset( $page_builder_data[ $page_builder ] ) ) {
588
589 $page_builder_name = $page_builder_data[ $page_builder ]['name'];
590 $doc_link = $page_builder_data[ $page_builder ]['doc'];
591
592 $notice = '<div class="wcf-metabox-notice-wrap"><p class="wcf-metabox-notice wcf-pb-modules-notice">';
593 $notice .= '<span class="dashicons dashicons-info"></span> ';
594 /* translators: %1$s page builder name "string" */
595 $notice .= sprintf( __( 'We have introduced %1$1s widgets for CartFlows shortcodes. Now, you can add/change/update design settings directly from the page builder as well.', 'cartflows' ), $page_builder_name );
596 $notice .= ' <a href="' . $doc_link . '" target="_blank">' . __( 'Learn More »', 'cartflows' ) . '</span></a>';
597 $notice .= '</p></div>';
598 }
599
600 return $notice;
601 }
602
603 /**
604 * Get step type.
605 *
606 * @param int $post_id post id.
607 *
608 * @return bool|string
609 * @since 1.0.0
610 */
611 function wcf_get_step_type( $post_id ) {
612
613 return get_post_meta( $post_id, 'wcf-step-type', true );
614 }
615
616 /**
617 * Get get step object.
618 *
619 * @param int $step_id current step ID.
620 * @since 1.5.9
621 */
622 function wcf_get_step( $step_id ) {
623
624 if ( ! isset( wcf()->wcf_step_objs[ $step_id ] ) ) {
625
626 wcf()->wcf_step_objs[ $step_id ] = new Cartflows_Step_Factory( $step_id );
627 }
628
629 return wcf()->wcf_step_objs[ $step_id ];
630 }
631
632 /**
633 * Check auto-prefill checkout fields feature is enabled or not.
634 *
635 * @return boolean
636 */
637 function is_auto_prefill_checkout_fields_enabled() {
638 return apply_filters( 'cartflows_auto_prefill_checkout_fields', true );
639 }
640
641 /**
642 * Is starter plan.
643 *
644 * @return boolean
645 */
646 function is_wcf_starter_plan() {
647 return defined( 'CARTFLOWS_PRO_PLUGIN_TYPE' ) && CARTFLOWS_PRO_PLUGIN_TYPE === 'starter';
648 }
649
650 /**
651 * Is PRO plan.
652 *
653 * @return boolean
654 */
655 function is_wcf_pro_plan() {
656 return defined( 'CARTFLOWS_PRO_PLUGIN_TYPE' ) && CARTFLOWS_PRO_PLUGIN_TYPE === 'pro';
657 }
658
659 /**
660 * Show notice.
661 *
662 * @param string $title title.
663 * @param string $message description.
664 * @param string $classes classes.
665 */
666 function wcf_feature_notice( $title, $message, $classes ) {
667
668 $image_path = esc_url( CARTFLOWS_URL . 'assets/images/cartflows-logo-small.jpg' );
669
670 $output = '<div class="wcf-notice wcf-dismissible-notice notice notice-info is-dismissible ' . $classes . '">';
671 $output .= '<div class="wcf-notice-container">';
672 $output .= '<img src=' . $image_path . ' class="wcf-notice-custom-logo" alt="CartFlows Icon" itemprop="logo">';
673 $output .= '<div class="wcf-notice-message"><p class="wcf-notice-heading">' . $title . '</p><p class="wcf-notice-description">' . $message . '</p></div>';
674 $output .= '</div>';
675 $output .= '</div>';
676
677 echo wp_kses_post( $output );
678 }
679
680 /**
681 * Get checkout layout type.
682 *
683 * @since 2.1.0
684 * @return string
685 */
686 function wcf_get_checkout_layout() {
687
688 $checkout_id = _is_wcf_checkout_type();
689
690 if ( ! $checkout_id ) {
691 $checkout_id = isset( $_GET['wcf_checkout_id'] ) && ! empty( $_GET['wcf_checkout_id'] ) ? intval( wp_unslash( $_GET['wcf_checkout_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
692 }
693
694 $checkout_layout = 'modern-checkout';
695
696 if ( ! empty( $checkout_id ) ) {
697 // Get checkout layout skin.
698 $checkout_layout = wcf()->options->get_checkout_meta_value( $checkout_id, 'wcf-checkout-layout' );
699 }
700
701 return $checkout_layout;
702 }
703
704 /** Check weather the OttoKit is installed and Connected.
705 *
706 * @return bool
707 */
708 function _is_suretriggers_connected() {
709
710 // Check is the plugin installed.
711 if ( ! defined( 'SURE_TRIGGERS_VER' ) ) {
712 return false;
713 }
714
715 // If installed then check is it connected or not.
716 return apply_filters( 'suretriggers_is_user_connected', '' );
717 }
718
719 /**
720 * Check if the current theme is a block theme OR a FSE Theme.
721 *
722 * @since 2.1.1
723 * @return bool
724 */
725 function wcf_is_current_theme_is_fse_theme() {
726
727 if ( function_exists( 'wp_is_block_theme' ) ) {
728 return boolval( wp_is_block_theme() );
729 }
730
731 return false;
732 }
733
734 /**
735 * Checks if deprecated step notes should be shown.
736 *
737 * This function applies a filter to determine if deprecated step notes should be displayed.
738 *
739 * @return bool Returns true if deprecated step notes should be shown, false otherwise.
740 */
741 function wcf_show_deprecated_step_notes() {
742 return apply_filters( 'cartflows_show_deprecated_step_notes', false );
743 }
744
745 /**
746 * Checks if file modifications are disabled in WordPress.
747 *
748 * This function determines whether file modifications (such as updates and installations)
749 * are disabled by checking the DISALLOW_FILE_MODS constant.
750 *
751 * @since 2.2.0
752 * @return bool True if file modifications are disabled, false otherwise.
753 */
754 function wcf_file_mod_disabled() {
755
756 $is_disabled = false;
757
758 $disallow_file_mods = defined( 'DISALLOW_FILE_MODS' ) ? DISALLOW_FILE_MODS : false;
759
760 if ( apply_filters( 'cartflows_file_mod_disabled', $disallow_file_mods ) ) {
761 $is_disabled = true;
762 }
763
764 return $is_disabled;
765 }
766