create plugin menu and message if posts without address
This commit is contained in:
@@ -143,32 +143,32 @@ function mp_fill_fields_value($id) {
|
||||
function mp_get_published_events() {
|
||||
$posts_list = mp_get_published_posts();
|
||||
|
||||
mp_console_log("posts :");
|
||||
mp_console_log($posts_list);
|
||||
foreach ($posts_list as $post) {
|
||||
mp_console_log("--------------- post :");
|
||||
$id = $post->ID;
|
||||
mp_console_log("id: " . $id);
|
||||
// mp_console_log("posts :");
|
||||
// mp_console_log($posts_list);
|
||||
// foreach ($posts_list as $post) {
|
||||
// mp_console_log("--------------- post :");
|
||||
// $id = $post->ID;
|
||||
// mp_console_log("id: " . $id);
|
||||
// mp_console_log("adresse: " . $event->adresse);
|
||||
// mp_console_log("pays: " . $event->pays);
|
||||
// mp_console_log("ville: " . $event->ville);
|
||||
// mp_console_log("irl: " . $event->irl);
|
||||
// mp_console_log($event);
|
||||
//
|
||||
$fields = get_fields($id);
|
||||
mp_console_log("fields:");
|
||||
mp_console_log($fields);
|
||||
$field_heure = get_field("heure_de_debut", $id);
|
||||
mp_console_log("field_heure: " . $field_heure);
|
||||
$post_metas = get_post_meta($id);
|
||||
mp_console_log("post_metas:");
|
||||
mp_console_log($post_metas);
|
||||
$post_custom = get_post_custom($id);
|
||||
mp_console_log("post_custom:");
|
||||
mp_console_log($post_custom);
|
||||
// $fields = get_fields($id);
|
||||
// mp_console_log("fields:");
|
||||
// mp_console_log($fields);
|
||||
// $field_heure = get_field("heure_de_debut", $id);
|
||||
// mp_console_log("field_heure: " . $field_heure);
|
||||
// $post_metas = get_post_meta($id);
|
||||
// mp_console_log("post_metas:");
|
||||
// mp_console_log($post_metas);
|
||||
// $post_custom = get_post_custom($id);
|
||||
// mp_console_log("post_custom:");
|
||||
// mp_console_log($post_custom);
|
||||
// foreach( $fields as $name => $value )
|
||||
// mp_console_log($name . " : " . $value);
|
||||
}
|
||||
// }
|
||||
|
||||
$events = [];
|
||||
foreach ($posts_list as $post) {
|
||||
|
||||
91
srcs/plugins/map_prof/srcs/menu/mp_menu_content.php
Normal file
91
srcs/plugins/map_prof/srcs/menu/mp_menu_content.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
function mp_get_all_posts() {
|
||||
|
||||
$get_posts_args = array(
|
||||
'numberposts' => -1,
|
||||
'post_type' => 'post',
|
||||
);
|
||||
$posts_list = get_posts($get_posts_args);
|
||||
|
||||
return $posts_list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_have_address($posts_list) {
|
||||
|
||||
$posts_no_address = [];
|
||||
foreach ($posts_list as $post) {
|
||||
$address = mp_get_address($post->ID);
|
||||
if (empty($address))
|
||||
array_push($posts_no_address, $post);
|
||||
}
|
||||
return $posts_no_address;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_show_list_posts_no_address($posts) {
|
||||
|
||||
echo <<<HTML
|
||||
<div style="border: 1px solid red; margin-right: 20px; padding: 0px 20px;">
|
||||
<p style="color: red;">
|
||||
<b>ATTENTION !</b>
|
||||
</p>
|
||||
<p>
|
||||
<b>
|
||||
HTML;
|
||||
echo count($posts);
|
||||
echo <<<HTML
|
||||
</b>
|
||||
articles n'ont pas d'adresse :
|
||||
</p>
|
||||
<ul style="list-style: square inside;">
|
||||
HTML;
|
||||
foreach ($posts as $post) {
|
||||
echo <<<HTML
|
||||
<li><b>
|
||||
HTML;
|
||||
echo 'id: ';
|
||||
echo $post->ID;
|
||||
echo ' (status: ';
|
||||
echo $post->post_status;
|
||||
echo ') - ';
|
||||
echo $post->mode[0];
|
||||
echo ' : </b>';
|
||||
echo $post->post_title;
|
||||
echo <<<HTML
|
||||
</li>
|
||||
HTML;
|
||||
}
|
||||
echo <<<HTML
|
||||
</ul>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function ljdp_map_plugin_content() {
|
||||
|
||||
$posts_list = mp_get_all_posts();
|
||||
|
||||
$posts_no_address = mp_have_address($posts_list);
|
||||
mp_console_log("posts_no_address: ");
|
||||
mp_console_log($posts_no_address);
|
||||
|
||||
echo <<<HTML
|
||||
<div>
|
||||
<h2>ljdp map plugin</h2>
|
||||
HTML;
|
||||
|
||||
if (count($posts_no_address) > 0)
|
||||
mp_show_list_posts_no_address($posts_no_address);
|
||||
|
||||
echo <<<HTML
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,5 +1,17 @@
|
||||
<?php
|
||||
|
||||
function mp_get_address($id) {
|
||||
$presentiel = get_field("mode", $id);
|
||||
|
||||
// irl or online
|
||||
if ($presentiel[0] === "En présentiel")
|
||||
$address = get_field("adresse", $id);
|
||||
else
|
||||
$address = get_field("pays", $id);
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
function mp_get_coordinates($id) {
|
||||
global $mp_api_key;
|
||||
$event = (object)[];
|
||||
@@ -11,17 +23,8 @@ function mp_get_coordinates($id) {
|
||||
$location->address = "";
|
||||
$location->approximate = false;
|
||||
|
||||
// get address
|
||||
$address = "";
|
||||
$fields = array(
|
||||
"adresse",
|
||||
"ville",
|
||||
"pays",
|
||||
);
|
||||
foreach($fields as $field) {
|
||||
$address_section = get_field($field, $id);
|
||||
$address .= $address_section . ",";
|
||||
}
|
||||
$address = mp_get_address($id);
|
||||
mp_console_log("adresse: " . $address);
|
||||
|
||||
// get coordinates from google maps api
|
||||
$geolocation = 'https://maps.googleapis.com/maps/api/geocode/json'
|
||||
@@ -56,6 +59,7 @@ function mp_get_coordinates($id) {
|
||||
if ($content->results[0]->geometry->location_type == "APPROXIMATE")
|
||||
$location->approximate = true;
|
||||
|
||||
// clean strings
|
||||
foreach ($location as $value) {
|
||||
if (gettype($value) != "string")
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user