Files
2022_WEBSITE_jipf/srcs/plugins/google_map/index.php
2022-10-26 14:05:02 +02:00

93 lines
2.8 KiB
PHP
Executable File

<?php
/* Plugin Name: Google Map
Plugin URI: https://www.inkthemes.com/
Description: Integrate Google Maps on any page or post in a simple way.
Version: 1.0
Author: Jaya Rai
Author URI: https://www.inkthemes.com/
*/
?>
<?php
// https://www.inkthemes.com/implement-google-map-plugin-for-wodpress/
// Error: Publishing failed. The response is not a valid JSON response.
// -> https://wordpress.org/support/topic/publishing-failed-error-message-the-response-is-not-a-valid-json-response-2/
// - solution permalink -> broken
// - permalink broken : https://wordpress.org/support/topic/permalinks-change-breaks-all-links/
// - solution classic editor -> ok
// https://stackify.com/how-to-log-to-console-in-php/
function console_log($output, $with_script_tags = true) {
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
add_action('admin_menu', 'ink_menu_page');
function ink_menu_page() {
add_menu_page('GM', 'Google Map', 'manage_options', 'gm_setting', 'ink_gm_setting', '', 120);
}
function ink_gm_setting(){
?>
<h2> Google Map </h2>
<form action="" method="post">
<div class="ink_set">
<label>Latitude : </label>
<input type="text" name="latitude" class="gm_lat">
</div>
<div class="ink_set">
<label>Longitude : </label>
<input type="text" name="longitude" class="gm_log">
</div>
<div class="ink_set">
<label>Zoom : </label>
<input type="text" name="zoom" class="gm_zoom">
</div>
<input type="submit" name="submit" class="submit_button">
</form>
<?php
}
if(isset($_POST['submit'])){
$latitude = $_POST['latitude'];
$logitude = $_POST['longitude'];
$zoom = $_POST['zoom'];
$map_type = $_POST['map_type'];
update_option('googleMap_latitude_position', $latitude );
update_option('googleMap_longitude_position', $logitude );
update_option('map_zoom_value', $zoom);
}
add_action( 'init', 'my_init_script' );
function my_init_script() {
$script_path = plugins_url('script.js', __FILE__);
wp_enqueue_script('my_script', $script_path, array('jquery'));
$style_path = plugins_url('style.css', __FILE__);
wp_enqueue_style('my_style', $style_path);
}
function show_google_map() {
global $wpdb;
$GoogleMap_Latitude = get_option('googleMap_latitude_position');
$GoogleMap_Longitude = get_option('googleMap_longitude_position');
$GoogleMap_zoom = get_option('map_zoom_value');
?>
<script
src="http://maps.googleapis.com/maps/api/js?&sensor=false?&key=AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE">
</script>
<div class="latitude"><?php echo $GoogleMap_Latitude; ?></div>
<div class="longitude" ><?php echo $GoogleMap_Longitude; ?></div>
<div class="zoom"><?php echo $GoogleMap_zoom; ?></div>
<div id="showmap"> </div>
<?php
}
add_shortcode('googlemap', 'show_google_map');
?>