-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks-assets.php
65 lines (63 loc) · 2.04 KB
/
hooks-assets.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
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Plugin Name: Hooks Assets
* Description: Example for loading assets using hooks.
* Requires at least: 6.1
* Requires PHP: 7.0
* Version: 0.1.0
* Author: The WordPress Contributors
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: hooks-assets
*/
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function enqueue_block_assets_register_scripts_and_styles() {
wp_enqueue_style(
'enqueue_block_assets_style_body',
plugins_url( 'body.css', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'body.css' )
);
wp_enqueue_style(
'enqueue_block_assets_style_wp_block',
plugins_url( 'wp-block.css', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'wp-block.css' )
);
wp_enqueue_script(
'enqueue_block_assets_script',
plugins_url( 'console.js', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'console.js' ),
true
);
}
add_action( 'enqueue_block_assets', 'enqueue_block_assets_register_scripts_and_styles' );
function enqueue_block_editor_assets_register_scripts_and_styles() {
wp_enqueue_style(
'enqueue_block_editor_assets_style_body',
plugins_url( 'body.css', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'body.css' )
);
wp_enqueue_style(
'enqueue_block_editor_assets_style_wp_block',
plugins_url( 'wp-block.css', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'wp-block.css' )
);
wp_enqueue_script(
'enqueue_block_editor_assets_script',
plugins_url( 'console-editor.js', __FILE__ ),
array( 'wp-dom' ),
filemtime( plugin_dir_path( __FILE__ ) . 'console-editor.js' ),
true
);
}
add_action( 'enqueue_block_editor_assets', 'enqueue_block_editor_assets_register_scripts_and_styles' );