87 lines
2.1 KiB
PHP
87 lines
2.1 KiB
PHP
<?php
|
|
/*
|
|
Plugin Name: map_prof
|
|
Plugin URI:
|
|
Description: add/remove locations on map at publication/deletion of posts
|
|
Author: hugogogo
|
|
Version: 1.0.0
|
|
Author URI:
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
* inclusions :
|
|
*/
|
|
|
|
include_once(dirname(__FILE__) . '/mp_console_log.php');
|
|
require_once(dirname(__FILE__) . '/mp_url_api.php');
|
|
require_once(dirname(__FILE__) . '/mp_add_to_scripts.php');
|
|
require_once(dirname(__FILE__) . '/settings/mp_required.php');
|
|
require_once(dirname(__FILE__) . '/settings/mp_optionnals.php');
|
|
|
|
|
|
|
|
/**
|
|
* global variables :
|
|
*/
|
|
|
|
$mp_icon_url = '/wp-content/plugins/map_prof/images/' . $mp_icon_file;
|
|
$mp_icon_size = [50, 50];
|
|
if (isset($mp_icon_size_setting)) {
|
|
if (is_array($mp_icon_size_setting)) {
|
|
if (count($mp_icon_size_setting) === 2) {
|
|
if ( is_numeric($mp_icon_size_setting[0]) && is_numeric($mp_icon_size_setting[1]) ) {
|
|
$mp_icon_size = $mp_icon_size_setting;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//$mp_icon_label_color = "red";
|
|
|
|
|
|
|
|
/**
|
|
* add scripts and styles to the header or the footer
|
|
*/
|
|
|
|
function mp_enqueue_scripts() {
|
|
// https://developers.google.com/maps/documentation/javascript/marker-clustering
|
|
$marker_clusterer = "https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js";
|
|
|
|
wp_enqueue_style( 'mp_style', plugins_url('styles/mp_style.css', __FILE__), '', '', '');
|
|
wp_enqueue_script('mp_marker_clusterer', $marker_clusterer, '', '', true);
|
|
wp_enqueue_script('mp_init_map', plugins_url('scripts/mp_init_map.js', __FILE__), ['mp_marker_clusterer'],'', true);
|
|
wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
|
|
|
|
mp_add_to_scripts();
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'mp_enqueue_scripts' );
|
|
|
|
|
|
|
|
/**
|
|
* to add a tag, like defer or async, to a script
|
|
*/
|
|
|
|
function mp_tag_scripts($tag, $handle) {
|
|
if ('mp_googe_api' === $handle)
|
|
return str_replace(' src="', ' async src="', $tag);
|
|
return $tag;
|
|
}
|
|
add_filter('script_loader_tag', 'mp_tag_scripts', 10, 2);
|
|
|
|
|
|
|
|
/**
|
|
* when 'shortcode' found in page, replace by return
|
|
*/
|
|
|
|
function mp_add_div() {
|
|
$mp_api_script = '<div id="ljdp_map">map here</div>';
|
|
return $mp_api_script;
|
|
}
|
|
add_shortcode('lejourduprof_map', 'mp_add_div');
|
|
|
|
?>
|