wpgmp_transit_layer - WP Maps Pro

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

wpgmp_transit_layer

This hook in the WP Maps Pro plugin allows developers to customize the display of the transit layer on a map at runtime. It is triggered when the map is being rendered, giving the opportunity to show or hide the transit layer based on specific conditions.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It is useful for dynamically controlling the visibility of the transit layer, depending on various factors such as user roles or custom settings.

Example 1

This example hides the transit layer for non-admin users.

add_filter('wpgmp_transit_layer', function($display_layer, $map) {
    if (!current_user_can('administrator')) {
        $display_layer = false;
    }
    return $display_layer;
}, 10, 2);

Example 2

In this example, the transit layer is shown only during weekdays.

add_filter('wpgmp_transit_layer', function($display_layer, $map) {
    $current_day = date('N'); // 1 (for Monday) through 7 (for Sunday)
    if ($current_day >= 1 && $current_day <= 5) {
        $display_layer = true;
    } else {
        $display_layer = false;
    }
    return $display_layer;
}, 10, 2);

Example 3

This example modifies the transit layer visibility based on a map-specific custom setting.

add_filter('wpgmp_transit_layer', function($display_layer, $map) {
    $custom_setting = get_post_meta($map->ID, 'transit_layer_setting', true);
    if ($custom_setting === 'show') {
        $display_layer = true;
    } else {
        $display_layer = false;
    }
    return $display_layer;
}, 10, 2);

Remember to always validate and sanitize any data used within hooks to ensure security and stability of your WordPress site.

Install Plugin Now!

WP MAPS PRO helps you create dynamic, customizable maps using Google Maps or Leaflet — no coding required. Includes free updates, premium support, and a 30-day money-back guarantee.