wip bad address are ignored
This commit is contained in:
@@ -141,37 +141,57 @@ add_shortcode('lejourduprof_map', 'mp_add_div');
|
|||||||
* when a post is saved or published or updated,
|
* when a post is saved or published or updated,
|
||||||
* find its coordinates
|
* find its coordinates
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function post_published_coordinates($id, $post) {
|
function post_published_coordinates($id, $post) {
|
||||||
|
|
||||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( !isset( $_POST['ep_eventposts_nonce'] ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( !wp_verify_nonce( $_POST['ep_eventposts_nonce'], plugin_basename( __FILE__ ) ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Is the user allowed to edit the post or page?
|
|
||||||
if ( !current_user_can( 'edit_post', $post->ID ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
$coordinates = mp_get_coordinates($id);
|
$coordinates = mp_get_coordinates($id);
|
||||||
|
|
||||||
if ( ! add_post_meta( $id, 'coordinates', $coordinates, true ) )
|
if ( ! add_post_meta( $id, 'coordinates', $coordinates, true ) )
|
||||||
update_post_meta( $id, 'coordinates', $coordinates );
|
update_post_meta( $id, 'coordinates', $coordinates );
|
||||||
|
|
||||||
}
|
}
|
||||||
add_action( 'save_post', 'post_published_coordinates', 10, 2 );
|
add_action( 'publish_post', 'post_published_coordinates', 10, 2 );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* trying to prevent publication with message if bad country address
|
||||||
|
*/
|
||||||
|
|
||||||
|
// // notice on post edit :
|
||||||
|
// // https://developer.wordpress.org/block-editor/how-to-guides/notices/
|
||||||
|
// // https://developer.wordpress.org/block-editor/how-to-guides/javascript/loading-javascript/
|
||||||
|
// // https://developer.wordpress.org/block-editor/reference-guides/components/notice/https://developer.wordpress.org/block-editor/reference-guides/components/notice/
|
||||||
|
// // modals : https://developer.wordpress.org/block-editor/reference-guides/components/modal/
|
||||||
|
//
|
||||||
|
// // https://www.wpbeginner.com/wp-tutorials/how-to-add-admin-notices-in-wordpress/
|
||||||
|
// // https://digwp.com/2016/05/wordpress-admin-notices/
|
||||||
|
// function my_notice() {
|
||||||
|
// //echo '<div class="notice notice-warning is-dismissible">
|
||||||
|
// //echo '<div class="notice notice-info is-dismissible">
|
||||||
|
// //echo '<div class="notice notice-success is-dismissible">
|
||||||
|
// //echo '<div class="components-notice is-error is-dismissible">
|
||||||
|
// // echo '
|
||||||
|
// // <div class="notice notice-error is-dismissible">
|
||||||
|
// // <p>my message</p>
|
||||||
|
// // </div>
|
||||||
|
// // ';
|
||||||
|
//
|
||||||
|
// mp_console_log("\n get values:");
|
||||||
|
// foreach ($_GET as $key => $value) {
|
||||||
|
// mp_console_log(" " . $key . ": " . $value);
|
||||||
|
// }
|
||||||
|
// $screen = get_current_screen();
|
||||||
|
// mp_console_log("\n screen values:");
|
||||||
|
// foreach ($screen as $key => $value) {
|
||||||
|
// mp_console_log(" " . $key . ": " . $value);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// add_action( 'admin_notices', 'my_notice');
|
||||||
|
//
|
||||||
// // https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled
|
// // https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled
|
||||||
// // https://developer.wordpress.org/reference/hooks/save_post/
|
// // https://developer.wordpress.org/reference/hooks/save_post/
|
||||||
// function test1($id, $post, $update) {
|
// function my_publish_check($id, $post, $update) {
|
||||||
//
|
//
|
||||||
// // is doing autosaving ?
|
// // is doing autosaving ?
|
||||||
// if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
// if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
||||||
@@ -206,8 +226,8 @@ add_action( 'save_post', 'post_published_coordinates', 10, 2 );
|
|||||||
// add_action('save_post', 'my_save_post');
|
// add_action('save_post', 'my_save_post');
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// add_action( 'save_post_post', 'test1', 10, 3);
|
// add_action( 'save_post_post', 'my_publish_check', 10, 3);
|
||||||
|
//
|
||||||
// function publish_error() {
|
// function publish_error() {
|
||||||
// wp_enqueue_script('mp_publish_error',
|
// wp_enqueue_script('mp_publish_error',
|
||||||
// plugins_url('scripts/mp_publish_error.js', __FILE__),
|
// plugins_url('scripts/mp_publish_error.js', __FILE__),
|
||||||
@@ -217,7 +237,7 @@ add_action( 'save_post', 'post_published_coordinates', 10, 2 );
|
|||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
// add_action( 'enqueue_block_editor_assets', 'publish_error');
|
// add_action( 'enqueue_block_editor_assets', 'publish_error');
|
||||||
|
//
|
||||||
// // https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled
|
// // https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled
|
||||||
// // https://wordpress.stackexchange.com/questions/15546/dont-publish-custom-post-type-post-if-a-meta-data-field-isnt-valid
|
// // https://wordpress.stackexchange.com/questions/15546/dont-publish-custom-post-type-post-if-a-meta-data-field-isnt-valid
|
||||||
// function my_redirect_location($location, $post_id) {
|
// function my_redirect_location($location, $post_id) {
|
||||||
@@ -237,39 +257,34 @@ add_action( 'save_post', 'post_published_coordinates', 10, 2 );
|
|||||||
// return $location;
|
// return $location;
|
||||||
// }
|
// }
|
||||||
// add_filter('redirect_post_location', 'my_redirect_location', 10, 2);
|
// add_filter('redirect_post_location', 'my_redirect_location', 10, 2);
|
||||||
|
//
|
||||||
|
// //function test1($id, $post) {
|
||||||
|
// // mp_console_log("save_post - " . $post->post_status);
|
||||||
|
// //}
|
||||||
|
// //add_action( 'save_post', 'test1', 10, 2 );
|
||||||
|
// /*
|
||||||
|
// modification rapide, publie -> brouillon : 1 - draft
|
||||||
|
// modification rapide, brouillon -> brouillon : 1 - draft
|
||||||
|
// modification rapide, brouillon -> publie : 1 - publish
|
||||||
|
// add post : 1 - auto-draft
|
||||||
|
// modification, publie -> brouillon : 2 - draft
|
||||||
|
// modification, brouillon -> brouillon : 2 - draft
|
||||||
|
// modification, brouillon -> publie : 2 - publish
|
||||||
|
// */
|
||||||
|
//
|
||||||
|
// //function test2($id, $post) {
|
||||||
|
// // mp_console_log("publish_post - " . $post->post_status);
|
||||||
|
// //}
|
||||||
|
// //add_action( 'publish_post', 'test2', 10, 2 );
|
||||||
|
// /*
|
||||||
|
// modification rapide, publie -> brouillon : /
|
||||||
|
// modification rapide, brouillon -> brouillon : /
|
||||||
|
// modification rapide, brouillon -> publie : 1 - publish
|
||||||
|
// add post : /
|
||||||
|
// modification, publie -> brouillon : /
|
||||||
|
// modification, brouillon -> brouillon : /
|
||||||
|
// modification, brouillon -> publie : 2 - publish
|
||||||
|
// */
|
||||||
|
|
||||||
/*
|
|
||||||
modification rapide, publie -> brouillon : 1 - draft
|
|
||||||
modification rapide, brouillon -> brouillon : 1 - draft
|
|
||||||
modification rapide, brouillon -> publie : 1 - publish
|
|
||||||
add post : 1 - auto-draft
|
|
||||||
modification, publie -> brouillon : 2 - draft
|
|
||||||
modification, brouillon -> brouillon : 2 - draft
|
|
||||||
modification, brouillon -> publie : 2 - publish
|
|
||||||
*/
|
|
||||||
|
|
||||||
//function test2($id, $post) {
|
|
||||||
// mp_console_log("publish_post - " . $post->post_status);
|
|
||||||
//}
|
|
||||||
//add_action( 'publish_post', 'test2', 10, 2 );
|
|
||||||
/*
|
|
||||||
modification rapide, publie -> brouillon : /
|
|
||||||
modification rapide, brouillon -> brouillon : /
|
|
||||||
modification rapide, brouillon -> publie : 1 - publish
|
|
||||||
add post : /
|
|
||||||
modification, publie -> brouillon : /
|
|
||||||
modification, brouillon -> brouillon : /
|
|
||||||
modification, brouillon -> publie : 2 - publish
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//function save_post_coordinates($id, $post) {
|
|
||||||
// mp_console_log("coordinates is null");
|
|
||||||
//}
|
|
||||||
//add_action( 'publish_post', 'post_published_coordinates', 10, 2 );
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
// https://stackify.com/how-to-log-to-console-in-php/
|
// https://stackify.com/how-to-log-to-console-in-php/
|
||||||
|
|
||||||
function mp_console_log($output) {
|
function mp_log($output) {
|
||||||
|
$type = gettype($output);
|
||||||
|
if ($type == 'object')
|
||||||
|
$output = serialize($output);
|
||||||
$time = date('H:i');
|
$time = date('H:i');
|
||||||
$file = '/var/www/html/wp-debug.log';
|
$file = '/var/www/html/wp-debug.log';
|
||||||
file_put_contents($file, $time . " " . $output . "\n", FILE_APPEND);
|
file_put_contents($file, $time . " " . $output . "\n", FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// function mp_console_log($output) {
|
function mp_console_log($output) {
|
||||||
// $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ');';
|
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ');';
|
||||||
// $js_code = '<script>' . $js_code . '</script>';
|
$js_code = '<script>' . $js_code . '</script>';
|
||||||
// echo $js_code;
|
echo $js_code;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// function mp_console_log($output, $with_script_tags = true) {
|
// function mp_console_log($output, $with_script_tags = true) {
|
||||||
// $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
|
// $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ function mp_get_coordinates($id) {
|
|||||||
);
|
);
|
||||||
foreach($fields as $field) {
|
foreach($fields as $field) {
|
||||||
$address_section = get_field($field, $id);
|
$address_section = get_field($field, $id);
|
||||||
|
// if ($field == "pays")
|
||||||
|
// if ($address_section == null)
|
||||||
|
// //return null;
|
||||||
$address .= $address_section . ",";
|
$address .= $address_section . ",";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,13 +107,11 @@ function mp_get_published_posts() {
|
|||||||
// );
|
// );
|
||||||
// $post_list = get_posts($post_args);
|
// $post_list = get_posts($post_args);
|
||||||
// foreach ($post_list as $post) {
|
// foreach ($post_list as $post) {
|
||||||
// //if ( get_field("nom", $post->ID) == "Rakhimov") {
|
// wp_update_post(array(
|
||||||
// wp_update_post(array(
|
// 'ID' => $post->ID,
|
||||||
// 'ID' => $post->ID,
|
// //'post_status' => 'draft',
|
||||||
// //'post_status' => 'draft',
|
// 'post_status' => 'publish',
|
||||||
// 'post_status' => 'publish',
|
// ));
|
||||||
// ));
|
|
||||||
// //};
|
|
||||||
// };
|
// };
|
||||||
|
|
||||||
$get_posts_args = array(
|
$get_posts_args = array(
|
||||||
@@ -173,12 +171,6 @@ function mp_get_published_events(&$pays) {
|
|||||||
$event = mp_fill_fields_value($post->ID, $pays);
|
$event = mp_fill_fields_value($post->ID, $pays);
|
||||||
$event->id = $post->ID;
|
$event->id = $post->ID;
|
||||||
$event->title = $post->post_title;
|
$event->title = $post->post_title;
|
||||||
// TEMP
|
|
||||||
if (strlen($event->pays) == 0) {
|
|
||||||
mp_console_log("pays nulle:");
|
|
||||||
mp_console_log($event);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
array_push($events, $event);
|
array_push($events, $event);
|
||||||
}
|
}
|
||||||
mp_console_log("nombre de posts: " . count($events));
|
mp_console_log("nombre de posts: " . count($events));
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ function create_markers(map, locations, infowindow) {
|
|||||||
let markers = [];
|
let markers = [];
|
||||||
for (loc of locations) {
|
for (loc of locations) {
|
||||||
|
|
||||||
|
if (loc.coordinates == null) {
|
||||||
|
console.log("coordinates == null");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let count = loc.events.length;
|
let count = loc.events.length;
|
||||||
|
|
||||||
let marker_icon_size = [
|
let marker_icon_size = [
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ function mp_init_map() {
|
|||||||
* following variable are created by mp_add_to_script.php
|
* following variable are created by mp_add_to_script.php
|
||||||
* - let locations = [
|
* - let locations = [
|
||||||
* {
|
* {
|
||||||
* coord: {}
|
* coordinates: {}
|
||||||
* events: [{}, ...]
|
* events : [{}, ...]
|
||||||
* },
|
* },
|
||||||
* ...
|
* ...
|
||||||
* ]
|
* ]
|
||||||
|
|||||||
Reference in New Issue
Block a user