wpgmp_map_routes - WP Maps Pro

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

wpgmp_map_routes

This hook in the WP Maps Pro plugin allows developers to customize map routes by modifying route data before it is rendered. It is triggered when routes are assigned or unassigned to a map.

Usage

Developers can implement this hook in their WordPress theme’s functions.php file or within a custom plugin to adjust route properties such as color, weight, and travel mode. This is particularly useful for dynamically configuring map routes based on specific conditions or settings.

Example 1

This example changes the stroke color of all routes to red.

add_filter('wpgmp_map_routes', 'customize_route_colors', 10, 2);
function customize_route_colors($routes, $map) {
    foreach ($routes as &$route) {
        $route['route_stroke_color'] = '#FF0000'; // Change stroke color to red
    }
    return $routes;
}

Example 2

In this example, the travel mode for all routes is set to ‘BICYCLING’.

add_filter('wpgmp_map_routes', 'set_travel_mode_to_bicycling', 10, 2);
function set_travel_mode_to_bicycling($routes, $map) {
    foreach ($routes as &$route) {
        $route['route_travel_mode'] = 'BICYCLING'; // Change travel mode to bicycling
    }
    return $routes;
}

Example 3

This example adds a condition to only optimize waypoints for routes with the title “UVA to Microsoft HQ”.

add_filter('wpgmp_map_routes', 'optimize_uva_to_microsoft_route', 10, 2);
function optimize_uva_to_microsoft_route($routes, $map) {
    foreach ($routes as &$route) {
        if ($route['route_title'] === 'UVA to Microsoft HQ') {
            $route['route_optimize_waypoints'] = true; // Optimize waypoints for this route
        }
    }
    return $routes;
}

Remember to always validate and sanitize any data manipulated through hooks to ensure security and prevent potential vulnerabilities.

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.