-
Notifications
You must be signed in to change notification settings - Fork 2
/
gutenberg-example.php
54 lines (48 loc) · 1.27 KB
/
gutenberg-example.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
<?php
/**
* Plugin Name: Gutenberg Example
* Description: Example plugin for creating custom Gutenberg blocks.
* Version: 1.0.0
*
* @since 1.0.0
* @package example
*/
namespace example;
const VERSION = '1.0.0';
function wp_debug() {
return defined( 'WP_DEBUG' ) && WP_DEBUG;
}
function register_blocks() {
register_block_type( 'example/example-block', array(
'editor_script' => 'example-block-editor',
'editor_style' => 'example-block-editor'
) );
}
add_action( 'init', 'example\register_blocks' );
function register_block_assets() {
if ( wp_debug() ) {
$script = "build/block.bundle.js";
} else {
$script = "build/block.production.min.js";
}
$deps = array(
'wp-blocks',
'wp-i18n',
'wp-element',
'wp-components'
);
$version = VERSION;
if ( wp_debug() ) {
$version = filemtime( plugin_dir_path( __FILE__ ) . $script );
}
wp_register_script( 'example-block-editor', plugins_url( $script , __FILE__ ), $deps, $version );
}
add_action( 'init', 'example\register_block_assets' );
function register_pinned_meta() {
register_meta( 'post', 'example_is_pinned', array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
) );
}
add_action( 'init', 'example\register_pinned_meta' );