wpgmp_marker_source - WP Maps Pro

15000+ live websites are using this google maps wordpress plugin.

wpgmp_marker_source

In WP Maps Pro, the wpgmp_marker_source hook allows developers to dynamically add or modify markers on maps. This hook is triggered when markers are being rendered, enabling custom marker data to be injected or existing data to be altered.

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 custom marker with additional information such as a fax number and email address.

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(
            "category" => "Custom Category",
            "id" => "15987",
            "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;
}

Example 2

Modify existing markers to change their icon based on a condition.

add_filter('wpgmp_marker_source', 'modify_marker_icon', 10, 2);
function modify_marker_icon($custom_markers, $map_id) {
    foreach($custom_markers as &$marker) {
        if($marker['category'] == 'Special Category') {
            $marker['icon'] = 'https://example.com/new-icon.png';
        }
    }
    return $custom_markers;
}

Example 3

Remove markers from a specific category to filter the map display.

add_filter('wpgmp_marker_source', 'remove_specific_category_markers', 10, 2);
function remove_specific_category_markers($custom_markers, $map_id) {
    foreach($custom_markers as $key => $marker) {
        if($marker['category'] == 'Remove Category') {
            unset($custom_markers[$key]);
        }
    }
    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.

Install Plugin Now!

Buy this plugin exclusively on CodeCanyon! You’ll get free updates, full support, and if you’re not satisfied, we’ve got you covered with a 30-day money-back guarantee.