The wpgmp_show_place hook in WP Maps Pro allows developers to control the visibility of a specific location on a map. It is triggered when determining whether a location should be displayed or hidden, with a default value of true indicating the location will be shown.
Usage
Developers can implement this hook in their WordPress theme or plugin to conditionally show or hide a location on a map. By returning false, a location can be hidden based on custom logic, such as user roles or specific conditions.
Example 1
This example shows how to hide a location based on a specific user role.
add_filter('wpgmp_show_place', 'hide_location_for_non_admins', 10, 3);
function hide_location_for_non_admins($use_me, $place, $map) {
if (!current_user_can('administrator')) {
return false;
}
return $use_me;
}
Example 2
In this example, a location is hidden if it is marked as private in the custom field.
add_filter('wpgmp_show_place', 'hide_private_locations', 10, 3);
function hide_private_locations($use_me, $place, $map) {
if (get_post_meta($place['id'], 'is_private', true) == 'yes') {
return false;
}
return $use_me;
}
Example 3
This example demonstrates how to show a location only on specific maps.
add_filter('wpgmp_show_place', 'show_location_on_specific_map', 10, 3);
function show_location_on_specific_map($use_me, $place, $map) {
$allowed_maps = array(1, 2, 3); // IDs of maps where the location should be visible
if (!in_array($map->map_id, $allowed_maps)) {
return false;
}
return $use_me;
}
Always ensure to perform necessary checks and validations when modifying the visibility of locations using this hook, especially when dealing with sensitive or private data.