Files
2023_WEBSITE_jipf/srcs/plugins/map_prof/map_prof.php
lenovo 039134cd96 plugin succed to : get published posts
+                    print them onlly in map page
+ wordpress plugin directory changed to save work in git
2022-10-23 21:44:38 +02:00

80 lines
1.8 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:
*/
$markers = array("two");
add_action('draft_to_publish', 'add_marker');
function add_marker(){
array_push($markers, "one");
}
add_action('the_content', 'print_content', 1);
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>";
//}
return $content;
};
?>