# cartflows/1.1.1/classes/class-cartflows-compatibility.php

CartFlows – Funnel Builder &amp; Checkout Plugin for WooCommerce, version 1.1.1. 332 lines.

- Page: https://pluginprobe.com/plugins/cartflows/1.1.1/code/classes/class-cartflows-compatibility.php
- Raw: https://pluginprobe.com/plugins/cartflows/1.1.1/raw/classes/class-cartflows-compatibility.php
- Modified: 2019-01-02T12:49:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/cartflows/1.1.1/code/classes/class-cartflows-compatibility.php#L10-L20`.

```php
<?php
/**
 * Page builder compatibility
 *
 * @package CartFlows
 */

if ( ! class_exists( 'Cartflows_Compatibility' ) ) {

	/**
	 * Class for page builder compatibility
	 */
	class Cartflows_Compatibility {

		/**
		 * Member Variable
		 *
		 * @var object instance
		 */
		private static $instance;

		/**
		 *  Initiator
		 */
		public static function get_instance() {
			if ( ! isset( self::$instance ) ) {
				self::$instance = new self;
			}
			return self::$instance;
		}

		/**
		 *  Constructor
		 */
		public function __construct() {

			$this->load_files();

			// Override post meta.
			add_action( 'wp', array( $this, 'override_meta' ), 0 );

			add_action( 'wp_enqueue_scripts', array( $this, 'load_fontawesome' ), 10000 );
		}

		/**
		 *  Load page builder compatibility files
		 */
		public function load_files() {
			if ( class_exists( '\Elementor\Plugin' ) ) {
				require_once CARTFLOWS_DIR . 'classes/class-cartflows-elementor-compatibility.php';
			}

			if ( $this->is_divi_enabled() ) {
				require_once CARTFLOWS_DIR . 'classes/class-cartflows-divi-compatibility.php';
			}
		}

		/**
		 *  Check if elementor preview mode is on.
		 */
		public function is_elementor_preview_mode() {

			if ( class_exists( '\Elementor\Plugin' ) ) {

				if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
					return true;
				}
			}

			return false;
		}

		/**
		 *  Get Current Theme.
		 */
		public function get_current_theme() {

			$theme_name = '';
			$theme      = wp_get_theme();

			if ( isset( $theme->parent_theme ) && '' != $theme->parent_theme || null != $theme->parent_theme ) {
				$theme_name = $theme->parent_theme;
			} else {
				$theme_name = $theme->name;
			}

			return $theme_name;
		}

		/**
		 *  Check if it is beaver builder preview mode
		 */
		public function is_bb_preview_mode() {

			if ( class_exists( 'FLBuilderModel' ) ) {
				if ( FLBuilderModel::is_builder_active() ) {
					return true;
				} else {
					return false;
				}
			}

			return false;
		}

		/**
		 *  Check for page builder preview mode.
		 */
		public function is_page_builder_preview() {

			if ( $this->is_elementor_preview_mode() || $this->is_bb_preview_mode() ) {
				return true;
			}

			return false;
		}

		/**
		 *  Check if divi builder enabled for post id.
		 *
		 * @param int $post_id post id.
		 */
		public function is_divi_builder_enabled( $post_id ) {

			if ( function_exists( 'et_pb_is_pagebuilder_used' ) && et_pb_is_pagebuilder_used( $post_id ) ) {
				return true;
			}

			return false;
		}

		/**
		 * Check if compatibility theme enabled.
		 */
		function is_compatibility_theme_enabled() {

			$theme = wp_get_theme();

			if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) || $this->is_oceanwp_enabled( $theme ) ) {

				return true;
			}

			return false;
		}

		/**
		 * Check if divi builder enabled for post id.
		 *
		 * @param object $theme theme data.
		 * @return boolean
		 */
		function is_divi_enabled( $theme = false ) {

			if ( ! $theme ) {
				$theme = wp_get_theme();
			}

			if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme ) {
				return true;
			}

			return false;
		}

		/**
		 * Check if Flatsome enabled for post id.
		 *
		 * @param object $theme theme data.
		 * @return boolean
		 */
		function is_flatsome_enabled( $theme = false ) {

			if ( ! $theme ) {
				$theme = wp_get_theme();
			}

			if ( 'Flatsome' == $theme->name || 'Flatsome' == $theme->parent_theme ) {
				return true;
			}

			return false;
		}

		/**
		 * Check if OceanWp enabled for post id.
		 *
		 * @param object $theme theme data.
		 * @return boolean
		 */
		function is_oceanwp_enabled( $theme = false ) {

			if ( ! $theme ) {
				$theme = wp_get_theme();
			}

			if ( 'OceanWP' == $theme->name || 'OceanWP' == $theme->parent_theme ) {
				return true;
			}

			return false;
		}

		/**
		 *  Check for thrive architect edit page.
		 *
		 * @param int $post_id post id.
		 */
		public function is_thrive_edit_page( $post_id ) {

			if ( true === $this->is_thrive_builder_page( $post_id ) ) {
				return true;
			} else {
				return false;
			}
		}

		/**
		 * Check if the page being rendered is the main ID on the editor page.
		 *
		 * @since 1.0.0
		 * @param String $post_id  Post ID which is to be rendered.
		 * @return boolean True if current if is being rendered is not being edited.
		 */
		private function is_thrive_builder_page( $post_id ) {
			$tve  = ( isset( $_GET['tve'] ) && 'true' == $_GET['tve'] ) ? true : false;
			$post = isset( $_GET['post'] ) ? sanitize_text_field( $_GET['post'] ) : false;

			return ( true == $tve && $post_id !== $post );
		}

		/**
		 *  Overwrite meta for page
		 */
		public function override_meta() {

			// don't override meta for `elementor_library` post type.
			if ( 'elementor_library' == get_post_type() ) {
				return;
			}

			if ( ! is_singular() ) {
				return;
			}

			global $post;
			$post_id   = $post->ID;
			$post_type = get_post_type();

			if ( 'cartflows_step' == $post_type && ( $this->is_elementor_preview_mode()
			|| $this->is_bb_preview_mode() || $this->is_thrive_edit_page( $post_id )
			|| $this->is_divi_builder_enabled( $post_id ) ) ) {

				if ( '' == $post->post_content ) {

					$this->overwrite_template( $post_id );
				}
			}
		}

		/**
		 *  Assign cartflow canvas template to page.
		 *
		 * @param int $post_id post ID.
		 */
		public function overwrite_template( $post_id ) {

			$template = 'cartflows-canvas';
			$key      = '_wp_page_template';

			$record_exists = get_post_meta( $post_id, $key, true );

			if ( 'cartflows-canvas' == $record_exists ) {
				return;
			}

			// As elementor doesn't allow update post meta using update_post_meta, run wpdb query to update post meta.
			if ( class_exists( '\Elementor\Plugin' ) ) {

				global $wpdb;

				if ( '' == $record_exists || ! $record_exists ) {

					$wpdb->insert(
						$wpdb->prefix . 'postmeta',
						array(
							'post_id'    => $post_id,
							'meta_key'   => $key,
							'meta_value' => $template, // ... and so on
						)
					);
				} else {

					$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s;", $template, $key, $post_id ) );
				}
			} else {

				update_post_meta( $post_id, $key, $template );
			}
		}

		/**
		 * Load font awesome style from oceanwp on checkout page.
		 */
		public function load_fontawesome() {

			$theme = get_template();

			if ( 'oceanwp' == strtolower( $theme ) && wcf()->utils->is_step_post_type() ) {

				$load_fa = apply_filters( 'cartflows_maybe_load_font_awesome', true );

				if ( $load_fa ) {

					wp_enqueue_style( 'font-awesome', OCEANWP_CSS_DIR_URI . 'third/font-awesome.min.css', false );
				}

				$custom_css = '
                #oceanwp-cart-sidebar-wrap,
                #owp-qv-wrap{
                    display: none;
                }';

				wp_add_inline_style( 'wcf-frontend-global', $custom_css );
			}
		}
	}
}

Cartflows_Compatibility::get_instance();


```
