-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello-block.php
56 lines (51 loc) · 1.4 KB
/
hello-block.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
<?php
/**
* Functions to register client-side assets (scripts and stylesheets) for the
* Gutenberg block.
*
* @package my-guten-block
*/
/**
* Registers all block assets so that they can be enqueued through Gutenberg in
* the corresponding context.
*
* @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/block-tutorial/applying-styles-with-stylesheets/
*/
function hello_block_block_init() {
// Skip block registration if Gutenberg is not enabled/merged.
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
$dir = dirname( __FILE__ );
$index_js = 'hello-block/index.js';
wp_register_script(
'hello-block-block-editor',
plugins_url( $index_js, __FILE__ ),
array(
'wp-blocks',
'wp-i18n',
'wp-element',
),
filemtime( "$dir/$index_js" )
);
$editor_css = 'hello-block/editor.css';
wp_register_style(
'hello-block-block-editor',
plugins_url( $editor_css, __FILE__ ),
array(),
filemtime( "$dir/$editor_css" )
);
$style_css = 'hello-block/style.css';
wp_register_style(
'hello-block-block',
plugins_url( $style_css, __FILE__ ),
array(),
filemtime( "$dir/$style_css" )
);
register_block_type( 'my-guten-block/hello-block', array(
'editor_script' => 'hello-block-block-editor',
'editor_style' => 'hello-block-block-editor',
'style' => 'hello-block-block',
) );
}
add_action( 'init', 'hello_block_block_init' );