Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/plugins/boost/changelog/add-divi-compat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Compatibility: Added compatibility with divi builder and Deferred JS.
43 changes: 43 additions & 0 deletions projects/plugins/boost/compatibility/divi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Compatibility functions for Divi Builder
*
* @package automattic/jetpack-boost
*/

namespace Automattic\Jetpack_Boost\Compatibility\Divi;

/**
* Defer JS can break Divi Builder.
*/
function disable_defer_js_for_divi_builder( $should_defer_js ) {
$is_divi_builder = filter_input( INPUT_GET, 'et_fb', FILTER_VALIDATE_INT );

if ( 1 === (int) $is_divi_builder ) {
return false;
}

$is_divi_preview = filter_input(
INPUT_GET,
'et_pb_preview',
FILTER_VALIDATE_BOOLEAN,
array(
'flags' => FILTER_NULL_ON_FAILURE,
)
);

if ( true === $is_divi_preview ) {
return false;
}

if ( function_exists( 'is_et_pb_preview' ) ) {
/** @phan-suppress-next-line PhanUndeclaredFunction */
if ( \is_et_pb_preview() ) {
return false;
}
}
Comment on lines +33 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to the top. If the plugin doesn't exist, there's no need to do the above things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the other comment for an explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see Pete's point: if the function exists and it is a simple return, it could go higher in the execution. I don't know if the microoptimization is all that important [unsure of the performance of the filter_input for example, etc.


return $should_defer_js;
}

add_filter( 'jetpack_boost_should_defer_js', __NAMESPACE__ . '\disable_defer_js_for_divi_builder' );
3 changes: 3 additions & 0 deletions projects/plugins/boost/jetpack-boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ function include_compatibility_files() {
require_once __DIR__ . '/compatibility/breakdance.php';
}

// Compatibility with Divi by Elegant Themes.
require_once __DIR__ . '/compatibility/divi.php';
Comment on lines +254 to +255
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wrap this in a function_exists check so we don't always load it (similar to the rest).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very comfortable depending on any specific function. I tried to find constants or functions that I can depend on. But, couldn't find anything prominent enough or anything documented. So, I decided to keep it outside of any conditional as the checks are not very intensive, just checking if a variable exists in runtime.

The get parameters seem to be consistent through different versions(according to users in forums) of the theme so it's a bit comforting to depend on them.


// Exclude known scripts that causes problem when concatenated.
require_once __DIR__ . '/compatibility/js-concatenate.php';

Expand Down
Loading