add_common_actions(); return; } $this->register_display_conditions_experiments(); $this->maybe_add_actions_and_components(); } public static function is_experiment_active(): bool { return Plugin::elementor()::$instance->experiments->is_feature_active( self::LICENSE_FEATURE_NAME ); } public static function should_show_promo(): bool { return ! self::can_use_display_conditions(); } private function add_actions() { $this->add_render_actions(); add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); add_filter( 'elementor/element/is_dynamic_content', [ $this, 'filter_element_caching_is_dynamic_content' ], 10, 3 ); } private function add_components() { $this->add_component( 'conditions', new Classes\Conditions_Manager( $this ) ); $this->add_component( 'cache_notice', new Classes\Cache_Notice() ); } private function add_common_actions() { $this->add_advanced_tab_actions(); add_action( 'elementor/editor/before_enqueue_scripts', function() { $this->enqueue_main_script(); } ); } private function enqueue_main_script() { $min_suffix = Utils::is_script_debug() ? '' : '.min'; wp_enqueue_script( 'e-display-conditions', ELEMENTOR_PRO_ASSETS_URL . 'js/display-conditions' . $min_suffix . '.js', [ 'react', 'react-dom', 'backbone-marionette', 'elementor-web-cli', 'wp-date', 'elementor-common', 'elementor-editor-modules', 'elementor-editor-document', 'elementor-v2-ui', 'elementor-v2-icons', ], ELEMENTOR_PRO_VERSION, true ); wp_set_script_translations( 'e-display-conditions', 'elementor-pro' ); } private function add_advanced_tab_actions() { $hooks = array( 'elementor/element/section/section_advanced/after_section_end' => 'css_classes', // Sections 'elementor/element/column/section_advanced/after_section_end' => 'css_classes', // Columns 'elementor/element/common/_section_style/after_section_end' => '_css_classes', // Widgets 'elementor/element/container/section_layout/after_section_end' => 'css_classes', // Containers ); foreach ( $hooks as $hook => $injection_position ) { add_action( $hook, function( $element, $args ) use ( $injection_position ) { $this->add_control_to_advanced_tab( $element, $args, $injection_position ); }, 10, 2 ); } } protected function add_render_actions() { $element_types = array( 'section', 'column', 'widget', 'container', ); foreach ( $element_types as $el ) { add_action( 'elementor/frontend/' . $el . '/before_render', array( $this, 'before_element_render' ) ); add_action( 'elementor/frontend/' . $el . '/after_render', array( $this, 'after_element_render' ) ); } } private function add_control_to_advanced_tab( $element, $args, $injection_position ) { $element->start_injection( array( 'of' => $injection_position, ) ); $element->add_control( 'e_display_conditions_trigger', array( 'type' => Controls_Manager::RAW_HTML, 'separator' => 'before', 'raw' => $this->get_display_conditions_control_template(), ) ); $element->add_control( 'e_display_conditions', array( 'type' => Controls_Manager::HIDDEN, ) ); $element->end_injection(); } private function get_display_conditions_control_template() { $icon_class = 'e-control-display-conditions'; $show_promo = self::should_show_promo(); if ( $show_promo ) { $icon_class .= '-promo'; } ob_start(); ?>