The wpgmp_marker_source hook in WP Maps Pro allows developers to add custom markers dynamically to maps.
This hook is triggered when markers are being rendered, enabling custom marker data to be injected into the map.
Usage
Developers can implement this hook within their theme’s functions.php file or within a custom plugin. The hook provides two parameters: $custom_markers and $map_id. By utilizing these parameters, developers can customize markers based on specific conditions or criteria relevant to each map instance.
Example 1
Adding a simple custom marker to the map.
add_filter('wpgmp_marker_source', 'add_custom_marker', 10, 2); function add_custom_marker($custom_markers, $map_id) { if($map_id == 1) { // Check for a specific map ID $custom_markers[] = array( "id" => "15987", "title" => "Custom Marker Title", "address" => "Custom Marker Address", "message" => "Info Window Custom Message", "latitude" => "30.210994", "longitude" => "74.94547450000005", "icon" => "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png" ); } return $custom_markers; }
Example 2
Adding a custom marker to the map with marker category.
add_filter('wpgmp_marker_source', 'add_custom_marker_with_category', 10, 2); function add_custom_marker_with_category($custom_markers, $map_id) { $custom_markers[] = array( "category" => "Custom category", "id" => "15990", "title" => "Custom Marker Title", "address" => "Custom Marker Address", "message" => "Info Window Custom Message", "latitude" => "30.210994", "longitude" => "74.94547450000005", "icon" => "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png" ); return $custom_markers; }
Example 3
Adding a custom marker with additional information such as a fax number and email address.
add_filter('wpgmp_marker_source', 'add_custom_marker_with_extra_fields', 10, 2); function add_custom_marker_with_extra_fields($custom_markers, $map_id) { $custom_markers[] = array( "id" => "15995", "title" => "Custom Marker Title", "address" => "Custom Marker Address", "message" => "Info Window Custom Message", "latitude" => "30.210994", "longitude" => "74.94547450000005", "extra_fields" => array("fax" => "123456", "email" => "hello@flippercode.com"), "icon" => "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png" ); return $custom_markers; }
Tip: Always validate and sanitize any external data before using it within hooks to ensure security and prevent vulnerabilities such as XSS or SQL injection.