Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a more specific <script> matching #23407

Merged
merged 2 commits into from
Jun 24, 2020
Merged
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
18 changes: 12 additions & 6 deletions lib/block-directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,24 @@ function gutenberg_enqueue_block_editor_assets_block_directory() {
/**
* Add data attribute of handle to all script tags output in the wp-admin.
*
* @param string $tag The `<script>` tag for the enqueued script.
* @param string $handle The script's registered handle.
* @param string $tag The `<script>` tag for the enqueued script.
* @param string $handle The script's registered handle.
* @param string $esc_src The script's pre-escaped registered src.
*
* @return string Filter script tag.
* @return string Filtered script tag.
*/
function gutenberg_change_script_tag( $tag, $handle ) {
function gutenberg_change_script_tag( $tag, $handle, $esc_src ) {
if ( ! is_admin() ) {
return $tag;
}
$tag = str_replace( '<script ', sprintf( '<script data-handle="%s" ', esc_attr( $handle ) ), $tag );

$tag = str_replace(
sprintf( "<script src='%s'></script>", $esc_src ),
sprintf( "<script data-handle='%s' src='%s'></script>", esc_attr( $handle ), $esc_src ),
$tag
);

return $tag;
}
add_filter( 'script_loader_tag', 'gutenberg_change_script_tag', 10, 2 );
add_filter( 'script_loader_tag', 'gutenberg_change_script_tag', 1, 3 );
}