Skip to content
Draft
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
25 changes: 25 additions & 0 deletions src/esi.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,35 @@ public function load_esi_shortcode($params)
$atts_ori[] = is_string($k) ? "$k='" . addslashes($v) . "'" : $v;
}

// Clear registered styles and scripts
global $wp_scripts, $wp_styles;
if($wp_scripts){
foreach($wp_styles->registered as $registered) wp_deregister_style($registered->handle);
}
if($wp_styles){
foreach($wp_scripts->registered as $registered) wp_deregister_script($registered->handle);
}

Tag::add(Tag::TYPE_ESI . "esi.$shortcode");

// Output original shortcode final content
echo do_shortcode("[$shortcode " . implode(' ', $atts_ori) . ' ]');

// Add registered styles and scripts from shortcode.
if(count($wp_styles->registered) > 0){
foreach($wp_styles->registered as $style_tag){
if( !is_bool($style_tag->src) && !empty($style_tag->src)){
echo '<style rel="stylesheet" href="'.$style_tag->src.'" id="'.$style_tag->handle.'">';
}
}
}
if(count($wp_scripts->registered) > 0){
foreach($wp_scripts->registered as $script_tag){
if(!empty($script_tag->src)){
echo '<script src="'.$script_tag->src.'" id="'.$script_tag->handle.'"></script>';
}
}
}
}

/**
Expand Down