| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions to register client-side assets (scripts and stylesheets) for the |
| 4 |
* Gutenberg block. |
| 5 |
* |
| 6 |
* @package event-post |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Registers all block assets so that they can be enqueued through Gutenberg in |
| 11 |
* the corresponding context. |
| 12 |
* |
| 13 |
* @see https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type/#enqueuing-block-scripts |
| 14 |
*/ |
| 15 |
function eventsmap_block_init() { |
| 16 |
global $EventPost; |
| 17 |
$dir = dirname( __FILE__ ); |
| 18 |
|
| 19 |
$block_js = 'eventsmap/block.js'; |
| 20 |
wp_register_script( |
| 21 |
'eventsmap-block-editor', |
| 22 |
plugins_url( $block_js, __FILE__ ), |
| 23 |
array( |
| 24 |
'wp-blocks', |
| 25 |
'wp-i18n', |
| 26 |
'wp-element', |
| 27 |
), |
| 28 |
filemtime( "$dir/$block_js" ) |
| 29 |
); |
| 30 |
|
| 31 |
$editor_css = 'eventsmap/editor.css'; |
| 32 |
wp_register_style( |
| 33 |
'eventsmap-block-editor', |
| 34 |
plugins_url( $editor_css, __FILE__ ), |
| 35 |
array( |
| 36 |
'wp-blocks', |
| 37 |
), |
| 38 |
filemtime( "$dir/$editor_css" ) |
| 39 |
); |
| 40 |
|
| 41 |
register_block_type( 'event-post/eventsmap', array( |
| 42 |
'editor_script' => 'eventsmap-block-editor', |
| 43 |
'editor_style' => 'eventsmap-block-editor', |
| 44 |
) ); |
| 45 |
|
| 46 |
wp_localize_script('eventsmap-block-editor', 'eventpost_gut_params', array( |
| 47 |
'maptiles' => $EventPost->maps, |
| 48 |
'map_interactions'=>$EventPost->map_interactions, |
| 49 |
)); |
| 50 |
} |
| 51 |
add_action( 'init', 'eventsmap_block_init' ); |
| 52 |
|