-
Notifications
You must be signed in to change notification settings - Fork 2
/
geocities-blocks.php
94 lines (85 loc) · 2.28 KB
/
geocities-blocks.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
<?php
/**
* Plugin Name: GeoCities Blocks
* Plugin URI: https://github.com/melchoyce/geocities-blocks
* Description:
* Version: 0.0.1
* Author: TBD
* Text Domain: geocities-blocks
*
* @package geocities-blocks
*/
defined( 'ABSPATH' ) || die();
define( 'GEOCITIES_VERSION', '0.0.1' );
define( 'GEOCITIES_DEV_MODE', true );
/**
* Load up the assets if Gutenberg is active.
*/
function geocities_initialize() {
if ( function_exists( 'register_block_type' ) ) {
add_action( 'init', 'geocities_register_block' );
}
}
add_action( 'plugins_loaded', 'geocities_initialize' );
/**
* Register blocks with their scripts.
*/
function geocities_register_block() {
register_block_type(
'geocities/example',
array(
'editor_script' => 'geocities-example-block',
'editor_style' => 'geocities-example-block',
)
);
// Register more blocks here.
}
/**
* Register the scripts & styles needed.
*/
function geocities_gutenberg_scripts() {
wp_register_script(
'geocities-example-block',
plugins_url( 'build/example-block.js', __FILE__ ),
array( 'wp-element', 'wp-blocks', 'wp-components', 'wp-i18n' ),
geocities_get_file_version( 'build/example-block.js' )
);
wp_register_style(
'geocities-example-block',
plugins_url( 'build/example-block.css', __FILE__ ),
array(),
geocities_get_file_version( 'build/example-block.css' )
);
// Register more block scripts & styles here.
}
add_action( 'enqueue_block_editor_assets', 'geocities_gutenberg_scripts' );
/**
* Get the file modified time if we're using SCRIPT_DEBUG.
*
* @param string $file Local path to the file.
* @return string The cache buster value to use for the given file.
*/
function geocities_get_file_version( $file ) {
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
return filemtime( plugin_dir_path( __FILE__ ) . $file );
}
return GEOCITIES_VERSION;
}
/**
* Add a new category for Geocities blocks.
*
* @param array $categories The block categories registered.
* @return array The block categories with the geocities category added.
*/
function geocities_register_block_category( $categories ) {
return array_merge(
$categories,
array(
array(
'slug' => 'geocities',
'title' => __( 'GeoCities', 'geocities-blocks' ),
),
)
);
}
add_filter( 'block_categories', 'geocities_register_block_category' );