create plugin menu and message if posts without address
This commit is contained in:
13
README.md
13
README.md
@@ -23,6 +23,13 @@
|
|||||||
|
|
||||||
## 1.2. todo
|
## 1.2. todo
|
||||||
|
|
||||||
|
- [ ] create wp plugin menu
|
||||||
|
- [ ] add infos in menu
|
||||||
|
- [ ] gmaps api key
|
||||||
|
- [ ] missing addresses
|
||||||
|
- [ ]
|
||||||
|
- [ ]
|
||||||
|
- [ ]
|
||||||
- [ ]
|
- [ ]
|
||||||
|
|
||||||
## 1.3. temps de travail
|
## 1.3. temps de travail
|
||||||
@@ -115,9 +122,13 @@
|
|||||||
|
|
||||||
- 21/09/23
|
- 21/09/23
|
||||||
- begin: 9h45
|
- begin: 9h45
|
||||||
|
- mes: "understand how custom fields works"
|
||||||
|
- end: 12h45
|
||||||
|
- len: 3h00
|
||||||
|
- begin: 15h15
|
||||||
- mes: ""
|
- mes: ""
|
||||||
- end: h
|
- end: h
|
||||||
- len: h
|
- len: 3h
|
||||||
- total: h
|
- total: h
|
||||||
- money: €
|
- money: €
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ require_once(dirname(__FILE__) . '/srcs/map_posts/mp_post_events_pages.php');
|
|||||||
require_once(dirname(__FILE__) . '/srcs/publish/mp_get_coordinates.php');
|
require_once(dirname(__FILE__) . '/srcs/publish/mp_get_coordinates.php');
|
||||||
require_once(dirname(__FILE__) . '/srcs/publish/mp_update_publish.php');
|
require_once(dirname(__FILE__) . '/srcs/publish/mp_update_publish.php');
|
||||||
|
|
||||||
|
require_once(dirname(__FILE__) . '/srcs/menu/mp_menu_content.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -54,8 +56,8 @@ function mp_ljdp_map() {
|
|||||||
mp_enqueue_scripts_and_styles();
|
mp_enqueue_scripts_and_styles();
|
||||||
|
|
||||||
$events = mp_get_published_events(); // mp_get_events.php
|
$events = mp_get_published_events(); // mp_get_events.php
|
||||||
// mp_console_log("events :");
|
mp_console_log("events :");
|
||||||
// mp_console_log($events);
|
mp_console_log($events);
|
||||||
// foreach ($events as $event) {
|
// foreach ($events as $event) {
|
||||||
// mp_console_log("--------------- event :");
|
// mp_console_log("--------------- event :");
|
||||||
// mp_console_log("id: " . $event->id);
|
// mp_console_log("id: " . $event->id);
|
||||||
@@ -95,10 +97,11 @@ add_shortcode('lejourduprof_map', 'mp_ljdp_map');
|
|||||||
* re-publish posts
|
* re-publish posts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function mp_add_update_button() {
|
// function mp_add_update_button() {
|
||||||
return mp_create_republish_button();
|
// return mp_create_republish_button();
|
||||||
}
|
// }
|
||||||
add_shortcode('ljdp_update_publish', 'mp_add_update_button');
|
// add_shortcode('ljdp_update_publish', 'mp_add_update_button');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -121,14 +124,35 @@ add_shortcode('ljdp_errors_map', 'mp_errors_map');
|
|||||||
* find its coordinates
|
* find its coordinates
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// function post_published_coordinates($id, $post) {
|
function post_published_coordinates($id, $post) {
|
||||||
//
|
|
||||||
// $location = mp_get_coordinates($id);
|
$location = mp_get_coordinates($id);
|
||||||
//
|
mp_console_log("location: ");
|
||||||
// if ( ! add_post_meta( $id, 'location', $location, true ) )
|
mp_console_log($location);
|
||||||
// update_post_meta( $id, 'location', $location );
|
|
||||||
//
|
// if ( ! add_post_meta( $id, 'location', $location, true ) )
|
||||||
// }
|
// update_post_meta( $id, 'location', $location );
|
||||||
// add_action( 'publish_post', 'post_published_coordinates', 10, 2 );
|
|
||||||
|
}
|
||||||
|
add_action( 'publish_post', 'post_published_coordinates', 10, 2 );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* menu plugin
|
||||||
|
*/
|
||||||
|
|
||||||
|
function ljdp_map_menu() {
|
||||||
|
add_menu_page(
|
||||||
|
'ljdp map', // page_title
|
||||||
|
'ljdp map', // menu_title
|
||||||
|
'manage_options', // capability
|
||||||
|
'ljdp-map-plugin', // menu_slug
|
||||||
|
'ljdp_map_plugin_content' // callback function to display page content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action('admin_menu', 'ljdp_map_menu');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -143,32 +143,32 @@ function mp_fill_fields_value($id) {
|
|||||||
function mp_get_published_events() {
|
function mp_get_published_events() {
|
||||||
$posts_list = mp_get_published_posts();
|
$posts_list = mp_get_published_posts();
|
||||||
|
|
||||||
mp_console_log("posts :");
|
// mp_console_log("posts :");
|
||||||
mp_console_log($posts_list);
|
// mp_console_log($posts_list);
|
||||||
foreach ($posts_list as $post) {
|
// foreach ($posts_list as $post) {
|
||||||
mp_console_log("--------------- post :");
|
// mp_console_log("--------------- post :");
|
||||||
$id = $post->ID;
|
// $id = $post->ID;
|
||||||
mp_console_log("id: " . $id);
|
// mp_console_log("id: " . $id);
|
||||||
// mp_console_log("adresse: " . $event->adresse);
|
// mp_console_log("adresse: " . $event->adresse);
|
||||||
// mp_console_log("pays: " . $event->pays);
|
// mp_console_log("pays: " . $event->pays);
|
||||||
// mp_console_log("ville: " . $event->ville);
|
// mp_console_log("ville: " . $event->ville);
|
||||||
// mp_console_log("irl: " . $event->irl);
|
// mp_console_log("irl: " . $event->irl);
|
||||||
// mp_console_log($event);
|
// mp_console_log($event);
|
||||||
//
|
//
|
||||||
$fields = get_fields($id);
|
// $fields = get_fields($id);
|
||||||
mp_console_log("fields:");
|
// mp_console_log("fields:");
|
||||||
mp_console_log($fields);
|
// mp_console_log($fields);
|
||||||
$field_heure = get_field("heure_de_debut", $id);
|
// $field_heure = get_field("heure_de_debut", $id);
|
||||||
mp_console_log("field_heure: " . $field_heure);
|
// mp_console_log("field_heure: " . $field_heure);
|
||||||
$post_metas = get_post_meta($id);
|
// $post_metas = get_post_meta($id);
|
||||||
mp_console_log("post_metas:");
|
// mp_console_log("post_metas:");
|
||||||
mp_console_log($post_metas);
|
// mp_console_log($post_metas);
|
||||||
$post_custom = get_post_custom($id);
|
// $post_custom = get_post_custom($id);
|
||||||
mp_console_log("post_custom:");
|
// mp_console_log("post_custom:");
|
||||||
mp_console_log($post_custom);
|
// mp_console_log($post_custom);
|
||||||
// foreach( $fields as $name => $value )
|
// foreach( $fields as $name => $value )
|
||||||
// mp_console_log($name . " : " . $value);
|
// mp_console_log($name . " : " . $value);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$events = [];
|
$events = [];
|
||||||
foreach ($posts_list as $post) {
|
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
|
<?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) {
|
function mp_get_coordinates($id) {
|
||||||
global $mp_api_key;
|
global $mp_api_key;
|
||||||
$event = (object)[];
|
$event = (object)[];
|
||||||
@@ -11,17 +23,8 @@ function mp_get_coordinates($id) {
|
|||||||
$location->address = "";
|
$location->address = "";
|
||||||
$location->approximate = false;
|
$location->approximate = false;
|
||||||
|
|
||||||
// get address
|
$address = mp_get_address($id);
|
||||||
$address = "";
|
mp_console_log("adresse: " . $address);
|
||||||
$fields = array(
|
|
||||||
"adresse",
|
|
||||||
"ville",
|
|
||||||
"pays",
|
|
||||||
);
|
|
||||||
foreach($fields as $field) {
|
|
||||||
$address_section = get_field($field, $id);
|
|
||||||
$address .= $address_section . ",";
|
|
||||||
}
|
|
||||||
|
|
||||||
// get coordinates from google maps api
|
// get coordinates from google maps api
|
||||||
$geolocation = 'https://maps.googleapis.com/maps/api/geocode/json'
|
$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")
|
if ($content->results[0]->geometry->location_type == "APPROXIMATE")
|
||||||
$location->approximate = true;
|
$location->approximate = true;
|
||||||
|
|
||||||
|
// clean strings
|
||||||
foreach ($location as $value) {
|
foreach ($location as $value) {
|
||||||
if (gettype($value) != "string")
|
if (gettype($value) != "string")
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user