Optimized Gutenberg Loading', 'elementor' ), 'description' => esc_html__( 'Use this experiment to reduce unnecessary render-blocking loads, enhancing site performance by dequeuing unused Gutenberg block editor files (styles and scripts).', 'elementor' ), 'release_status' => Experiments_Manager::RELEASE_STATUS_STABLE, 'default' => Experiments_Manager::STATE_ACTIVE, 'tag' => esc_html__( 'Performance', 'elementor' ), 'generator_tag' => true, ] ); } public function dequeue_assets() { if ( ! Plugin::$instance->experiments->is_feature_active( 'block_editor_assets_optimize' ) ) { return; } if ( ! static::should_dequeue_gutenberg_assets() ) { return; } wp_dequeue_style( 'wp-block-library' ); wp_dequeue_style( 'wp-block-library-theme' ); wp_dequeue_style( 'wc-block-style' ); wp_dequeue_style( 'wc-blocks-style' ); } private static function should_dequeue_gutenberg_assets() : bool { $post = get_post(); if ( empty( $post->ID ) ) { return false; } if ( ! static::is_built_with_elementor( $post ) ) { return false; } if ( static::is_gutenberg_in_post( $post ) ) { return false; } return true; } private static function is_built_with_elementor( $post ) : bool { $document = Plugin::$instance->documents->get( $post->ID ); if ( ! $document || ! $document->is_built_with_elementor() ) { return false; } return true; } private static function is_gutenberg_in_post( $post ) : bool { if ( has_blocks( $post ) ) { return true; } if ( static::current_theme_is_fse_theme() ) { return true; } return false; } private static function current_theme_is_fse_theme() : bool { if ( function_exists( 'wp_is_block_theme' ) ) { return (bool) wp_is_block_theme(); } if ( function_exists( 'gutenberg_is_fse_theme' ) ) { return (bool) gutenberg_is_fse_theme(); } return false; } }