This hook allows developers to customize the display of the bicycle layer on a map within the WP Maps Pro plugin. It is triggered when the map is being rendered and determines whether the bicycle layer should be shown or hidden. The modifiable data is a boolean value within an array, specifically {“display_layer”:true}.
Usage
Developers can implement this hook in their theme’s functions.php file or a custom plugin. It provides a way to conditionally show or hide the bicycle layer based on certain conditions or settings. By attaching a custom function to this hook, developers can manipulate the visibility of the bicycle layer dynamically.
Example 1
This example demonstrates how to hide the bicycle layer for a specific map.
add_filter('wpgmp_bicycling_layer', 'custom_hide_bicycle_layer', 10, 2); function custom_hide_bicycle_layer($map_data, $map) { if ($map->ID == 123) { // Assuming 123 is the map ID $map_data['display_layer'] = false; } return $map_data; }
Example 2
Show the bicycle layer only if the current user is logged in.
add_filter('wpgmp_bicycling_layer', 'show_bicycle_layer_for_logged_in_users', 10, 2); function show_bicycle_layer_for_logged_in_users($map_data, $map) { if (is_user_logged_in()) { $map_data['display_layer'] = true; } else { $map_data['display_layer'] = false; } return $map_data; }
Example 3
Toggle the bicycle layer based on a custom field value associated with the map.
add_filter('wpgmp_bicycling_layer', 'toggle_bicycle_layer_based_on_custom_field', 10, 2); function toggle_bicycle_layer_based_on_custom_field($map_data, $map) { $custom_field_value = get_post_meta($map->ID, 'show_bicycle_layer', true); if ($custom_field_value === 'yes') { $map_data['display_layer'] = true; } else { $map_data['display_layer'] = false; } return $map_data; }
Always validate and sanitize any data used within your hook functions to ensure secure and reliable code.