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
48 changes: 48 additions & 0 deletions projects/plugins/boost/app/lib/minify/class-concatenate-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ public function do_items( $handles = false, $group = false ) {
}
}

/** This filter is documented in wp-includes/class-wp-scripts.php */
$js_url = esc_url_raw( apply_filters( 'script_loader_src', $js_url, $handle ) );
if ( ! $js_url ) {
$do_concat = false;
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
printf( "\n<!-- No Concat JS %s => No URL -->\n", esc_html( $handle ) );
}
} elseif ( 'module' === $this->get_script_type( $handle, $js_url ) ) {
$do_concat = false;
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
printf( "\n<!-- No Concat JS %s => Module Script -->\n", esc_html( $handle ) );
}
}

/**
* Filter that allows plugins to disable concatenation of certain scripts.
*
Expand Down Expand Up @@ -326,6 +340,40 @@ public function do_items( $handles = false, $group = false ) {
return $this->done;
}

/**
* Returns the type of the script.
* module, text/javascript, etc. False if the script tag is invalid,
* or the type is not set.
*
* @since $$next-version$$
*
* @param string $handle The script's registered handle.
* @param string $src The script's source URL.
*
* @return string|false The type of the script. False if the script tag is invalid,
* or the type is not set.
*/
private function get_script_type( $handle, $src ) {
$script_tag_attr = array(
'src' => $src,
'id' => "$handle-js",
);

// Get the script tag and allow plugins to filter it.
$script_tag = wp_get_script_tag( $script_tag_attr );

// This is a workaround to get the type of the script without outputting it.
$script_tag = apply_filters( 'script_loader_tag', $script_tag, $handle, $src );
$processor = new \WP_HTML_Tag_Processor( $script_tag );

// If for some reason the script tag isn't valid, bail.
if ( ! $processor->next_tag() ) {
return false;
}

return $processor->get_attribute( 'type' );
}

public function __isset( $key ) {
return isset( $this->old_scripts->$key );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Concatenate JS: Exclude scripts of type module from concatenation.
Loading