-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
65 lines (57 loc) · 1.81 KB
/
plugin.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: Gutenberg Test Block
* Description:
* Version: 1.0
* Requires at least: 5.5
* Requires PHP: 7.4
* Author: Big Bite
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Update URI: https://example.com/my-plugin/
* Text Domain:
*/
// Include our render function.
require_once ( __DIR__ . '/inc/render.php' );
// Enqueue any assets required by the block editor.
function bb_enqueue_editor_assets() {
wp_enqueue_script(
'gutenberg-test-block-script',
plugins_url( 'gutenberg-test/dist/editor.js', ),
[ 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-plugins', 'wp-edit-post' ],
filemtime( plugin_dir_path( __FILE__ ) . 'dist/editor.js' )
);
wp_enqueue_style(
'gutenberg-test-block-style',
plugins_url( 'gutenberg-test/dist/editor.css', ),
[],
filemtime( plugin_dir_path( __FILE__ ) . 'dist/editor.css' )
);
}
add_action( 'enqueue_block_editor_assets', 'bb_enqueue_editor_assets');
// Enqueue any assets for the frontend.
function enqueue_frontend_assets(){
wp_enqueue_script(
'gutenberg-test-block-frontend-script',
plugins_url( 'gutenberg-test/dist/frontend.js', ),
[],
filemtime( plugin_dir_path( __FILE__ ) . 'dist/frontend.js' )
);
wp_enqueue_style(
'gutenberg-test-block-frontend-style',
plugins_url( 'gutenberg-test/dist/frontend.css', ),
[],
filemtime( plugin_dir_path( __FILE__ ) . 'dist/frontend.css' )
);
}
add_action('wp_enqueue_scripts', 'enqueue_frontend_assets');
// Register our block.
function bb_render_block_gutenberg_test() {
register_block_type_from_metadata(
__DIR__ . '/inc/block.json',
[
'render_callback' => 'render_gutenberg_test_block',
]
);
}
add_action( 'init', 'bb_render_block_gutenberg_test', 2 );