This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.php
80 lines (63 loc) · 2.22 KB
/
plugin.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
<?php
/*
Plugin Name: Matts Gutenberg Maps Test
Plugin URI: http://matth.eu
Description: Testing Gutenberg
Version: 1.0
Author: Matthew Haines-Young
Author URI: http://matth.eu
*/
namespace Mattheu\GutenbergMapBoxBlock;
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\register_scripts', 1 );
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\register_scripts', 1 );
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_block_editor_assets' );
add_action( 'enqueue_block_assets', __NAMESPACE__ . '\\enqueue_block_assets' );
function register_scripts() {
wp_register_style(
'mattheu-gb-map-test-mapbox',
'https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.css'
);
wp_register_script(
'mattheu-gb-map-test-mapbox',
'https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.js'
);
wp_register_style(
'mattheu-gb-map-test-mapbox-geocoder',
'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.1.0/mapbox-gl-geocoder.css'
);
wp_register_script(
'mattheu-gb-map-test-mapbox-geocoder',
'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.1.0/mapbox-gl-geocoder.min.js'
);
}
function enqueue_block_editor_assets() {
wp_enqueue_script(
'mattheu-gb-map-test',
plugins_url( 'js/build/editor.bundle.js', __FILE__ ),
[ 'wp-blocks', 'wp-element', 'mattheu-gb-map-test-mapbox', 'mattheu-gb-map-test-mapbox-geocoder' ]
);
wp_localize_script( 'mattheu-gb-map-test', 'mattheuGbMapTestData', [
'mapboxKey' => defined( 'MATTHEU_GB_MB_TEST_KEY' ) ? MATTHEU_GB_MB_TEST_KEY : null,
] );
wp_enqueue_style( 'mattheu-gb-map-test-mapbox-geocoder' );
}
function enqueue_block_assets() {
if ( ! is_admin() ) {
wp_enqueue_script(
'mattheu-gb-map-test',
plugins_url( 'js/build/frontend.bundle.js', __FILE__ ),
[ 'mattheu-gb-map-test-mapbox', 'wp-element' ],
'0.1',
true
);
wp_localize_script( 'mattheu-gb-map-test', 'mattheuGbMapTestData', [
'mapboxKey' => defined( 'MATTHEU_GB_MB_TEST_KEY' ) ? MATTHEU_GB_MB_TEST_KEY : null,
] );
}
wp_enqueue_style(
'mattheu-gb-map-test',
plugins_url( 'css/editor.css', __FILE__ ),
[ 'mattheu-gb-map-test-mapbox' ],
filemtime( plugin_dir_path( __FILE__ ) . '/css/editor.css' )
);
}