Skip to content

Instantly share code, notes, and snippets.

@lots0logs
Forked from igmoweb/divi-hummingbird.php
Last active October 17, 2016 17:06
Show Gist options
  • Save lots0logs/eb63d9a0960e397054f612e131594f42 to your computer and use it in GitHub Desktop.
Save lots0logs/eb63d9a0960e397054f612e131594f42 to your computer and use it in GitHub Desktop.
It avoids minification and concatenation for Divi assets (assets slugs must be filled)
<?php
function wphb_et_divi_theme_active() {
$theme = wp_get_theme();
return ( 'divi' === strtolower( $theme ) || 'divi' === strtolower( $theme->get_template() ) );
}
if ( ! function_exists( 'wphb_divi_after_init' ) ):
function wphb_divi_after_init() {
if ( wphb_et_divi_theme_active() ) {
remove_action( 'wp_head', 'et_add_custom_css', 100 );
add_action( 'wp_head', 'et_add_custom_css', 9999 );
remove_action( 'wp_head', 'et_divi_add_customizer_css' );
add_action( 'wp_head', 'et_divi_add_customizer_css', 9998 );
}
if ( wphb_et_visual_builder_active() || wphb_et_divi_builder_active() ) {
add_filter( 'wp_hummingbird_is_active_module_minify', '__return_false', 500 );
}
}
endif;
function wphb_et_visual_builder_active() {
return false !== strpos( $_SERVER['REQUEST_URI'], '?et_fb=1' );
}
function wphb_et_divi_builder_active() {
return is_admin() && function_exists( 'et_builder_should_load_framework' ) && et_builder_should_load_framework();
}
function wphb_et_divi_essential_scripts() {
return array(
'et-builder-modules-global-functions-script',
'et-builder-modules-script',
'divi-custom-script',
'et-frontend-builder', // This is already handled by `wphb_divi_after_init()` , including it here to hide it in HB dashboard.
);
}
function wphb_et_maybe_exclude_divi_essential_scripts( $action, $handle, $type ) {
if ( is_array( $handle ) && isset( $handle['handle'] ) ) {
$handle = $handle['handle'];
}
if ( 'scripts' === $type && in_array( $handle, wphb_et_divi_essential_scripts() ) ) {
return false;
}
return $action;
}
if ( wphb_et_divi_theme_active() || class_exists( 'ET_Builder_Plugin' ) ) {
add_action( 'init', 'wphb_divi_after_init', 1 );
add_filter( 'wphb_minify_resource', 'wphb_et_maybe_exclude_divi_essential_scripts', 10, 3 );
add_filter( 'wphb_combine_resource', 'wphb_et_maybe_exclude_divi_essential_scripts', 10, 3 );
add_filter( 'wphb_minification_display_enqueued_file', 'wphb_et_maybe_exclude_divi_essential_scripts', 10, 3 );
}
@lots0logs
Copy link
Author

lots0logs commented Oct 4, 2016

@igmoweb I just sent you an email saying that this should do it. However, I just realized that the plugins_loaded action is too early to properly detect whether or not to override Hummingbird's handling of the Divi Builder scripts. Really the action hooked on line 62 (with priority 1) is the earliest. Can you make this work on your end using that hook and priority instead of plugins-loaded?

_Edit:_ Ah, nevermind. Init would obviously be too late. I just noticed something else, I'll email you the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment