| 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 eventpost_list_block_init() { |
| 17 |
global $EventPost; |
| 18 |
$dir = dirname( __FILE__ ); |
| 19 |
|
| 20 |
wp_register_script( |
| 21 |
'eventpost-blocks', |
| 22 |
plugins_url( 'index.js', __FILE__ ), |
| 23 |
array( |
| 24 |
'wp-blocks', |
| 25 |
'wp-editor', |
| 26 |
'wp-components', |
| 27 |
'wp-i18n', |
| 28 |
'wp-element', |
| 29 |
) |
| 30 |
); |
| 31 |
wp_enqueue_script('eventpost-blocks'); |
| 32 |
|
| 33 |
|
| 34 |
$block_js = 'eventslist/build/index.js'; |
| 35 |
wp_register_script( |
| 36 |
'eventslist-block-editor', |
| 37 |
plugins_url( $block_js, __FILE__ ), |
| 38 |
array( |
| 39 |
'wp-blocks', |
| 40 |
'wp-editor', |
| 41 |
'wp-components', |
| 42 |
'wp-i18n', |
| 43 |
'wp-element', |
| 44 |
), |
| 45 |
filemtime( "$dir/$block_js" ) |
| 46 |
); |
| 47 |
|
| 48 |
if ( function_exists('wp_set_script_translations') ) { |
| 49 |
wp_set_script_translations( 'eventslist-block-editor', 'event-post' ); |
| 50 |
} |
| 51 |
|
| 52 |
$editor_css = 'eventslist/build/style.css'; |
| 53 |
wp_register_style( |
| 54 |
'eventslist-block-editor', |
| 55 |
plugins_url( $editor_css, __FILE__ ), |
| 56 |
array(), |
| 57 |
filemtime( "$dir/$editor_css" ) |
| 58 |
); |
| 59 |
|
| 60 |
register_block_type( 'eventpost/list', array( |
| 61 |
'editor_script' => 'eventslist-block-editor', |
| 62 |
'editor_style' => 'eventslist-block-editor', |
| 63 |
'render_callback' => array($EventPost->Shortcodes, 'shortcode_list'), |
| 64 |
) ); |
| 65 |
} |
| 66 |
add_action( 'init', 'eventpost_list_block_init' ); |
| 67 |
|