PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.3
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.3
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 / compatibilities / class-cartflows-compatibility.php

class-cartflows-compatibility.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.1.3, at compatibilities/class-cartflows-compatibility.php

629 lines 14.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Page builder compatibility
4 *
5 * @package CartFlows
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12 if ( ! class_exists( 'Cartflows_Compatibility' ) ) {
13
14 /**
15 * Class for page builder compatibility
16 */
17 class Cartflows_Compatibility {
18
19 /**
20 * Member Variable
21 *
22 * @var object instance
23 */
24 private static $instance;
25
26 /**
27 * Initiator
28 */
29 public static function get_instance() {
30 if ( ! isset( self::$instance ) ) {
31 self::$instance = new self();
32 }
33 return self::$instance;
34 }
35
36 /**
37 * Constructor
38 */
39 public function __construct() {
40
41 $this->load_compatibility_constants();
42
43 $this->load_files();
44
45 add_action( 'init', array( $this, 'load_cartflows_theme_support' ), 100 );
46
47 // Override post meta.
48 add_action( 'wp', array( $this, 'override_meta' ), 0 );
49
50 add_action( 'wp_enqueue_scripts', array( $this, 'load_fontawesome' ), 10000 );
51
52 add_filter( 'cartflows_admin_localized_vars', array( $this, 'localize_required_compatibility_vars' ), 10, 1 );
53
54 // Let WooCommerce know, CartFlows is compatible with HPOS.
55 add_action( 'before_woocommerce_init', array( $this, 'declare_woo_hpos_compatibility' ) );
56 }
57
58 /**
59 * Load popular theme fallback files.
60 *
61 * @since X.X.X
62 *
63 * @return void
64 */
65 public function load_cartflows_theme_support() {
66
67 if ( defined( 'ASTRA_THEME_VERSION' ) ) {
68
69 /**
70 * Astra
71 */
72 include_once CARTFLOWS_DIR . 'compatibilities/themes/astra/class-cartflows-astra-compatibility.php';
73 }
74 }
75
76 /**
77 * Add localized data for OttoKit
78 *
79 * @param array $localize localized variables.
80 * @return array $localize localized variables.
81 */
82 public function localize_required_compatibility_vars( $localize ) {
83
84 $localize['get_suretriggers_data_nonce'] = wp_create_nonce( 'cartflows_get_suretriggers_data' );
85
86 return $localize;
87 }
88
89 /**
90 * Declare the woo HPOS compatibility.
91 */
92 public function declare_woo_hpos_compatibility() {
93
94 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
95 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', CARTFLOWS_FILE, true );
96 }
97 }
98
99 /**
100 * Define compatibility constants.
101 *
102 * @since 2.1.0
103 * @return void
104 */
105 public function load_compatibility_constants() {
106 define( 'CARTFLOWS_SURETRIGGERS_INTEGRATION_BASE_URL', 'https://app.ottokit.com/' );
107 }
108
109 /**
110 * Load page builder compatibility files
111 */
112 public function load_files() {
113 if ( class_exists( '\Elementor\Plugin' ) ) {
114 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-elementor-compatibility.php';
115 }
116
117 if ( $this->is_divi_enabled() ) {
118 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-divi-compatibility.php';
119 }
120
121 if ( $this->is_bb_enabled() ) {
122 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-bb-compatibility.php';
123 }
124
125 if ( class_exists( 'TCB_Post' ) ) {
126 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-thrive-compatibility.php';
127 }
128
129 if ( defined( 'LEARNDASH_VERSION' ) ) {
130 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-learndash-compatibility.php';
131 }
132
133 if ( defined( 'TUTOR_VERSION' ) ) {
134 require_once CARTFLOWS_DIR . 'compatibilities/plugins/tutor-lms/class-cartflows-tutor-compatibility.php';
135 }
136
137 if ( defined( 'ASTRA_EXT_VER' ) ) {
138 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-astra-addon-compatibility.php';
139 }
140
141 if ( defined( 'POSTNL_WC_PLUGIN_FILE' ) ) {
142 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-postnl-for-woocommerce-compatibility.php';
143 }
144
145 if ( class_exists( 'WC_SC_Coupon_Actions' ) ) {
146 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-smart-coupons-compatibility.php';
147 }
148
149 // Load the gateway support files for the checkout page compatibility.
150 $this->load_gateway_compatibility();
151
152 // Compatibility to allow of Modern Cart to redirect the user to flow from single product page.
153 if ( class_exists( 'ModernCart\Plugin_Loader' ) ) {
154 add_filter(
155 'moderncart_redirect_after_add_to_cart',
156 function ( $allow ) {
157 return 'yes';
158 }
159 );
160 }
161
162 $page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
163
164 if ( $this->is_bricks_enabled() ) {
165 include_once CARTFLOWS_DIR . 'compatibilities/themes/bricks/class-cartflows-bricks-compatibility.php';
166 if ( 'bricks-builder' === $page_builder ) {
167 include_once CARTFLOWS_DIR . 'modules/bricks/class-cartflows-bricks-elements-loader.php';
168 }
169 }
170
171 if ( defined( 'SURE_TRIGGERS_VER' ) ) {
172 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-suretriggers-compatibility.php';
173 }
174
175 // Compatibility file for DPD baltic shipping plugin.
176 if ( defined( 'DPD_NAME_VERSION' ) ) {
177 require_once CARTFLOWS_DIR . 'compatibilities/plugins/class-cartflows-dpd-baltic-compatibility.php';
178 }
179 }
180
181 /**
182 * Loads compatibility files for gateways.
183 *
184 * This function checks for the presence of various gateways and loads their compatibility files if they are active.
185 */
186 public function load_gateway_compatibility() {
187
188 if ( defined( 'WC_STRIPE_VERSION' ) ) {
189 require_once CARTFLOWS_DIR . 'compatibilities/plugins/gateways/class-cartflows-wc-stripe-compatibility.php';
190 }
191 }
192
193 /**
194 * Check if it is beaver builder enabled.
195 *
196 * @since 1.1.4
197 */
198 public function is_bb_enabled() {
199
200 if ( class_exists( 'FLBuilderModel' ) ) {
201 return true;
202 }
203
204 return false;
205 }
206
207 /**
208 * Check if elementor preview mode is on.
209 */
210 public function is_elementor_preview_mode() {
211
212 if ( class_exists( '\Elementor\Plugin' ) ) {
213
214 if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
215 return true;
216 }
217 }
218
219 return false;
220 }
221
222 /**
223 * Get Current Theme.
224 */
225 public function get_current_theme() {
226
227 $theme_name = '';
228 $theme = wp_get_theme();
229
230 if ( ! empty( $theme->parent_theme ) ) {
231 $theme_name = $theme->parent_theme;
232 } else {
233 $theme_name = $theme->name;
234 }
235 return $theme_name;
236 }
237
238 /**
239 * Check if it is beaver builder preview mode
240 */
241 public function is_bb_preview_mode() {
242
243 if ( class_exists( 'FLBuilderModel' ) ) {
244 if ( FLBuilderModel::is_builder_active() ) {
245 return true;
246 } else {
247 return false;
248 }
249 }
250
251 return false;
252 }
253
254 /**
255 * Check for page builder preview mode.
256 */
257 public function is_page_builder_preview() {
258
259 if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() || $this->is_divi_builder_preview() || $this->is_bricks_preview_mode() ) {
260 return true;
261 }
262
263 return false;
264 }
265
266 /**
267 * Check if divi builder enabled.
268 */
269 public function is_divi_builder_preview() {
270
271 if ( isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
272 return true;
273 }
274
275 return false;
276 }
277
278 /**
279 * Check if divi builder enabled for post id.
280 *
281 * @param int $post_id post id.
282 */
283 public function is_divi_builder_enabled( $post_id ) {
284
285 if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
286 return true;
287 }
288
289 return false;
290 }
291
292 /**
293 * Check if compatibility theme enabled.
294 */
295 public function is_compatibility_theme_enabled() {
296
297 $theme = wp_get_theme();
298
299 $is_compatibility = false;
300
301 if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) || $this->is_pro_enabled( $theme ) || $this->is_kallyas_enabled( $theme ) ) {
302
303 $is_compatibility = true;
304 }
305
306 return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
307 }
308
309 /**
310 * Check if pro theme enabled.
311 *
312 * @param object $theme theme data.
313 * @return boolean
314 */
315 public function is_pro_enabled( $theme = false ) {
316
317 if ( ! $theme ) {
318 $theme = wp_get_theme();
319 }
320
321 if ( 'Pro' == $theme->name ) {
322 return true;
323 }
324
325 return false;
326 }
327
328 /**
329 * Check if kallyas theme enabled.
330 *
331 * @param object $theme theme data.
332 * @return boolean
333 */
334 public function is_kallyas_enabled( $theme = false ) {
335
336 if ( ! $theme ) {
337 $theme = wp_get_theme();
338 }
339
340 if ( 'Kallyas' == $theme->name ) {
341 return true;
342 }
343
344 return false;
345 }
346
347 /**
348 * Check if divi builder enabled.
349 *
350 * @param object $theme theme data.
351 * @return boolean
352 */
353 public function is_divi_enabled( $theme = false ) {
354
355 if ( ! $theme ) {
356 $theme = wp_get_theme();
357 }
358
359 if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme || 'Extra' == $theme->name || 'Extra' == $theme->parent_theme ) {
360 return true;
361 }
362
363 return false;
364 }
365
366 /**
367 * Check if Divi theme is install status.
368 *
369 * @return boolean
370 */
371 public function is_divi_theme_installed() {
372 foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
373 if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme || 'Extra' == $theme->name || 'Extra' == $theme->parent_theme ) {
374 return true;
375 }
376 }
377 return false;
378 }
379
380 /**
381 * Check if Flatsome enabled.
382 *
383 * @param object $theme theme data.
384 * @return boolean
385 */
386 public function is_flatsome_enabled( $theme = false ) {
387
388 if ( ! $theme ) {
389 $theme = wp_get_theme();
390 }
391
392 if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
393 return true;
394 }
395
396 return false;
397 }
398
399 /**
400 * Check if The7 enabled.
401 *
402 * @param object $theme theme data.
403 * @return boolean
404 */
405 public function is_the_seven_enabled( $theme = false ) {
406
407 if ( ! $theme ) {
408 $theme = wp_get_theme();
409 }
410
411 if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
412 return true;
413 }
414
415 return false;
416 }
417
418 /**
419 * Check if OceanWp enabled.
420 *
421 * @param object $theme theme data.
422 * @return boolean
423 */
424 public function is_oceanwp_enabled( $theme = false ) {
425
426 if ( ! $theme ) {
427 $theme = wp_get_theme();
428 }
429
430 if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
431 return true;
432 }
433
434 return false;
435 }
436
437 /**
438 * Check if Astra enabled.
439 *
440 * @param object $theme theme data.
441 * @return boolean
442 */
443 public function is_astra_enabled( $theme = false ) {
444
445 if ( ! $theme ) {
446 $theme = wp_get_theme();
447 }
448
449 if ( 'Astra' == $theme->name || 'Astra' == $theme->parent_theme ) {
450 return true;
451 }
452
453 return false;
454 }
455
456 /**
457 * Check if brick builder enabled.
458 *
459 * @return boolean
460 */
461 public static function is_bricks_enabled() {
462
463 $theme = wp_get_theme();
464 if ( 'Bricks' == $theme->name || 'Bricks' == $theme->parent_theme ) {
465 return true;
466 }
467
468 return false;
469 }
470
471 /**
472 * Check if bricks preview mode is on.
473 *
474 * @return boolean
475 */
476 public function is_bricks_preview_mode() {
477
478 return $this->is_bricks_enabled() && function_exists( 'bricks_is_builder' ) && bricks_is_builder();
479 }
480
481 /**
482 * Check for thrive architect edit page.
483 *
484 * @param int $post_id post id.
485 */
486 public function is_thrive_edit_page( $post_id ) {
487
488 if ( true === $this->is_thrive_builder_page( $post_id ) ) {
489 return true;
490 } else {
491 return false;
492 }
493 }
494
495 /**
496 * Check if the page being rendered is the main ID on the editor page.
497 *
498 * @since 1.0.0
499 * @param String $post_id Post ID which is to be rendered.
500 * @return boolean True if current if is being rendered is not being edited.
501 */
502 private function is_thrive_builder_page( $post_id ) {
503 $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
504 $post = isset( $_GET['post'] ) ? intval( wp_unslash( $_GET['post'] ) ) : false; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
505
506 return ( true == $tve && $post_id !== $post );
507 }
508
509 /**
510 * Check if Oxygen builder is enabled.
511 *
512 * @return boolean True if Oxygen builder is enabled, otherwise false.
513 */
514 public static function is_oxygen_builder_enabled() {
515 return defined( 'CT_PLUGIN_MAIN_FILE' );
516 }
517
518 /**
519 * Overwrite meta for page
520 */
521 public function override_meta() {
522
523 // don't override meta for `elementor_library` post type.
524 if ( 'elementor_library' == get_post_type() ) {
525 return;
526 }
527
528 if ( ! is_singular() ) {
529 return;
530 }
531
532 global $post;
533
534 // Return if the Post object is empty. We don't want to throw any errors.
535 if ( empty( $post ) ) {
536 return;
537 }
538
539 $post_id = $post->ID;
540 $post_type = get_post_type();
541
542 if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
543 || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
544 || $this->is_divi_builder_enabled( $post_id ) ) ) {
545
546 if ( '' == $post->post_content ) {
547
548 $this->overwrite_template( $post_id );
549 }
550 }
551 }
552
553 /**
554 * Assign cartflow canvas template to page.
555 *
556 * @param int $post_id post ID.
557 */
558 public function overwrite_template( $post_id ) {
559
560 $template = 'cartflows-canvas';
561 $key = '_wp_page_template';
562
563 $record_exists = get_post_meta( $post_id, $key, true );
564
565 if ( 'cartflows-canvas' == $record_exists ) {
566 return;
567 }
568
569 // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
570 if ( class_exists( '\Elementor\Plugin' ) ) {
571
572 global $wpdb;
573
574 if ( '' == $record_exists || ! $record_exists ) {
575
576 $wpdb->insert(
577 $wpdb->prefix . 'postmeta',
578 array(
579 'post_id' => $post_id,
580 'meta_key' => $key,
581 'meta_value' => $template, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
582 )
583 );// db call ok;.
584
585 // alternative query to above query.
586 // $table = $wpdb->prefix . 'postmeta';
587 // $wpdb->query($wpdb->prepare( "INSERT INTO { $table } ( `post_id`, `meta_key`, 'meta_value' )
588 // VALUES ( '$post_id', '$key', '$template' )" ) );// db call ok; no-cache ok.
589
590 } else {
591
592 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) ); // db call ok; no-cache ok.
593 }
594 } else {
595
596 update_post_meta( $post_id, $key, $template );
597 }
598 }
599
600 /**
601 * Load font awesome style from oceanwp on checkout page.
602 */
603 public function load_fontawesome() {
604
605 $theme = get_template();
606
607 if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
608
609 $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
610
611 if ( $load_fa ) {
612
613 wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', array(), CARTFLOWS_VER );
614 }
615
616 $custom_css = '
617 #oceanwp-cart-sidebar-wrap,
618 #owp-qv-wrap{
619 display: none;
620 }';
621
622 wp_add_inline_style( 'wcf-frontend-global', $custom_css );
623 }
624 }
625 }
626 }
627
628 Cartflows_Compatibility::get_instance();
629