PluginProbe
Gutenberg / 8.7.1
Gutenberg v8.7.1
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / block-directory.php

block-directory.php in Gutenberg 8.7.1, at lib/block-directory.php

55 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Block directory functions.
4 *
5 * @package gutenberg
6 */
7
8 if (
9 ! has_action( 'admin_enqueue_scripts', 'enqueue_block_editor_assets_block_directory' )
10 ) {
11 /**
12 * Function responsible for enqueuing the assets required
13 * for the block directory functionality in the editor.
14 *
15 * This filter can be removed when plugin support requires WordPress 5.5.0+.
16 *
17 * @see https://core.trac.wordpress.org/ticket/50321
18 * @see https://core.trac.wordpress.org/changeset/48242
19 */
20 function gutenberg_enqueue_block_editor_assets_block_directory() {
21 wp_enqueue_script( 'wp-block-directory' );
22 wp_enqueue_style( 'wp-block-directory' );
23 }
24 add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_block_editor_assets_block_directory' );
25
26 /**
27 * Add data attribute of handle to all script tags output in the wp-admin.
28 *
29 * This filter can be removed when plugin support requires WordPress 5.5.0+.
30 *
31 * @see https://core.trac.wordpress.org/ticket/48654
32 * @see https://core.trac.wordpress.org/changeset/48295
33 *
34 * @param string $tag The `<script>` tag for the enqueued script.
35 * @param string $handle The script's registered handle.
36 * @param string $esc_src The script's pre-escaped registered src.
37 *
38 * @return string Filtered script tag.
39 */
40 function gutenberg_change_script_tag( $tag, $handle, $esc_src ) {
41 if ( ! is_admin() ) {
42 return $tag;
43 }
44
45 $tag = str_replace(
46 sprintf( "<script src='%s'></script>", $esc_src ),
47 sprintf( "<script data-handle='%s' src='%s'></script>", esc_attr( $handle ), $esc_src ),
48 $tag
49 );
50
51 return $tag;
52 }
53 add_filter( 'script_loader_tag', 'gutenberg_change_script_tag', 1, 3 );
54 }
55