| 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 |
* @since 5.2 |
| 15 |
*/ |
| 16 |
function eventsmap_block_init() { |
| 17 |
global $EventPost; |
| 18 |
$dir = dirname( __FILE__ ); |
| 19 |
|
| 20 |
$block_js = 'eventsmap/build/index.js'; |
| 21 |
wp_register_script( |
| 22 |
'eventsmap-block-editor', |
| 23 |
plugins_url( $block_js, __FILE__ ), |
| 24 |
array( |
| 25 |
'wp-blocks', |
| 26 |
'wp-i18n', |
| 27 |
'wp-element', |
| 28 |
), |
| 29 |
filemtime( "$dir/$block_js" ) |
| 30 |
); |
| 31 |
|
| 32 |
$editor_css = 'eventsmap/build/style.css'; |
| 33 |
wp_register_style( |
| 34 |
'eventsmap-block-editor', |
| 35 |
plugins_url( $editor_css, __FILE__ ), |
| 36 |
array(), |
| 37 |
filemtime( "$dir/$editor_css" ) |
| 38 |
); |
| 39 |
|
| 40 |
register_block_type( 'eventpost/map', array( |
| 41 |
'editor_script' => 'eventsmap-block-editor', |
| 42 |
'editor_style' => 'eventsmap-block-editor', |
| 43 |
'render_callback' => array($EventPost->Shortcodes, 'shortcode_map'), |
| 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 |
|