I have developed a javascript plugin retrieving data for my website (no wordpress here). The user can simply add it to its website with a div (the container of the plugin) and a script tag (the plugin). This plugin displays a google map with some fancy information.
As wordpress does not allow the user to add its own js, I try to write a wordpress plugin bypassing this with the wp_register/wp_enqueue functions. My javascript is loaded (so is the google maps api) however the google map is not displayed (the google api is called from my plugin and not from the wp queue scripts).
Any idea/suggestion ?
EDIT: Here is the code of the wp plugin + what is used in the posts to display the widget (can't show the plugin as it is hundreds of lines long, I can only say that it's working on a classical server) :
define ( 'EVP_IDS_PATTERN', '/\[EVP_WIDGET:\{ID:"(\w+)"\},\{TYPE:"(\w+)"\}\]/i' );
functon insert_evp_widget ( $text ) {
if ( is_single ( ) || is_page ( ) ) {
$ids = [];
// The page contains an evp collection ID
if ( preg_match ( EVP_IDS_PATTERN, $text, $ids ) ) {
// We add the script to the page (css is direclty loaded from the widget)
wp_register_script ( 'evp_widget', 'http://widget.evp.com/javascripts/app.js' );
wp_enqueue_script ( 'evp_widget' );
// We add the widget container in the page
$widget = '<div data-evp-id="' . $ids[1] . '" data-evp-type="' . $ids[2] . '"></div>';
$text .= $widget;
// Remove the wordpress widget tag from the article.
$text = preg_replace ( EVP_IDS_PATTERN, '', $text );
return $text;
}
}
}
add_filter ( 'the_content', 'insert_evp_widget' );
Post data used to display the widget :
[EVP_WIDGET:{ID:"Xm9sAzEzMDY"},{type:"album"}]
The widget is supposed to be able to display two kinds of widget : an album and a map version. The album version works (with a API call using json-p), however, the map version does not work (API call using json-p + google maps call). The google scripts are in the page.