_page_id, $may_be_post, $design_data ) ) { $global_embed_form_url = apply_filters( 'wfacp_global_embed_form_redirect_url', get_the_permalink( $this->override_checkout_page_id ), $this->override_checkout_page_id, $may_be_post ); wp_redirect( $global_embed_form_url ); exit; } if ( $may_be_post->post_status == 'publish' ) { //wfacp pages $this->override_checkout_page_id = apply_filters( 'wfacp_wpml_checkout_page_id', $this->override_checkout_page_id ); do_action( 'wfacp_changed_default_woocommerce_page', $this->override_checkout_page_id ); WFACP_Common::set_id( $this->override_checkout_page_id ); $this->checkout_post = $may_be_post; if ( $this->override_checkout_page_id !== $may_be_post->ID ) { $this->checkout_post = get_post( $this->override_checkout_page_id ); } self::$is_checkout = true; add_filter( 'woocommerce_is_checkout', '__return_true' ); do_action( 'wfacp_checkout_page_found', $this->override_checkout_page_id ); return true; } } } if ( ! is_null( $post ) ) { do_action( 'wfacp_none_checkout_pages', $post ); } return false; } public function setup_preview() { add_filter( 'template_include', array( $this, 'maybe_load' ), 99 ); } /** * Finds out if its safe to initiate data setup for the current request. * Checks for the environmental conditions and provide results. * @return bool true on success| false otherwise * @see WFACP_Template_loader::maybe_setup_page() */ public function is_valid_state_for_data_setup() { return self::$is_checkout; } /** * @hooked over `init`:15 * This method try and sets up the data for all the existing pages. * customizer-admin | customizer-preview | front-end-funnel | front-end-ajax-request-during-funnel * For the given environments we have our offer ID setup at this point. So its safe and necessary to set the data. * This method does: * 1. Fetches and sets up the offer data based on the offer id provided * 2. Finds the loads the appropriate template. * 3. loads offer data to the template instance * 4. Build offer data for the current offer */ public function maybe_setup_page() { if ( ! is_null( $this->current_template ) ) { return; } if ( ! $this->is_valid_state_for_data_setup() ) { return; } $id = WFACP_Common::get_id(); /** * @var $get_customizer_instance WFACP_Customizer */ $instances = $this->load_template( $id ); if ( ! is_null( $instances ) ) { $this->current_template = $instances; do_action( 'wfacp_template_class_found', $this->current_template, $this ); } } /** * Locate Template using offer meta data also setup data * * @param $wfacp_id * * @return mixed|null */ public function load_template( $wfacp_id ) { if ( empty( $wfacp_id ) || $wfacp_id == 0 ) { return null; } if ( $this->current_template instanceof WFACP_Template_Common ) { return $this->current_template; } $template_file = false; $template = WFACP_Common::get_page_design( $wfacp_id ); $selected_type = $template['selected_type']; $this->template = $template['selected']; $locate_template = $this->locate_template( $this->template, $selected_type ); if ( false !== $locate_template ) { $template_file = $locate_template['path']; } $template_file = apply_filters( 'wfacp_template_class', $template_file, $locate_template, $this->templates, $this ); if ( false == $template_file || ! file_exists( $template_file ) ) { return null; } include __DIR__ . '/class-wfacp-template.php'; do_action( 'wfacp_template_load', $wfacp_id, $template ); include WFACP_Core()->dir( 'builder/customizer/class-wfacp-pre-built.php' ); // include abstract wrapper class for templates $this->current_template = include $template_file; if ( ! method_exists( $this->current_template, 'get_slug' ) ) { return null; } $this->current_template->set_selected_template( $locate_template ); $this->current_template->set_wfacp_id( $wfacp_id ); $this->current_template->set_data(); if ( 'embed_form' !== $this->current_template->get_template_type() && false === apply_filters( 'wfacp_block_editor_compatibility', false ) ) { remove_filter( 'the_content', 'do_blocks', 9 ); } do_action( 'wfacp_after_template_found', $this->current_template ); return $this->current_template; } public function assign_template( $template ) { global $post; if ( is_null( $post ) || ( $post->post_type !== WFACP_Common::get_post_type_slug() && is_null( $this->current_template ) ) ) { return $template; } // In case above statement bypass and template instance not created then return if ( is_null( $this->current_template ) ) { return $template; } $wfacp_id = WFACP_Common::get_id(); if ( 0 == $wfacp_id ) { return $template; } $my_template = get_post_meta( $wfacp_id, '_wp_page_template', true ); if ( ( isset( $_REQUEST['elementor-preview'] ) && $_REQUEST['elementor-preview'] > 0 ) || ( isset( $_REQUEST['preview_id'] ) && $_REQUEST['preview_id'] > 0 ) ) { $wfacp_id = WFACP_Common::get_id(); $revision_my_template = $this->get_last_revision_page_template( $wfacp_id ); if ( '' !== $revision_my_template ) { $my_template = $revision_my_template; } } if ( 'wfacp-canvas.php' == $my_template ) { $template = WFACP_Core()->dir( 'public/page-template/template-canvas.php' ); } elseif ( 'wfacp-full-width.php' == $my_template ) { $template = WFACP_Core()->dir( 'public/page-template/template-default-boxed.php' ); } else { add_filter( 'next_post_link', '__return_empty_string' ); add_filter( 'previous_post_link', '__return_empty_string' ); if ( false !== strpos( $template, 'single.php' ) ) { $page = locate_template( array( 'page.php' ) ); if ( ! empty( $page ) ) { $template = $page; } } } return $template; } /** * @hooked over `template_include` * This method checks for the current running funnels and controller to setup data & offer validation * It also loads and echo/prints current template if the offer demands to. * * @param $template * * @return mixed */ public function maybe_load( $template ) { if ( is_subclass_of( $this->current_template, 'WFACP_Template_Common' ) ) { do_action( 'wfacp_after_checkout_page_found', WFACP_Common::get_id() ); if ( apply_filters( 'wfacp_load_template', true, $this->current_template, $this ) && true == $this->current_template->use_own_template() ) { $this->current_template->get_view( $template ); } } else { do_action( 'wfacp_checkout_page_not_found' ); } return $template; } public function get_template_type() { return $this->template_type; } public function get_template_type_data() { return $this->template_type_data; } public function locate_template( $slug, $template_type = 'pre_built', $data = false ) { $template_data = false; if ( $template_type === 'pre_built' || empty( $template_type ) ) { $path = $this->get_template_path_by_template( $slug ); //handle_customizer $template_data = array( 'path' => WFACP_BUILDER_DIR . '/customizer/templates/' . $path . '/template.php', 'slug' => $slug, ); } else if ( $template_type === 'embed_forms' ) { //handle_customizer $template_data = array( 'path' => WFACP_BUILDER_DIR . '/customizer/templates/embed_forms_1/template.php', 'slug' => $slug, ); } else if ( $template_type === 'elementor' ) { $template_data = array( 'path' => WFACP_BUILDER_DIR . '/elementor/template/template.php', 'slug' => $slug, ); } else if ( $template_type === 'divi' ) { $template_data = array( 'path' => WFACP_BUILDER_DIR . '/divi/template/template.php', 'slug' => $slug, ); } if ( $template_type === 'oxy' ) { return array( 'path' => WFACP_BUILDER_DIR . '/oxygen/template/template.php', 'slug' => $slug, 'name' => 'oxygen', 'template_type' => $template_type, ); } return apply_filters( 'wfacp_locate_template', $template_data, $this ); } public function get_template_path_by_template( $slug ) { $config = array( 'classic' => 'layout_1', 'classic-step-2' => 'layout_1', 'classic-step-3' => 'layout_1', 'salesletter' => 'layout_2', 'salesletter-step-2' => 'layout_2', 'salesletter-step-3' => 'layout_2', 'marketer' => 'layout_4', 'marketer-step-2' => 'layout_4', 'marketer-step-3' => 'layout_4', 'shopcheckout' => 'layout_9', 'shopcheckout-multi' => 'layout_9', 'shopcheckout-three' => 'layout_9', 'shopcheckout-step-3' => 'layout_9', 'royale-step-2' => 'layout_9', 'royale-step-3' => 'layout_9', ); return $config[ $slug ]; } /** * @param string $is_single * * @return array */ public function get_templates( $builder = '' ) { if ( isset( $this->templates[ $builder ] ) ) { return $this->templates[ $builder ]; } return $this->templates; } public function get_single_template( $template = '', $type = 'pre_built' ) { if ( empty( $template ) ) { return []; } if ( isset( $this->templates[ $type ] ) && isset( $this->templates[ $type ][ $template ] ) ) { return $this->templates[ $type ][ $template ]; } return []; } public function get_template_ins() { return $this->current_template; } /** * to avoid unserialize of the current class */ public function __wakeup() { throw new ErrorException( 'WFACP_Core can`t converted to string' ); } /** * to avoid serialize of the current class */ public function __sleep() { throw new ErrorException( 'WFACP_Core can`t converted to string' ); } /** * To avoid cloning of current template class */ protected function __clone() { } /** * Get Plugins list by page builder. * * @return array Required Plugins list. * @since 1.1.4 * */ public function get_plugins_groupby_page_builders() { $divi_status = $this->get_plugin_status( 'divi-builder/divi-builder.php' ); $sling_status = $this->get_plugin_status( 'slingblocks/slingblocks.php' ); $theme_status = 'not-installed'; if ( $divi_status ) { if ( true === $this->is_divi_theme_installed() ) { if ( false === $this->is_divi_theme_enabled() ) { $theme_status = 'deactivated'; } else { $theme_status = 'activated'; $divi_status = ''; } } } $oxygen_status = $this->get_plugin_status( 'oxygen/functions.php' ); $plugins = array( 'elementor' => array( 'title' => 'Elementor', 'plugin-status' => $this->get_plugin_status( 'elementor/elementor.php' ), 'plugins' => array( array( 'slug' => 'elementor', // For download from wordpress.org. 'init' => 'elementor/elementor.php', 'status' => $this->get_plugin_status( 'elementor/elementor.php' ), ), ), ), 'gutenberg' => array( 'title' => 'SlingBlocks', 'plugin-status' => $sling_status, 'plugins' => array( array( 'slug' => 'slingblocks', // For download from wordpress.org. 'init' => 'slingblocks/slingblocks.php', 'status' => $sling_status, ), ), ), 'divi' => array( 'title' => 'Divi', 'theme-status' => $theme_status, 'plugin-status' => $divi_status, 'plugins' => array( array( 'slug' => 'divi-builder', // For download from wordpress.org. 'init' => 'divi-builder/divi-builder.php', 'status' => $divi_status, ), ), ), 'oxy' => array( 'title' => 'Oxygen', 'plugin-status' => $oxygen_status, 'plugins' => array( array( 'slug' => 'oxygen', // For download from wordpress.org. 'init' => 'oxygen/functions.php', 'status' => $oxygen_status, ), ), ), ); $plugins['beaver-builder'] = array( 'title' => 'Beaver Builder', 'plugins' => array(), ); // Check if Pro Exist. if ( file_exists( WP_PLUGIN_DIR . '/' . 'bb-plugin/fl-builder.php' ) && ! is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) ) { $plugins['beaver-builder']['plugin-status'] = $this->get_plugin_status( 'bb-plugin/fl-builder.php' ); $plugins['beaver-builder']['plugins'][] = array( 'slug' => 'bb-plugin', 'init' => 'bb-plugin/fl-builder.php', 'status' => $this->get_plugin_status( 'bb-plugin/fl-builder.php' ), ); } else { $plugins['beaver-builder']['plugin-status'] = $this->get_plugin_status( 'beaver-builder-lite-version/fl-builder.php' ); $plugins['beaver-builder']['plugins'][] = array( 'slug' => 'beaver-builder-lite-version', // For download from wordpress.org. 'init' => 'beaver-builder-lite-version/fl-builder.php', 'status' => $this->get_plugin_status( 'beaver-builder-lite-version/fl-builder.php' ), ); } $plugins['wp_editor']['plugins'][] = array( 'slug' => '', 'status' => null, ); return $plugins; } /** * Get plugin status * * @param string $plugin_init_file Plguin init file. * * @return mixed * @since 1.0.0 * */ public function get_plugin_status( $plugin_init_file ) { if ( null === $this->installed_plugins ) { $this->installed_plugins = get_plugins(); } if ( ! isset( $this->installed_plugins[ $plugin_init_file ] ) ) { return 'install'; } elseif ( ! is_plugin_active( $plugin_init_file ) ) { return 'activate'; } } /** * Check if Divi theme is install status. * * @return boolean */ public function is_divi_theme_installed() { foreach ( (array) wp_get_themes() as $theme ) { if ( 'Divi' === $theme->name || 'Divi' === $theme->parent_theme || 'Extra' === $theme->name || 'Extra' === $theme->parent_theme ) { return true; } } return false; } /** * Check if divi theme enabled for post id. * * @param object $theme theme data. * * @return boolean */ public function is_divi_theme_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; } public function localize_page_builder_texts() { $pageBuildersTexts = []; $get_all_opted_page_builders = [ 'gutenberg', 'elementor', 'divi', 'oxy' ]; if ( empty( $get_all_opted_page_builders ) ) { return $pageBuildersTexts; } foreach ( $get_all_opted_page_builders as $builder ) { $page_builder = $this->get_dependent_plugins_for_page_builder( $builder ); $plugin_string = sprintf( __( 'This template needs %s plugin activated.', 'woofunnels-aero-checkout' ), esc_html( $page_builder['title'] ) ); $button_text = __( 'Activate', 'woofunnels-aero-checkout' ); $cancel_btn = __( 'Cancel', 'woofunnels-aero-checkout' ); $no_install = 'no'; $title = __( 'Import Template', 'woofunnels-aero-checkout' ); $show_cancel_btn = 'yes'; $plugin_status = isset( $page_builder['plugin-status'] ) ? $page_builder['plugin-status'] : ''; $theme_status = isset( $page_builder['theme-status'] ) ? $page_builder['theme-status'] : ''; $string = sprintf( __( ' Click the button to install and activate %s.', 'woofunnels-aero-checkout' ), esc_html( $page_builder['title'] ) ); $install = sprintf( __( ' Install and activate %s.', 'woofunnels-aero-checkout' ), esc_html( $page_builder['title'] ) ); $builder_link = ''; /** * If its a divi builder we need to handle few cases down there for best user experience */ /** * If its a divi builder we need to handle few cases down there for best user experience */ if ( 'divi' === $builder ) { if ( 'activated' !== $theme_status && 'activate' === $plugin_status ) { $plugin_string = $string; } else { $plugin_string .= $install; $button_text = __( 'Install Divi Builder', 'woofunnels-aero-checkout' ); $no_install = 'yes'; $builder_link = esc_url( 'https://www.elegantthemes.com/' ); } } else if ( 'oxy' === $builder ) { if ( 'install' === $plugin_status ) { $plugin_string .= $string; $button_text = __( 'Install Oxygen Builder', 'woofunnels-aero-checkout' ); $no_install = 'yes'; $builder_link = esc_url( 'https://oxygenbuilder.com/' ); } else { $plugin_string .= $install; } } else { $plugin_string .= $string; } $pageBuildersTexts[ $builder ] = array( 'text' => $plugin_string, 'ButtonText' => $button_text, 'noInstall' => $no_install, 'title' => $title, 'show_cancel_btn' => $show_cancel_btn, 'close_btn' => $cancel_btn, 'builder_link' => $builder_link, 'plugin_status' => $plugin_status, ); } return $pageBuildersTexts; } public function get_dependent_plugins_for_page_builder( $page_builder_slug = '', $default = 'elementor' ) { $plugins = $this->get_plugins_groupby_page_builders(); if ( array_key_exists( $page_builder_slug, $plugins ) ) { return $plugins[ $page_builder_slug ]; } return $plugins[ $default ]; } /** * Get Revision Page Template * * @param $id * * @return mixed|string */ private function get_last_revision_page_template( $id ) { global $wpdb; $data = $wpdb->get_results( "select ID from {$wpdb->posts} where post_parent='{$id}' ORDER BY ID DESC LIMIT 1", ARRAY_A ); $template = ''; if ( ! empty( $data ) ) { $revision_id = $data[0]['ID']; $template = get_post_meta( $revision_id, '_wp_page_template', true ); } return $template; } /** * @return WP_Post; */ public function get_checkout_post() { return $this->checkout_post; } } if ( class_exists( 'WFACP_Core' ) && ! WFACP_Common::is_disabled() ) { WFACP_Core::register( 'template_loader', 'WFACP_Template_loader' ); }