coordinates; // mp_console_log("coordinates:"); // mp_console_log($coordinates); // } function is_event_post() { if ( is_admin() ) return false; if ( get_post_type() != "post" ) return 0; if ( get_post_status() != "publish" ) return 0; return true; } /** * when 'shortcode' found in page, enqueue scripts and styles, * run php script, and replace shortcode by return value */ function mp_ljdp_map() { /* * * * * * * * * * * * * * * * ENQUEUE SCRIPTS AND STYLES */ // https://developers.google.com/maps/documentation/javascript/marker-clustering $marker_clusterer = "https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"; wp_enqueue_style('mp__style', plugins_url('styles/mp__style.css', __FILE__), '', '', false); // enqueue header wp_enqueue_script('mp_info_window', plugins_url('scripts/mp_info_window.js', __FILE__), '', '', false); wp_enqueue_script('mp_errors_map', plugins_url('scripts/mp_errors_map.js', __FILE__), '', '', false); wp_enqueue_script('mp_create_filters', plugins_url('scripts/mp_create_filters.js', __FILE__), '', '', false); wp_enqueue_script('mp_create_markers', plugins_url('scripts/mp_create_markers.js', __FILE__), '', '', false); wp_enqueue_script('mp_create_map', plugins_url('scripts/mp_create_map.js', __FILE__), '', '', false); wp_enqueue_script('mp_draw_clusters', plugins_url('scripts/mp_draw_clusters.js', __FILE__), '', '', false); wp_enqueue_script('mp_filter_events', plugins_url('scripts/mp_filter_events.js', __FILE__), '', '', false); // enqueue footer wp_enqueue_script('mp_marker_clusterer', $marker_clusterer, '', '', true); wp_enqueue_script('mp_init_map', plugins_url('scripts/mp_init_map.js', __FILE__), ['mp_marker_clusterer'],'', true); wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true); /* * * * * * * * * * FIND LOCATIONS */ $events = mp_get_published_events(); //mp_console_log("php events:"); //mp_console_log($events); $locations = mp_sort_events($events); //mp_console_log("php locations:"); //mp_console_log($locations); $filters = mp_get_filters($events); //mp_console_log("php filters:"); //mp_console_log($filters); $to_add = array( "locations" => $locations, "filters" => $filters, ); // if post event instead of map page, change ccoordinate and zoom global $mp_zoom; if (is_event_post()) { $mp_zoom = $mp_zoom_set[1]; $location = get_field(location); $coordinates = $location->coordinates; $mp_coordinates_default = $coordinates; } mp_add_to_scripts($to_add); /* * * * * * * * * ADD FILTERS */ $mp_map_div = mp_create_div($filters); return $mp_map_div; } add_shortcode('lejourduprof_map', 'mp_ljdp_map'); /** * errors map */ function mp_errors_map() { return mp_find_address_errors(); } add_shortcode('ljdp_errors_map', 'mp_errors_map'); /** * when a post is saved or published or updated, * find its coordinates */ function post_published_coordinates($id, $post) { $location = mp_get_coordinates($id); if ( ! add_post_meta( $id, 'location', $location, true ) ) update_post_meta( $id, 'location', $location ); } 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 '
my message
// //