Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
61.54% covered (warning)
61.54%
8 / 13
0.00% covered (danger)
0.00%
0 / 2
CRAP
n/a
0 / 0
Automattic\Jetpack_Boost\Compatibility\Beaver_Builder\exclude_beaver_builder_custom_post_types
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
Automattic\Jetpack_Boost\Compatibility\Beaver_Builder\disable_js_concatenate_for_beaver_builder
71.43% covered (warning)
71.43%
5 / 7
0.00% covered (danger)
0.00%
0 / 1
5.58
1<?php
2/**
3 * Compatibility for Beaver Builder (both lite and Pro versions).
4 *
5 * @package automattic/jetpack-boost
6 */
7
8namespace Automattic\Jetpack_Boost\Compatibility\Beaver_Builder;
9
10/**
11 * Exclude Beaver Builder custom post types from list of posts to generate critical CSS for.
12 *
13 * @param array $post_types Post types.
14 */
15function exclude_beaver_builder_custom_post_types( $post_types ) {
16    unset( $post_types['fl-builder-template'] );
17    unset( $post_types['fl-theme-layout'] );
18
19    return $post_types;
20}
21
22add_filter( 'jetpack_boost_critical_css_post_types_singular', __NAMESPACE__ . '\exclude_beaver_builder_custom_post_types' );
23add_filter( 'jetpack_boost_critical_css_post_types_archives', __NAMESPACE__ . '\exclude_beaver_builder_custom_post_types' );
24
25/**
26 * Disable JS concatenation when Beaver Builder editor is active.
27 * The editor depends on specific script execution order that concatenation breaks.
28 *
29 * @param bool   $do_concat Whether to concatenate the script.
30 * @param string $handle    Script handle.
31 * @return bool
32 */
33function disable_js_concatenate_for_beaver_builder( $do_concat, $handle ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
34    // Check for fl_builder query parameter (BB editor mode)
35    // BB uses ?fl_builder (no value) to indicate editor mode
36    $is_bb_editor = filter_input( INPUT_GET, 'fl_builder' );
37    if ( null !== $is_bb_editor ) {
38        return false;
39    }
40
41    // Fallback: Check BB's native function for builder active state
42    // @phan-suppress-next-line PhanUndeclaredClassReference
43    if ( class_exists( 'FLBuilderModel' ) && method_exists( 'FLBuilderModel', 'is_builder_active' ) ) {
44        /** @phan-suppress-next-line PhanUndeclaredClassMethod */
45        if ( \FLBuilderModel::is_builder_active() ) {
46            return false;
47        }
48    }
49
50    return $do_concat;
51}
52
53add_filter( 'js_do_concat', __NAMESPACE__ . '\disable_js_concatenate_for_beaver_builder', 10, 2 );