builder_page_id = BuilderFns::builder_page_id_by_page(); $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id ); if ( ! is_admin() ) { BuilderHooks::instance(); } BuilderCpt::instance(); if ( defined( 'ELEMENTOR_VERSION' ) ) { $this->elementor_init(); $this->both_builder_frontend(); add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] ); } // RT Select2 Ajax. add_action( 'wp_ajax_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); add_action( 'wp_ajax_nopriv_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); // Select2 ajax save data. add_action( 'wp_ajax_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); add_action( 'wp_ajax_nopriv_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); } /** * Apply for frontend. * * @return void */ public function both_builder_frontend() { add_action( 'rtsb/builder/template/before/content', [ $this, 'builder_template_before_content' ] ); add_action( 'rtsb/builder/template/after/content', [ $this, 'builder_template_after_content' ] ); } /** * Register Category * * @return void */ public function elementor_init() { add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_widget_categories' ] ); add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] ); add_action( 'elementor/controls/register', [ $this, 'init_controls' ] ); add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] ); add_action( 'elementor/icons_manager/additional_tabs', [ $this, 'rtsb_icons' ] ); } /** * Register Category * * @param object $elements_manager Category hooks. * * @return void */ public function add_elementor_widget_categories( $elements_manager ) { $categories = []; $builder_id = get_queried_object_id(); $id = Fns::wpml_object_id( $builder_id, BuilderFns::$post_type_tb, 'default' ); $type = BuilderFns::builder_type( $id ); if ( $type ) { $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type ); $categories['rtsb-shopbuilder'] = [ 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), 'icon' => 'fa fa-plug', ]; } if ( 'quick-view' !== $type ) { $categories['rtsb-shopbuilder-general'] = [ 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ), 'icon' => 'fa fa-plug', ]; } $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories ); $other_categories = $elements_manager->get_categories(); $categories = array_merge( array_slice( $other_categories, 0, 1 ), $categories, array_slice( $other_categories, 1 ) ); $set_categories = function ( $categories ) use ( $elements_manager ) { $elements_manager->categories = $categories; }; $set_categories->call( $elements_manager, $categories ); } /** * Init Controls * * Include controls files and register them * * @param object $controls_manager Controls Manager. * * @since 1.0.0 */ public function init_controls( $controls_manager ) { $controls_manager->register( new ImageSelectorControl() ); $controls_manager->register( new Select2AjaxControl() ); } /** * Init Widgets * * Include widgets files and register them * * @since 1.0.0 */ public function init_widgets( $widgets_manager ) { $get_list = ElementList::instance()->get_list( true, 'active' ); foreach ( $get_list as $element ) { if ( isset( $element['active'] ) && 'on' !== $element['active'] ) { continue; } if ( ! empty( $element['package'] ) && 'pro-disabled' === $element['package'] ) { continue; } if ( empty( $element['base_class'] ) || ! class_exists( $element['base_class'] ) ) { continue; } if ( ! empty( $element['category'] ) ) { $widget = false; $import = apply_filters( 'rtsb_import_status', false ); switch ( $element['category'] ) { case 'product': if ( BuilderFns::is_product() || $import ) { $widget = new $element['base_class'](); } break; case 'shop': if ( BuilderFns::is_archive() || BuilderFns::is_shop() || $import ) { $widget = new $element['base_class'](); } break; case 'archive': if ( BuilderFns::is_archive() || $import ) { $widget = new $element['base_class'](); } break; case 'cart': if ( BuilderFns::is_cart() || $import ) { $widget = new $element['base_class'](); } break; case 'checkout': if ( BuilderFns::is_checkout() || $import ) { $widget = new $element['base_class'](); } break; case 'general': $widget = new $element['base_class'](); break; default: } $widget = apply_filters( 'rtsb/element/list/init/widgets', $widget, $element ); if ( $widget && is_object( $widget ) ) { $widgets_manager->register( $widget ); } } } } /** * Adding custom icons in Elementor * * @param array $tabs Tabs. * * @return array */ public function rtsb_icons( $tabs = [] ) { $custom_icons = Fns::get_custom_icon_names(); $tabs['shopbuilder-icons'] = [ 'name' => 'rtsb-fonts', 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ), 'labelIcon' => 'fab fa-elementor', 'prefix' => 'rtsb-icon-', 'displayPrefix' => 'rtsb-icon', 'url' => rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ), 'icons' => $custom_icons, 'ver' => '1.0', ]; return $tabs; } /** * Editor JS. * * @return void */ public function editor_scripts() { $version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : RTSB_VERSION; wp_enqueue_script( 'rtsb-editor-script', rtsb()->get_assets_uri( 'js/backend/editor.js' ), [ 'jquery', 'elementor-editor', 'jquery-elementor-select2', ], $version, true ); $params = [ 'isEditorForBuilder' => false, ]; if ( BuilderFns::is_builder_preview() ) { $params['isEditorForBuilder'] = true; } wp_localize_script( 'rtsb-editor-script', 'rtsbTemplateBuilderEditorScript', $params ); wp_enqueue_style( 'rtsb-el-editor-style', rtsb()->get_assets_uri( 'css/backend/elementor-editor.css' ), [], $version ); } /** * Before Content for Elementor. * * @return void */ public function builder_template_before_content() { /** * Before Header-Footer page template content. * * Fires before the content of Elementor Header-Footer page template. * * @since 2.0.0 */ if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) { do_action( 'elementor/page_templates/header-footer/before_content' ); } $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] ); if ( BuilderFns::is_product() ) { $product_id = Fns::get_prepared_product_id(); $parent_class = wc_get_product_class( $parent_class, $product_id ); if ( function_exists( 'rtwpvs' ) ) { $_product = Fns::get_product(); if ( $_product->is_type( 'variable' ) ) { $parent_class[] = 'rtwpvs-product'; $beside_label = function_exists( 'rtwpvsp' ) && rtwpvs()->get_option( 'attribute_on_click_behavior' ); if ( $beside_label ) { $parent_class[] = 'rtwpvs-selected-term-beside-label'; } } } } if ( BuilderFns::is_shop() ) { $parent_class[] = 'shop'; } if ( BuilderFns::is_archive() ) { $parent_class[] = 'archive'; } if ( BuilderFns::is_checkout() ) { $parent_class[] = 'checkout-page '; } ?>