-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxds-wp-plugins.php
54 lines (47 loc) · 1.31 KB
/
axds-wp-plugins.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
<?php
/**
* @package axds-wp-plugins
* @version 0.6.0
*/
/*
Plugin Name: Axiom WP Plugins
Plugin URI: http://wordpress.org/plugins/hello-dolly/
Description:
Author: [email protected]
Version: 0.6.0
*/
// Global variable to store all the widget attributes
$widgets = array();
// $tag: the name of the shortcode
function shortcode( $atts = [], $content = null, $tag = '') {
$id = uniqid("widget_");
$atts = array_change_key_case( (array) $atts, CASE_LOWER );
$widget_parameters = array(
'id' => $id,
'type' => $tag,
'parameters' => $atts
);
$GLOBALS['widgets'][$id] = $widget_parameters;
add_parameters();
return "<div id='" . $id . "'>" . $id . "</div>";
}
add_shortcode('widget_1', 'shortcode');
add_shortcode('widget_2', 'shortcode');
add_shortcode('axiom_sensor', 'shortcode');
add_shortcode('axiom_virtual_sensor', 'shortcode');
function add_parameters() {
wp_localize_script( 'axds-wp-plugins', 'widgets', $GLOBALS['widgets'] ); //localize script to pass PHP data to JS
}
// add the react script
add_action('wp_enqueue_scripts', 'enq_axds_wp_plugins');
function enq_axds_wp_plugins(){
wp_register_script(
'axds-wp-plugins',
plugin_dir_url( __FILE__ ) . '/dist/main.js',
['wp-element'],
rand(), // Change this to null for production
true
);
wp_enqueue_script( 'axds-wp-plugins' );
add_parameters();
}