99 lines
2.4 KiB
PHP
Executable File
99 lines
2.4 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* @package map_prof
|
|
* @version 1.0.0
|
|
*/
|
|
/*
|
|
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:
|
|
*/
|
|
|
|
// if bock theme : https://wordpress.org/support/topic/twenty-twenty-two-cpt-template-error-theme-without-header-is-deprecated/
|
|
function add_map_api(){
|
|
?>
|
|
<script type="text/javascript" src="https://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
|
|
<script type="text/javascript" defer>
|
|
//<![CDATA[
|
|
import Map from 'ol/Map';
|
|
import View from 'ol/View';
|
|
import OSM from 'ol/source/OSM';
|
|
import TileLayer from 'ol/layer/Tile';
|
|
|
|
new Map({
|
|
layers: [
|
|
new TileLayer({source: new OSM()}),
|
|
],
|
|
view: new View({
|
|
center: [0, 0],
|
|
zoom: 2,
|
|
}),
|
|
target: 'map',
|
|
});
|
|
//]]>
|
|
</script>
|
|
<?php
|
|
}
|
|
add_action('wp_head', 'add_map_api');
|
|
|
|
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') && 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'><p>OSM map 2</p></div>";
|
|
return $content;
|
|
};
|
|
add_action('the_content', 'print_content', 1);
|
|
|
|
?>
|