From 630b2da38bb03fe977d4d82641d9061a3a784d60 Mon Sep 17 00:00:00 2001 From: "Jorge vitrubio.net" Date: Thu, 28 Mar 2024 22:09:20 +0100 Subject: [PATCH] added leaflet map functions to be used in theme --- includes/xarxaprod-leafletmap.php | 68 +++++++++++++++++++++++++++++++ xarxaprod-wp-plugin.php | 3 ++ 2 files changed, 71 insertions(+) create mode 100644 includes/xarxaprod-leafletmap.php diff --git a/includes/xarxaprod-leafletmap.php b/includes/xarxaprod-leafletmap.php new file mode 100644 index 0000000..2abd6e2 --- /dev/null +++ b/includes/xarxaprod-leafletmap.php @@ -0,0 +1,68 @@ + + * + */ + +// Detect plugin. For use on Front End only. +include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); +// check for plugin using plugin name +if ( ! is_plugin_active( 'leaflet-map/leaflet-map.php' ) ) { + echo '

The plugin LeafletMap is needed to show this map

'; +} else { + if (! function_exists( 'xarxaprod_show_leaflet_map' )) { + function xarxaprod_show_leaflet_map() { + // show the map + echo do_shortcode( '[leaflet-map fitbounds lat="41.3922" lng="2.1755" height="100%" width="100%" tileurl=https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png scrollwheel detect-retina]'); + } + }; + + if ( ! is_plugin_active( 'acf-openstreetmap-field/index.php' ) ) { + echo '

The plugin ACF OpenStreetMap Field is needed to show the points in the map

'; + } else { + if (! function_exists( 'xarxaprod_show_leaflet_associat_blob' )) { + function xarxaprod_show_leaflet_associat_blob() { + // get the field values + // https://www.advancedcustomfields.com/resources/get_field/ + // var_dump get_field(''); + $args = get_field('xxp_associat_osm_map',false, false); + + if ( count( $args['markers'] ) ) { + foreach ( $args['markers'] as $marker ) { + // define the fields for the blob + if ( get_field('xxp_associat_citymap') ){ + // if city for map written use it + $associat_address = get_field('xxp_associat_citymap'); + } else { + // else use the ACF OpenStreetMap nominatim value + $associat_address = $marker['label']; + }; + $associat_xxp_weblink = '' . get_the_title() . ''; + $associat_own_weblink = '' . get_field('xxp_associat_web') . ''; + $associat_email = '' . get_field('xxp_associat_mail') . ''; + $associat_lat = $marker['lat']; + $associat_lng = $marker['lng']; + $associat_blobcolor = get_field('xxp_associat_colormap'); + echo do_shortcode( ' + [leaflet-marker svg background="#555" color="#555" iconSize="17,19" iconClass="dashicons dashicons-marker" opacity="0.6" lat=' . $associat_lat . ' lng=' . $associat_lng . ']' + . '

' . $associat_address . '

' + . '
' . $associat_xxp_weblink . '
' + . '

' . $associat_own_weblink . '

' + . '

' . $associat_email . '

' + . '[/leaflet-marker]' + ); // end shortcode each marker + }; // end each marker + }; // end count all markers + }; + }; //end function xarxaprod_show_leaflet_associat_blob + };//end ACF OpenStreetMap active +}; diff --git a/xarxaprod-wp-plugin.php b/xarxaprod-wp-plugin.php index 84c50b2..a14a88d 100644 --- a/xarxaprod-wp-plugin.php +++ b/xarxaprod-wp-plugin.php @@ -84,3 +84,6 @@ include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-associats-filter-funct // plugin js scripts include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php'); + +// include leaflet map shortcodes +include( XARXAPROD_WPPLUGIN_PATH . 'includes/xarxaprod-leafletmap.php');