From feef306cec332d2d6a3560668f7993290783474a Mon Sep 17 00:00:00 2001 From: lenovo Date: Mon, 31 Oct 2022 15:00:57 +0100 Subject: [PATCH] start importing data from posts --- srcs/plugins/map_prof/map_prof_hooks.php | 72 --------------------- srcs/plugins/map_prof/mp_add_to_scripts.php | 67 ++++++++++++++++--- 2 files changed, 58 insertions(+), 81 deletions(-) diff --git a/srcs/plugins/map_prof/map_prof_hooks.php b/srcs/plugins/map_prof/map_prof_hooks.php index b7cd760..7dcd655 100644 --- a/srcs/plugins/map_prof/map_prof_hooks.php +++ b/srcs/plugins/map_prof/map_prof_hooks.php @@ -52,76 +52,4 @@ function mp_add_div() { } 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 .= "

"; -// $content .= "nb posts published : "; -// $content .= count($posts_list); -// $content .= "

"; -// foreach ($posts_list as $post_value) { -// $content .= "
"; -// $content .= "- post title: ["; -// $content .= $post_value->post_title; -// $content .= "] - content: ["; -// $content .= $post_value->post_content; -// $content .= "]"; -// $content .= "
"; -// } -// -// // TESTS : print posts full content -// // -// //$posts_list = get_posts($args); -// //$content .= "

"; -// //$content .= "nb posts published : "; -// //$content .= count($posts_list); -// //$content .= "

"; -// //foreach ($posts_list as $post_key => $post_value) { -// // $content .= "

"; -// // $content .= "post content : "; -// // $content .= $post_key; -// // $content .= " : "; -// // $content .= "
"; -// // foreach ($post_value as $key => $value) { -// // $content .= "- ["; -// // $content .= $key; -// // $content .= "]: ["; -// // $content .= $value; -// // $content .= "]
"; -// // } -// // $content .= "

"; -// //} -// -// $content .= '
'; -// $content .= ''; -// $content .= ''; -// -// return $content; -//}; -//add_action('the_content', 'print_content', 1); - ?> diff --git a/srcs/plugins/map_prof/mp_add_to_scripts.php b/srcs/plugins/map_prof/mp_add_to_scripts.php index de84932..3434c0a 100644 --- a/srcs/plugins/map_prof/mp_add_to_scripts.php +++ b/srcs/plugins/map_prof/mp_add_to_scripts.php @@ -1,17 +1,66 @@ "; +// //$content .= "nb posts published : "; +// //$content .= count($posts_list); +// //$content .= "

"; +// //foreach ($posts_list as $post_key => $post_value) { +// // $content .= "

"; +// // $content .= "post content : "; +// // $content .= $post_key; +// // $content .= " : "; +// // $content .= "
"; +// // foreach ($post_value as $key => $value) { +// // $content .= "- ["; +// // $content .= $key; +// // $content .= "]: ["; +// // $content .= $value; +// // $content .= "]
"; +// // } +// // $content .= "

"; +// //} + function mp_get_locations() { - $locations = ' - let locations = [ - {lat: 38.8833, lng: -77.0167}, - {lat: 39.8833, lng: -76.0167}, - ]; - '; + + // https://developer.wordpress.org/reference/functions/get_posts/ + $get_posts_args = array( + 'numberposts' => -1, + 'post_status' => 'publish', + ); + $posts_list = get_posts($get_posts_args); + $locs = ""; + foreach ($posts_list as $post_key => $post_value) { + $locs .= "\n" + . 'post_key: ' + . $post_key . "\n" + . 'post_value: ' . "\n"; + foreach ($post_value as $key => $value) { + $locs .= " " + . $key + . ': ' + . $value . "\n" + ; + }; + }; + mp_console_log("locs : \n" . $locs); + + $locations = + 'let locations = [' + . '{lat: 38.8833, lng: -77.0167}' . ',' + . '{lat: 39.8833, lng: -76.0167}' . ',' + . '];' + ; wp_add_inline_script('mp_init_map', $locations, 'before'); } function mp_get_markers() { - $markers = 'let icon_url = "' - . '/wp-content/plugins/map_prof/marker.png' - . '";'; + $markers = + 'let icon_url = "' + . '/wp-content/plugins/map_prof/marker.png' + . '";' + ; wp_add_inline_script('mp_init_map', $markers, 'before'); } ?>