exclusions = $exclusions; add_action( 'init', array( $this, 'check_elementor_editor' ) ); } /** * Check if Elementor is active. * * @return bool */ public static function is_active() { return did_action( 'elementor/loaded' ) || class_exists( '\Elementor\Plugin' ); } /** * Auto-exclude Elementor editor and preview frames from optimization. */ public function check_elementor_editor() { if ( isset( $_GET['elementor-preview'] ) || ( isset( $_GET['action'] ) && 'elementor' === $_GET['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->exclusions->add_exclusion( '*' ); return; } if ( class_exists( '\Elementor\Plugin' ) ) { if ( \Elementor\Plugin::$instance->editor && \Elementor\Plugin::$instance->editor->is_edit_mode() ) { $this->exclusions->add_exclusion( '*' ); } elseif ( \Elementor\Plugin::$instance->preview && \Elementor\Plugin::$instance->preview->is_preview_mode() ) { $this->exclusions->add_exclusion( '*' ); } } } }