-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathblock-bindings.php
74 lines (72 loc) · 1.51 KB
/
block-bindings.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
<?php
/**
* Plugin Name: Gutenberg Test Block Bindings
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-block-bindings
*/
/**
* Register custom fields and custom block bindings sources.
*/
function gutenberg_test_block_bindings_registration() {
// Register custom block bindings sources.
register_block_bindings_source(
'core/server-source',
array(
'label' => 'Server Source',
'get_value_callback' => function () {},
)
);
// Register custom fields.
register_meta(
'post',
'text_custom_field',
array(
'show_in_rest' => true,
'type' => 'string',
'single' => true,
'default' => 'Value of the text custom field',
)
);
register_meta(
'post',
'url_custom_field',
array(
'show_in_rest' => true,
'type' => 'string',
'single' => true,
'default' => '#url-custom-field',
)
);
register_meta(
'post',
'empty_field',
array(
'show_in_rest' => true,
'type' => 'string',
'single' => true,
'default' => '',
)
);
register_meta(
'post',
'_protected_field',
array(
'type' => 'string',
'single' => true,
'default' => 'protected field value',
)
);
register_meta(
'post',
'show_in_rest_false_field',
array(
'show_in_rest' => false,
'type' => 'string',
'single' => true,
'default' => 'show_in_rest false field value',
)
);
}
add_action( 'init', 'gutenberg_test_block_bindings_registration' );