PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.2
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.2
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.2, at classes/class-cartflows-compatibility.php

336 lines 7.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 ( class_exists( 'TCB_Post' ) ) {
58 require_once CARTFLOWS_DIR . 'classes/class-cartflows-thrive-compatibility.php';
59 }
60 }
61
62 /**
63 * Check if elementor preview mode is on.
64 */
65 public function is_elementor_preview_mode() {
66
67 if ( class_exists( '\Elementor\Plugin' ) ) {
68
69 if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
70 return true;
71 }
72 }
73
74 return false;
75 }
76
77 /**
78 * Get Current Theme.
79 */
80 public function get_current_theme() {
81
82 $theme_name = '';
83 $theme = wp_get_theme();
84
85 if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
86 $theme_name = $theme->parent_theme;
87 } else {
88 $theme_name = $theme->name;
89 }
90
91 return $theme_name;
92 }
93
94 /**
95 * Check if it is beaver builder preview mode
96 */
97 public function is_bb_preview_mode() {
98
99 if ( class_exists( 'FLBuilderModel' ) ) {
100 if ( FLBuilderModel::is_builder_active() ) {
101 return true;
102 } else {
103 return false;
104 }
105 }
106
107 return false;
108 }
109
110 /**
111 * Check for page builder preview mode.
112 */
113 public function is_page_builder_preview() {
114
115 if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() ) {
116 return true;
117 }
118
119 return false;
120 }
121
122 /**
123 * Check if divi builder enabled for post id.
124 *
125 * @param int $post_id post id.
126 */
127 public function is_divi_builder_enabled( $post_id ) {
128
129 if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
130 return true;
131 }
132
133 return false;
134 }
135
136 /**
137 * Check if compatibility theme enabled.
138 */
139 function is_compatibility_theme_enabled() {
140
141 $theme = wp_get_theme();
142
143 if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) ) {
144
145 return true;
146 }
147
148 return false;
149 }
150
151 /**
152 * Check if divi builder enabled for post id.
153 *
154 * @param object $theme theme data.
155 * @return boolean
156 */
157 function is_divi_enabled( $theme = false ) {
158
159 if ( ! $theme ) {
160 $theme = wp_get_theme();
161 }
162
163 if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
164 return true;
165 }
166
167 return false;
168 }
169
170 /**
171 * Check if Flatsome enabled for post id.
172 *
173 * @param object $theme theme data.
174 * @return boolean
175 */
176 function is_flatsome_enabled( $theme = false ) {
177
178 if ( ! $theme ) {
179 $theme = wp_get_theme();
180 }
181
182 if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
183 return true;
184 }
185
186 return false;
187 }
188
189 /**
190 * Check if OceanWp enabled for post id.
191 *
192 * @param object $theme theme data.
193 * @return boolean
194 */
195 function is_oceanwp_enabled( $theme = false ) {
196
197 if ( ! $theme ) {
198 $theme = wp_get_theme();
199 }
200
201 if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
202 return true;
203 }
204
205 return false;
206 }
207
208 /**
209 * Check for thrive architect edit page.
210 *
211 * @param int $post_id post id.
212 */
213 public function is_thrive_edit_page( $post_id ) {
214
215 if ( true === $this->is_thrive_builder_page( $post_id ) ) {
216 return true;
217 } else {
218 return false;
219 }
220 }
221
222 /**
223 * Check if the page being rendered is the main ID on the editor page.
224 *
225 * @since 1.0.0
226 * @param String $post_id Post ID which is to be rendered.
227 * @return boolean True if current if is being rendered is not being edited.
228 */
229 private function is_thrive_builder_page( $post_id ) {
230 $tve = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false;
231 $post = isset( $_GET['post'] ) ? sanitize_text_field( $_GET['post'] ) : false;
232
233 return ( true == $tve && $post_id !== $post );
234 }
235
236 /**
237 * Overwrite meta for page
238 */
239 public function override_meta() {
240
241 // don't override meta for `elementor_library` post type.
242 if ( 'elementor_library' == get_post_type() ) {
243 return;
244 }
245
246 if ( ! is_singular() ) {
247 return;
248 }
249
250 global $post;
251 $post_id = $post->ID;
252 $post_type = get_post_type();
253
254 if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
255 || $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
256 || $this->is_divi_builder_enabled( $post_id ) ) ) {
257
258 if ( '' == $post->post_content ) {
259
260 $this->overwrite_template( $post_id );
261 }
262 }
263 }
264
265 /**
266 * Assign cartflow canvas template to page.
267 *
268 * @param int $post_id post ID.
269 */
270 public function overwrite_template( $post_id ) {
271
272 $template = 'cartflows-canvas';
273 $key = '_wp_page_template';
274
275 $record_exists = get_post_meta( $post_id, $key, true );
276
277 if ( 'cartflows-canvas' == $record_exists ) {
278 return;
279 }
280
281 // As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
282 if ( class_exists( '\Elementor\Plugin' ) ) {
283
284 global $wpdb;
285
286 if ( '' == $record_exists || ! $record_exists ) {
287
288 $wpdb->insert(
289 $wpdb->prefix . 'postmeta',
290 array(
291 'post_id' => $post_id,
292 'meta_key' => $key,
293 'meta_value' => $template, // ... and so on
294 )
295 );
296 } else {
297
298 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) );
299 }
300 } else {
301
302 update_post_meta( $post_id, $key, $template );
303 }
304 }
305
306 /**
307 * Load font awesome style from oceanwp on checkout page.
308 */
309 public function load_fontawesome() {
310
311 $theme = get_template();
312
313 if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {
314
315 $load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );
316
317 if ( $load_fa ) {
318
319 wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );
320 }
321
322 $custom_css = '
323 #oceanwp-cart-sidebar-wrap,
324 #owp-qv-wrap{
325 display: none;
326 }';
327
328 wp_add_inline_style( 'wcf-frontend-global', $custom_css );
329 }
330 }
331 }
332 }
333
334 Cartflows_Compatibility::get_instance();
335
336