PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.15
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.15
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-compatibility.php

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

401 lines 8.3 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 if ( ! class_exists( 'Cartflows_Compatibility' ) ) {
9
10 /**
11 * Class for page builder compatibility
12 */
13 class Cartflows_Compatibility {
14
15 /**
16 * Member Variable
17 *
18 * @var object instance
19 */
20 private static $instance;
21
22 /**
23 * Initiator
24 */
25 public static function get_instance() {
26 if ( ! isset( self::$instance ) ) {
27 self::$instance = new self;
28 }
29 return self::$instance;
30 }
31
32 /**
33 * Constructor
34 */
35 public function __construct() {
36
37 $this->load_files();
38
39 // Override post meta.
40 add_action( 'wp', array( $this, 'override_meta' ), 0 );
41
42 add_action( 'wp_enqueue_scripts', array( $this, 'load_fontawesome' ), 10000 );
43 }
44
45 /**
46 * Load page builder compatibility files
47 */
48 public function load_files() {
49 if ( class_exists( '\Elementor\Plugin' ) ) {
50 require_once CARTFLOWS_DIR . 'classes/class-cartflows-elementor-compatibility.php';
51 }
52
53 if ( $this->is_divi_enabled() ) {
54 require_once CARTFLOWS_DIR . 'classes/class-cartflows-divi-compatibility.php';
55 }
56
57 if ( $this->is_bb_enabled() ) {
58 require_once CARTFLOWS_DIR . 'classes/class-cartflows-bb-compatibility.php';
59 }
60
61 if ( class_exists( 'TCB_Post' ) ) {
62 require_once CARTFLOWS_DIR . 'classes/class-cartflows-thrive-compatibility.php';
63 }
64 }
65
66 /**
67 * Check if it is beaver builder enabled.
68 *
69 * @since 1.1.4
70 */
71 public function is_bb_enabled() {
72
73 if ( class_exists( 'FLBuilderModel' ) ) {
74 return true;
75 }
76
77 return false;
78 }
79
80 /**
81 * Check if elementor preview mode is on.
82 */
83 public function is_elementor_preview_mode() {
84
85 if ( class_exists( '\Elementor\Plugin' ) ) {
86
87 if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
88 return true;
89 }
90 }
91
92 return false;
93 }
94
95 /**
96 * Get Current Theme.
97 */
98 public function get_current_theme() {
99
100 $theme_name = '';
101 $theme = wp_get_theme();
102
103 if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
104 $theme_name = $theme->parent_theme;
105 } else {
106 $theme_name = $theme->name;
107 }
108
109 return $theme_name;
110 }
111
112 /**
113 * Check if it is beaver builder preview mode
114 */
115 public function is_bb_preview_mode() {
116
117 if ( class_exists( 'FLBuilderModel' ) ) {
118 if ( FLBuilderModel::is_builder_active() ) {
119 return true;
120 } else {
121 return false;
122 }
123 }
124
125 return false;
126 }
127
128 /**
129 * Check for page builder preview mode.
130 */
131 public function is_page_builder_preview() {
132
133 if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() || $this->is_divi_builder_preview() ) {
134 return true;
135 }
136
137 return false;
138 }
139
140 /**
141 * Check if divi builder enabled for post id.
142 */
143 public function is_divi_builder_preview() {
144
145 if ( isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] ) {
146 return true;
147 }
148
149 return false;
150 }
151
152 /**
153 * Check if divi builder enabled for post id.
154 *
155 * @param int $post_id post id.
156 */
157 public function is_divi_builder_enabled( $post_id ) {
158
159 if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
160 return true;
161 }
162
163 return false;
164 }
165
166 /**
167 * Check if compatibility theme enabled.
168 */
169 function is_compatibility_theme_enabled() {
170
171 $theme = wp_get_theme();
172
173 $is_compatibility = false;
174
175 if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) ) {
176
177 $is_compatibility = true;
178 }
179
180 return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
181 }
182
183 /**
184 * Check if divi builder enabled for post id.
185 *
186 * @param object $theme theme data.
187 * @return boolean
188 */
189 function is_divi_enabled( $theme = false ) {
190
191 if ( ! $theme ) {
192 $theme = wp_get_theme();
193 }
194
195 if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
196 return true;
197 }
198
199 return false;
200 }
201
202 /**
203 * Check if Divi theme is install status.
204 *
205 * @return boolean
206 */
207 function is_divi_theme_installed() {
208 foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
209 if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
210 return true;
211 }
212 }
213 return false;
214 }
215
216 /**
217 * Check if Flatsome enabled for post id.
218 *
219 * @param object $theme theme data.
220 * @return boolean
221 */
222 function is_flatsome_enabled( $theme = false ) {
223
224 if ( ! $theme ) {
225 $theme = wp_get_theme();
226 }
227
228 if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
229 return true;
230 }
231
232 return false;
233 }
234
235 /**
236 * Check if The7 enabled for post id.
237 *
238 * @param object $theme theme data.
239 * @return boolean
240 */
241 function is_the_seven_enabled( $theme = false ) {
242
243 if ( ! $theme ) {
244 $theme = wp_get_theme();
245 }
246
247 if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
248 return true;
249 }
250
251 return false;
252 }
253
254 /**
255 * Check if OceanWp enabled for post id.
256 *
257 * @param object $theme theme data.
258 * @return boolean
259 */
260 function is_oceanwp_enabled( $theme = false ) {
261
262 if ( ! $theme ) {
263 $theme = wp_get_theme();
264 }
265
266 if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
267 return true;
268 }
269
270 return false;
271 }
272
273 /**
274 * Check for thrive architect edit page.
275 *
276 * @param int $post_id post id.
277 */
278 public function is_thrive_edit_page( $post_id ) {
279
280 if ( true === $this->is_thrive_builder_page( $post_id ) ) {
281 return true;
282 } else {
283 return false;
284 }
285 }
286
287 /**
288 * Check if the page being rendered is the main ID on the editor page.
289 *
290 * @since 1.0.0
291 * @param String $post_id Post ID which is to be rendered.
292 * @return boolean True if current if is being rendered is not being edited.
293 */
294 private function is_thrive_builder_page( $post_id ) {
295 $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false;
296 $post = isset( $_GET['post'] ) ? sanitize_text_field( $_GET['post'] ) : false;
297
298 return ( true == $tve && $post_id !== $post );
299 }
300
301 /**
302 * Overwrite meta for page
303 */
304 public function override_meta() {
305
306 // don't override meta for `elementor_library` post type.
307 if ( 'elementor_library' == get_post_type() ) {
308 return;
309 }
310
311 if ( ! is_singular() ) {
312 return;
313 }
314
315 global $post;
316 $post_id = $post->ID;
317 $post_type = get_post_type();
318
319 if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
320 || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
321 || $this->is_divi_builder_enabled( $post_id ) ) ) {
322
323 if ( '' == $post->post_content ) {
324
325 $this->overwrite_template( $post_id );
326 }
327 }
328 }
329
330 /**
331 * Assign cartflow canvas template to page.
332 *
333 * @param int $post_id post ID.
334 */
335 public function overwrite_template( $post_id ) {
336
337 $template = 'cartflows-canvas';
338 $key = '_wp_page_template';
339
340 $record_exists = get_post_meta( $post_id, $key, true );
341
342 if ( 'cartflows-canvas' == $record_exists ) {
343 return;
344 }
345
346 // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
347 if ( class_exists( '\Elementor\Plugin' ) ) {
348
349 global $wpdb;
350
351 if ( '' == $record_exists || ! $record_exists ) {
352
353 $wpdb->insert(
354 $wpdb->prefix . 'postmeta',
355 array(
356 'post_id' => $post_id,
357 'meta_key' => $key,
358 'meta_value' => $template, // ... and so on
359 )
360 );
361 } else {
362
363 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) );
364 }
365 } else {
366
367 update_post_meta( $post_id, $key, $template );
368 }
369 }
370
371 /**
372 * Load font awesome style from oceanwp on checkout page.
373 */
374 public function load_fontawesome() {
375
376 $theme = get_template();
377
378 if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
379
380 $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
381
382 if ( $load_fa ) {
383
384 wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );
385 }
386
387 $custom_css = '
388 #oceanwp-cart-sidebar-wrap,
389 #owp-qv-wrap{
390 display: none;
391 }';
392
393 wp_add_inline_style( 'wcf-frontend-global', $custom_css );
394 }
395 }
396 }
397 }
398
399 Cartflows_Compatibility::get_instance();
400
401