133 lines
3.6 KiB
Plaintext
133 lines
3.6 KiB
Plaintext
<?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:
|
|
*/
|
|
|
|
include_once('./console_log.php');
|
|
//require_once('./mp_gapi.php');
|
|
|
|
function wpa_enqueue_scripts() {
|
|
$path = plugins_url('mp_style.css', __FILE__);
|
|
wp_enqueue_style('mp_style', $path, [], null, false);
|
|
|
|
// $path = mp_url_api();
|
|
// wp_enqueue_script('mp_gapi', $path, [], null, true);
|
|
|
|
$path = plugins_url('mp_create_map.js', __FILE__);
|
|
// wp_enqueue_script('mp_create_map', $path, ['mp_gapi'], null, true);
|
|
wp_enqueue_script('mp_create_map', $path, [], null, true);
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'wpa_enqueue_scripts' );
|
|
|
|
function mp_add_div() {
|
|
$mp_api_script = '<div id="map"></div>';
|
|
return $mp_api_script;
|
|
}
|
|
function mp_add_api() {
|
|
$mp_create_url = array(
|
|
'src' => 'https://maps.googleapis.com/maps/api/js',
|
|
'key' => 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE',
|
|
'callback' => 'mp_init_map',
|
|
);
|
|
$mp_src = "";
|
|
foreach ($mp_create_url as $url_key => $url_value) {
|
|
if ($url_key === 'src') {
|
|
$mp_src .= $url_value;
|
|
if (count($mp_create_url > 1))
|
|
$mp_src .= "?";
|
|
}
|
|
else
|
|
$mp_src .= "&" . $url_key . "=" . $url_value;
|
|
};
|
|
|
|
$mp_api_script = '<script async defer ';
|
|
$mp_api_script .= 'src="' . $mp_src . '"></script>';
|
|
return $mp_api_script;
|
|
}
|
|
function show_map() {
|
|
$mp_api_script = mp_add_div();
|
|
$mp_api_script .= mp_add_api();
|
|
return $mp_api_script;
|
|
}
|
|
add_shortcode('lejourduprof_map', 'show_map');
|
|
//add_shortcode('lejourduprof_map', 'mp_add_div');
|
|
|
|
|
|
//function print_content($content){
|
|
//
|
|
// // print only on the page 'map', and other conditions
|
|
// // https://developer.wordpress.org/reference/hooks/the_content/
|
|
// if (!( is_page('map_prof') && in_the_loop() && is_main_query() ))
|
|
// return $content;
|
|
//
|
|
// // https://developer.wordpress.org/reference/functions/get_posts/
|
|
// $get_posts_args = array(
|
|
// 'numberposts' => -1,
|
|
// 'post_status' => 'publish',
|
|
// );
|
|
//
|
|
// $posts_list = get_posts($get_posts_args);
|
|
// $content .= "<p>";
|
|
// $content .= "nb posts published : ";
|
|
// $content .= count($posts_list);
|
|
// $content .= "</p>";
|
|
// foreach ($posts_list as $post_value) {
|
|
// $content .= "<div>";
|
|
// $content .= "- post title: [";
|
|
// $content .= $post_value->post_title;
|
|
// $content .= "] - content: [";
|
|
// $content .= $post_value->post_content;
|
|
// $content .= "]";
|
|
// $content .= "</div>";
|
|
// }
|
|
//
|
|
// // TESTS : print posts full content
|
|
// //
|
|
// //$posts_list = get_posts($args);
|
|
// //$content .= "<p>";
|
|
// //$content .= "nb posts published : ";
|
|
// //$content .= count($posts_list);
|
|
// //$content .= "</p>";
|
|
// //foreach ($posts_list as $post_key => $post_value) {
|
|
// // $content .= "<p>";
|
|
// // $content .= "post content : ";
|
|
// // $content .= $post_key;
|
|
// // $content .= " : ";
|
|
// // $content .= "<br>";
|
|
// // foreach ($post_value as $key => $value) {
|
|
// // $content .= "- [";
|
|
// // $content .= $key;
|
|
// // $content .= "]: [";
|
|
// // $content .= $value;
|
|
// // $content .= "]<br>";
|
|
// // }
|
|
// // $content .= "</p>";
|
|
// //}
|
|
//
|
|
// $content .= '<div id="map"></div>';
|
|
// $content .= '<script>
|
|
// function initMap() {
|
|
// var location = {lat: 38.8833, lng: -77.0167};
|
|
// var map = new google.maps.Map(document.getElementById("map"), {
|
|
// zoom: 12,
|
|
// center: location
|
|
// });
|
|
// var marker = new google.maps.Marker({
|
|
// position: location,
|
|
// map: map
|
|
// });
|
|
// }
|
|
// </script>';
|
|
// $content .= '<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE&callback=initMap"></script>';
|
|
//
|
|
// return $content;
|
|
//};
|
|
//add_action('the_content', 'print_content', 1);
|
|
|
|
?>
|