-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
100 lines (81 loc) · 2.26 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Plugin Name: Example Blocks
* Description: Troubleshooting block.json expectations.
* Version: 1.0.0
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
namespace JF\ExampleBlocks;
add_action( 'init', __NAMESPACE__ . '\init' );
add_action( 'enqueue_block_assets', __NAMESPACE__ . '\register_block_assets' );
/**
* Register the block using the metadata loaded from the `block.json` file.
*/
function init() {
register_block_type_from_metadata(
__DIR__ . '/example-one/'
);
register_block_type_from_metadata(
__DIR__ . '/example-two/'
);
register_block_type_from_metadata(
__DIR__ . '/example-three/'
);
register_block_type_from_metadata(
__DIR__ . '/example-four/'
);
register_block_type_from_metadata(
__DIR__ . '/example-five/',
array(
'render_callback' => __NAMESPACE__ . '\render_example_five',
)
);
register_block_type_from_metadata(
__DIR__ . '/example-six/',
array(
'render_callback' => __NAMESPACE__ . '\render_example_six',
)
);
}
function register_block_assets() {
$asset_data = require_once __DIR__ . '/build/example-three-view.asset.php';
wp_register_script(
'example-three-view',
plugin_dir_url( __FILE__ ) . 'build/example-three-view.js',
$asset_data['dependencies'],
$asset_data['version'],
true
);
$asset_data = require_once __DIR__ . '/build/example-four-view.asset.php';
wp_register_script(
'example-four-view',
plugin_dir_url( __FILE__ ) . 'build/example-four-view.js',
$asset_data['dependencies'],
$asset_data['version'],
true
);
$asset_data = require_once __DIR__ . '/build/example-five-view.asset.php';
wp_register_script(
'example-five-view',
plugin_dir_url( __FILE__ ) . 'build/example-five-view.js',
$asset_data['dependencies'],
$asset_data['version'],
true
);
$asset_data = require_once __DIR__ . '/build/example-six-view.asset.php';
wp_register_script(
'example-six-view',
plugin_dir_url( __FILE__ ) . 'build/example-six-view.js',
$asset_data['dependencies'],
$asset_data['version'],
true
);
}
function render_example_five() {
return '<h1>Example Five Block</h1>';
}
function render_example_six() {
wp_enqueue_script( 'example-six-view' );
return '<h1>Example Six Block</h1>';
}