-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathblock-directory.php
54 lines (50 loc) · 1.63 KB
/
block-directory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Block directory functions.
*
* @package gutenberg
*/
if (
! has_action( 'admin_enqueue_scripts', 'enqueue_block_editor_assets_block_directory' )
) {
/**
* Function responsible for enqueuing the assets required
* for the block directory functionality in the editor.
*
* This filter can be removed when plugin support requires WordPress 5.5.0+.
*
* @see https://core.trac.wordpress.org/ticket/50321
* @see https://core.trac.wordpress.org/changeset/48242
*/
function gutenberg_enqueue_block_editor_assets_block_directory() {
wp_enqueue_script( 'wp-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.
*
* This filter can be removed when plugin support requires WordPress 5.5.0+.
*
* @see https://core.trac.wordpress.org/ticket/48654
* @see https://core.trac.wordpress.org/changeset/48295
*
* @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 Filtered script tag.
*/
function gutenberg_change_script_tag( $tag, $handle, $esc_src ) {
if ( ! is_admin() ) {
return $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', 1, 3 );
}