<?php
/**
* Page builder compatibility
*
* @package CartFlows
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
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';
}
if ( $this->is_bb_enabled() ) {
require_once CARTFLOWS_DIR . 'classes/class-cartflows-bb-compatibility.php';
}
if ( class_exists( 'TCB_Post' ) ) {
require_once CARTFLOWS_DIR . 'classes/class-cartflows-thrive-compatibility.php';
}
if ( defined( 'LEARNDASH_VERSION' ) ) {
require_once CARTFLOWS_DIR . 'classes/class-cartflows-learndash-compatibility.php';
}
}
/**
* Check if it is beaver builder enabled.
*
* @since 1.1.4
*/
public function is_bb_enabled() {
if ( class_exists( 'FLBuilderModel' ) ) {
return true;
}
return false;
}
/**
* 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() || $this->is_divi_builder_preview() ) {
return true;
}
return false;
}
/**
* Check if divi builder enabled for post id.
*/
public function is_divi_builder_preview() {
if ( isset( $_GET['et_fb'] ) && '1' === $_GET['et_fb'] ) { //phpcs:ignore
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.
*/
public function is_compatibility_theme_enabled() {
$theme = wp_get_theme();
$is_compatibility = false;
if ( $this->is_divi_enabled( $theme ) || $this->is_flatsome_enabled( $theme ) || $this->is_pro_enabled( $theme ) || $this->is_kallyas_enabled( $theme ) ) {
$is_compatibility = true;
}
return apply_filters( 'cartflows_is_compatibility_theme', $is_compatibility );
}
/**
* Check if pro theme enabled for post id.
*
* @param object $theme theme data.
* @return boolean
*/
public function is_pro_enabled( $theme = false ) {
if ( ! $theme ) {
$theme = wp_get_theme();
}
if ( 'Pro' == $theme->name ) {
return true;
}
return false;
}
/**
* Check if kallyas theme enabled for post id.
*
* @param object $theme theme data.
* @return boolean
*/
public function is_kallyas_enabled( $theme = false ) {
if ( ! $theme ) {
$theme = wp_get_theme();
}
if ( 'Kallyas' == $theme->name ) {
return true;
}
return false;
}
/**
* Check if divi builder enabled for post id.
*
* @param object $theme theme data.
* @return boolean
*/
public function is_divi_enabled( $theme = false ) {
if ( ! $theme ) {
$theme = wp_get_theme();
}
if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme || 'Extra' == $theme->name || 'Extra' == $theme->parent_theme ) {
return true;
}
return false;
}
/**
* Check if Divi theme is install status.
*
* @return boolean
*/
public function is_divi_theme_installed() {
foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
if ( 'Divi' == $theme->name || 'Divi' == $theme->parent_theme || 'Extra' == $theme->name || 'Extra' == $theme->parent_theme ) {
return true;
}
}
return false;
}
/**
* Check if Flatsome enabled for post id.
*
* @param object $theme theme data.
* @return boolean
*/
public 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 The7 enabled for post id.
*
* @param object $theme theme data.
* @return boolean
*/
public function is_the_seven_enabled( $theme = false ) {
if ( ! $theme ) {
$theme = wp_get_theme();
}
if ( 'The7' == $theme->name || 'The7' == $theme->parent_theme ) {
return true;
}
return false;
}
/**
* Check if OceanWp enabled for post id.
*
* @param object $theme theme data.
* @return boolean
*/
public 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; //phpcs:ignore
$post = isset( $_GET['post'] ) ? intval( wp_unslash( $_GET['post'] ) ) : false; //phpcs:ignore
return ( true == $tve && $post_id !== $post );
}
Loading ...