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

Add data-handle to all script tags in the admin. #22721

Merged
merged 3 commits into from
Jun 4, 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: 18 additions & 0 deletions lib/block-directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,22 @@ function gutenberg_enqueue_block_editor_assets_block_directory() {
wp_enqueue_style( 'wp-block-directory' );
}
add_action( 'enqueue_block_editor_assets', '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.
*
* @return string Filter script tag.
*/
function gutenberg_change_script_tag( $tag, $handle ) {
if ( ! is_admin() ) {
return $tag;
}
$tag = str_replace( '<script ', sprintf( '<script data-handle="%s" ', esc_attr( $handle ) ), $tag );

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