| @@ -1,53 +1,35 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Functions to register client-side assets (scripts and stylesheets) for the | |
| 4 | - * Gutenberg block. | |
| 3 | + * Functions to register client-side assets (scripts and stylesheets) for the Gutenberg block. | |
| 5 | 4 | * |
| 6 | 5 | * @package event-post |
| 6 | + * @version 6.1.2 | |
| 7 | + * @since 5.2 | |
| 8 | + * @see https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type/#enqueuing-block-scripts | |
| 7 | 9 | */ |
| 8 | 10 | |
| 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 | |
| 11 | + if ( ! defined( 'ABSPATH' ) ) exit; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * Registers eventpost/map block | |
| 15 | 15 | */ |
| 16 | + | |
| 16 | 17 | function eventsmap_block_init() { |
| 17 | - global $EventPost; | |
| 18 | 18 | $dir = dirname( __DIR__ ); |
| 19 | - $dir_path = $EventPost->plugin_path; | |
| 20 | - $block_js = 'js/block-map.min.js'; | |
| 19 | + $dir_path = EventPost()->plugin_path; | |
| 20 | + $block_js = 'build/map/index.js'; | |
| 21 | 21 | |
| 22 | - wp_register_script( | |
| 23 | - 'event-post-map-block-editor', | |
| 24 | - plugins_url( $block_js, $dir ), | |
| 25 | - array( | |
| 26 | - 'wp-blocks', | |
| 27 | - 'wp-i18n', | |
| 28 | - 'wp-element', | |
| 29 | - ), | |
| 30 | - filemtime( "$dir_path/$block_js" ) | |
| 31 | - ); | |
| 32 | - wp_set_script_translations( 'event-post-map-block-editor', 'event-post' ); | |
| 22 | + wp_register_script('eventpost-map-editor-script',plugins_url( $block_js, $dir ),array( 'wp-blocks', 'wp-i18n', 'wp-element', 'event-post-map'),filemtime( "$dir_path/$block_js" )); | |
| 23 | + wp_add_inline_script('eventpost-map-editor-script', 'var EventPost = EventPost || {}; EventPost.GutParams='.wp_json_encode(array('maptiles' => EventPost()->maps,'map_interactions'=>EventPost()->map_interactions,)), 'before'); | |
| 33 | 24 | |
| 34 | - $editor_css = 'css/block-map.css'; | |
| 35 | - wp_register_style( | |
| 36 | - 'event-post-map-block-editor', | |
| 37 | - plugins_url( $editor_css, $dir ), | |
| 38 | - array(), | |
| 39 | - filemtime( "$dir_path/$editor_css" ) | |
| 40 | - ); | |
| 25 | + wp_register_style('event-post-map', plugins_url('/build/map/event-map.css', $dir), []); | |
| 26 | + wp_register_script('event-post-map', plugins_url( '/build/map/event-map.js', $dir ), ['jquery'], false, true); | |
| 41 | 27 | |
| 42 | - wp_localize_script('event-post-map-block-editor', 'eventpost_gut_params', array( | |
| 43 | - 'maptiles' => $EventPost->maps, | |
| 44 | - 'map_interactions'=>$EventPost->map_interactions, | |
| 28 | + \register_block_type( $dir_path . '/build/map', array( | |
| 29 | + 'editor_script' => 'eventpost-map-editor-script', | |
| 30 | + 'script' => 'event-post-map', | |
| 31 | + 'style' => 'event-post-map', | |
| 32 | + 'render_callback' => array(EventPost()->Shortcodes, 'shortcode_map'), | |
| 45 | 33 | )); |
| 46 | - | |
| 47 | - register_block_type( 'eventpost/map', array( | |
| 48 | - 'editor_script' => 'event-post-map-block-editor', | |
| 49 | - 'editor_style' => 'event-post-map-block-editor', | |
| 50 | - 'render_callback' => array($EventPost->Shortcodes, 'shortcode_map'), | |
| 51 | - ) ); | |
| 52 | 34 | } |
| 53 | -add_action( 'init', 'eventsmap_block_init' ); | |
| 35 | +add_action( 'wp_loaded', 'eventsmap_block_init' ); | |