map Archives - WP Maps Pro

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

Hook Category: map

This hook allows developers to customize the spiderfier settings in the WP Maps Pro plugin, which is used for clustering overlapping markers on a map. It is triggered when the map marker spiderfier settings are being retrieved, allowing modifications to the default settings.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It is useful for altering how markers are displayed when they overlap, such as changing the behavior of spiraling or the minimum number of markers required to trigger spiderfying. Here are some practical tips: ensure your changes don’t conflict with other map settings, and test across different browsers to ensure compatibility.

Example 1

Modify spiderfier settings to disable the spiral feature and require only 5 markers to spiderfy.

add_filter('wpgmp_map_marker_spiderfier_settings', function($settings, $map) {
    $settings['marker_enable_spiral'] = 'false';
    $settings['minimum_markers'] = '5';
    return $settings;
}, 10, 2);

Example 2

Enable spiderfying only if the map being displayed has a specific ID, e.g., map ID 123.

add_filter('wpgmp_map_marker_spiderfier_settings', function($settings, $map) {
    if ($map->map_id == 123) {
        $settings['marker_spiderfy'] = 'true';
    }
    return $settings;
}, 10, 2);

Example 3

Change the spiderfy settings based on a custom field value associated with the map.

add_filter('wpgmp_map_marker_spiderfier_settings', function($settings, $map) {
    $custom_value = get_post_meta($map->map_id, 'custom_spiderfy_setting', true);
    if ($custom_value) {
        $settings['minimum_markers'] = $custom_value;
    }
    return $settings;
}, 10, 2);

Remember to always back up your site before implementing new hooks or modifying existing ones. Test changes in a staging environment to ensure they work as expected without affecting live site functionality.

The wpgmp_route_tab hook in the WP Maps Pro plugin allows developers to customize the functionality of the route tab settings at runtime. It is triggered when the route tab settings need to be modified, providing flexibility to change how routes are displayed or managed in the plugin.

Usage

Developers can implement this hook within their WordPress themes or plugins to modify route tab settings. It is particularly useful for those who want to customize the appearance or behavior of routes in their WP Maps Pro setup. A practical tip is to ensure that any modifications do not conflict with other functionalities of the plugin.

Example 1

Description: Customize the title of the route tab to display a custom name.

add_filter('wpgmp_route_tab', 'custom_route_tab_title', 10, 2);
function custom_route_tab_title($route_tab, $map) {
    $route_tab['route_tab_title'] = 'Custom Routes';
    return $route_tab;
}

Example 2

Description: Disable the display of the route tab by setting the display parameter to 0.

add_filter('wpgmp_route_tab', 'disable_route_tab_display', 10, 2);
function disable_route_tab_display($route_tab, $map) {
    $route_tab['display_route_tab'] = 0;
    return $route_tab;
}

Example 3

Description: Change the travel mode of a specific route to “BICYCLING”.

add_filter('wpgmp_route_tab', 'change_route_travel_mode', 10, 2);
function change_route_travel_mode($route_tab, $map) {
    foreach ($route_tab['route_tab_data'] as &$route) {
        if ($route['route_id'] == 14) {
            $route['route_travel_mode'] = 'BICYCLING';
        }
    }
    return $route_tab;
}

Tip: When using this hook, always backup your site and test changes in a staging environment to prevent any potential conflicts or unexpected behavior.

This hook in the WP Maps Pro plugin allows developers to customize the settings of the “Nearby Places” tab. It is triggered when the nearby tab’s settings are being configured, enabling developers to modify various attributes like the title, amenities, and visual properties of the nearby circle.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It’s a powerful way to tailor the user experience by altering the default settings of the nearby tab according to specific requirements.

Example 1

Change the title of the nearby tab to a custom text.

add_filter('wpgmp_nearby_tab', 'custom_nearby_tab_title', 10, 2);
function custom_nearby_tab_title($nearby_tab, $map) {
    $nearby_tab['nearby_tab_title'] = 'Local Attractions';
    return $nearby_tab;
}

Example 2

Modify the amenities shown in the nearby tab to include only certain types of places.

add_filter('wpgmp_nearby_tab', 'custom_nearby_amenities', 10, 2);
function custom_nearby_amenities($nearby_tab, $map) {
    $nearby_tab['nearby_amenities'] = array(
        'restaurant' => 'restaurant',
        'hotel' => 'hotel'
    );
    return $nearby_tab;
}

Example 3

Adjust the visual settings of the nearby circle to have different stroke color and weight.

add_filter('wpgmp_nearby_tab', 'custom_nearby_circle_style', 10, 2);
function custom_nearby_circle_style($nearby_tab, $map) {
    $nearby_tab['nearby_circle_strokecolor'] = '#FF5733';
    $nearby_tab['nearby_circle_strokeweight'] = 2;
    return $nearby_tab;
}

Always ensure you validate and sanitize inputs when modifying settings to maintain the security and stability of your WordPress site.

This hook in the WP Maps Pro plugin allows developers to modify the marker cluster settings of a map. It is triggered when the map is rendering, providing an opportunity to customize how markers are clustered.

Usage

Developers can implement this hook in their theme’s functions.php file or in a custom plugin. By doing so, they can adjust the cluster settings dynamically, such as changing the grid size, max zoom level, or the icons used for clusters.

Example 1

Modify the grid size used by the marker cluster to make clusters more or less dense.

add_filter('wpgmp_map_markercluster', function($marker_cluster, $map) {
    $marker_cluster['grid'] = 20; // Change grid size to 20
    return $marker_cluster;
}, 10, 2);

Example 2

Change the cluster icons to custom images for a more personalized map appearance.

add_filter('wpgmp_map_markercluster', function($marker_cluster, $map) {
    $marker_cluster['icon'] = 'http://example.com/path/to/custom/icon.png';
    $marker_cluster['hover_icon'] = 'http://example.com/path/to/custom/hover_icon.png';
    return $marker_cluster;
}, 10, 2);

Example 3

Set a custom zoom level when clusters are clicked, providing a closer look at the clustered markers.

add_filter('wpgmp_map_markercluster', function($marker_cluster, $map) {
    $marker_cluster['marker_zoom_level'] = 15; // Set custom zoom level
    return $marker_cluster;
}, 10, 2);

Tip: Always validate and sanitize any data you modify to ensure your site remains secure and performs optimally.

This hook in WP Maps Pro allows developers to customize the directions tab settings at runtime. It is triggered when there is a need to modify the settings related to the directions tab in a map instance.

Usage

Developers can implement this hook to alter the appearance and functionality of the directions tab in WP Maps Pro. It is typically used in the theme’s functions.php file or a custom plugin, allowing for dynamic changes based on specific conditions or preferences.

Example 1

Modify the title of the directions tab.

add_filter('wpgmp_direction_tab', function($direction_tab, $map) {
    $direction_tab['direction_tab_title'] = 'Custom Directions Title';
    return $direction_tab;
}, 10, 2);

Example 2

Disable markers in the directions tab for a specific map.

add_filter('wpgmp_direction_tab', function($direction_tab, $map) {
    if($map->ID == 123) { // assuming 123 is the map ID
        $direction_tab['suppress_markers'] = 0;
    }
    return $direction_tab;
}, 10, 2);

Example 3

Enable the directions tab only for logged-in users.

add_filter('wpgmp_direction_tab', function($direction_tab, $map) {
    if(!is_user_logged_in()) {
        $direction_tab['dir_tab'] = 0;
    }
    return $direction_tab;
}, 10, 2);

Always ensure that any custom code implementing hooks is thoroughly tested in a staging environment before deploying to a live site to prevent any unexpected behavior or site downtime.

The wpgmp_shapes hook in WP Maps Pro allows developers to customize the shapes displayed on Google Maps at runtime. This includes adding or removing shapes such as polygons, polylines, circles, and rectangles.

Usage

Developers can implement the wpgmp_shapes hook to modify the map data before it is rendered. This is useful for dynamically changing the map’s appearance based on user input or other conditions. The hook is typically used in the functions.php file of your theme or a custom plugin.

Example 1

Description of the first use-case: Adding a new polygon to the map.

add_filter('wpgmp_shapes', 'add_custom_polygon', 10, 3);
function add_custom_polygon($map_shapes, $map_data, $map_id) {
    $new_polygon = array(
        'cordinates' => array("35.6895,-139.6917", "35.6895,-140.6917", "36.6895,-140.6917"),
        'settings' => array(
            'stroke_color' => '#FF0000',
            'stroke_opacity' => '0.7',
            'stroke_weight' => '2',
            'fill_color' => '#FF0000',
            'fill_opacity' => '0.7'
        ),
        'events' => array(
            'url' => '',
            'message' => 'New polygon infowindow message'
        )
    );
    $map_shapes['polygons'][] = $new_polygon;
    return $map_shapes;
}

Example 2

Description of the second use-case: Removing all circles from the map.

add_filter('wpgmp_shapes', 'remove_all_circles', 10, 3);
function remove_all_circles($map_shapes, $map_data, $map_id) {
    $map_shapes['circles'] = array(); // Clear all circles
    return $map_shapes;
}

Example 3

Description of the third use-case: Modifying the message of a rectangle infowindow.

add_filter('wpgmp_shapes', 'update_rectangle_message', 10, 3);
function update_rectangle_message($map_shapes, $map_data, $map_id) {
    if (!empty($map_shapes['rectangles'])) {
        foreach ($map_shapes['rectangles'] as &$rectangle) {
            $rectangle['events']['message'] = 'Updated rectangle infowindow message';
        }
    }
    return $map_shapes;
}

Tip: Always validate and sanitize any user input used within the hook to prevent security vulnerabilities, especially when data is dynamically added to the map.

This hook in the WP Maps Pro plugin allows developers to customize the placeholder text for the search input field at runtime.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It allows for dynamic customization of the search box placeholder text, enhancing user experience by providing context-specific instructions.

Example 1

Change the placeholder text to a more descriptive prompt for a restaurant search map.

add_filter( 'wpgmp_searchbox_placeholder', function( $text ) {
    return esc_html__( 'Search for restaurants...', 'wpgmp-google-map' );
});

Example 2

Modify the placeholder text based on user roles, providing administrators with a different message.

add_filter( 'wpgmp_searchbox_placeholder', function( $text ) {
    if ( current_user_can( 'administrator' ) ) {
        return esc_html__( 'Admin: Enter location...', 'wpgmp-google-map' );
    }
    return esc_html__( 'Type here...', 'wpgmp-google-map' );
});

Example 3

Set a placeholder text that changes based on the time of day, offering a personalized experience.

add_filter( 'wpgmp_searchbox_placeholder', function( $text ) {
    $hour = date('H');
    if ( $hour < 12 ) {
        return esc_html__( 'Good morning! Where to?', 'wpgmp-google-map' );
    } elseif ( $hour < 18 ) {
        return esc_html__( 'Good afternoon! Search your destination...', 'wpgmp-google-map' );
    } else {
        return esc_html__( 'Good evening! Find a place...', 'wpgmp-google-map' );
    }
});

Always ensure that any custom text is properly sanitized using esc_html__() for security and to prevent potential XSS vulnerabilities.

This hook in the WP Maps Pro plugin allows developers to customize the functionality related to accepting cookies before displaying the map. It is triggered before the map is shown and ensures that user consent is obtained for cookies.

Usage

Developers can implement this hook within their theme or plugin to alter or enhance the way cookies are managed before a map is displayed. This can be done by adding custom functions to modify behavior or integrate additional functionalities, such as logging or conditional display based on cookie acceptance.

Example 1

This example shows how to log a message when the cookie acceptance hook is triggered.

add_action('wpgmp_accept_cookies', function() {
    error_log('Map cookies have been accepted.');
});

Example 2

In this example, the hook is used to redirect users to a cookie policy page if they haven’t accepted cookies.

add_action('wpgmp_accept_cookies', function() {
    if (!isset($_COOKIE['maps_cookie_accepted'])) {
        wp_redirect(home_url('/cookie-policy'));
        exit;
    }
});

Example 3

This example demonstrates how to display a custom message to users who have accepted cookies.

add_action('wpgmp_accept_cookies', function() {
    if (isset($_COOKIE['maps_cookie_accepted'])) {
        echo '<div class="cookie-message">Thank you for accepting cookies. The map is now visible.</div>';
    }
});

Remember to always check if cookies are set and handle them securely, ensuring compliance with privacy regulations such as GDPR.

This hook in WP Maps Pro allows developers to modify the list of post types that are considered when querying for posts with assigned locations. It is triggered during the process of optimizing queries to improve performance by excluding unnecessary post types.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It helps in customizing the set of post types to be included or excluded based on specific requirements.

Example 1

Exclude a custom post type ‘event’ from being queried for location data.

add_filter('wpgmp_map_supported_post_types', function($all_post_types, $map) {
    if(($key = array_search('event', $all_post_types)) !== false) {
        unset($all_post_types[$key]);
    }
    return $all_post_types;
}, 10, 2);

Example 2

Include a custom post type ‘property’ in the list of post types being queried for location data.

add_filter('wpgmp_map_supported_post_types', function($all_post_types, $map) {
    if(!in_array('property', $all_post_types)) {
        $all_post_types[] = 'property';
    }
    return $all_post_types;
}, 10, 2);

Example 3

Restrict the query to only ‘post’ and ‘page’ post types, ignoring all others.

add_filter('wpgmp_map_supported_post_types', function($all_post_types, $map) {
    return array_intersect($all_post_types, ['post', 'page']);
}, 10, 2);

Tip: Always ensure that you test the hook implementation in a staging environment before deploying to a live site to avoid unexpected issues.

This hook in the WP Maps Pro plugin allows developers to filter which registered post types display the WP Maps Pro meta box on add or edit screens. It’s triggered when the meta boxes are being set up for the post types.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It allows you to customize the post types that should display the WP Maps Pro meta box by modifying the array of post types.

Example 1

This example shows how to display the WP Maps Pro meta box only on ‘page’ post types.

add_filter('wpgmp_meta_box_post_types', function($screens) {
    return ['page'];
});

Example 2

This example demonstrates how to add a custom post type ‘portfolio’ to the list of post types that display the WP Maps Pro meta box.

add_filter('wpgmp_meta_box_post_types', function($screens) {
    $screens[] = 'portfolio';
    return $screens;
});

Example 3

In this example, we remove the WP Maps Pro meta box from the ‘post’ post type, leaving it on other default and custom types.

add_filter('wpgmp_meta_box_post_types', function($screens) {
    return array_filter($screens, function($screen) {
        return $screen !== 'post';
    });
});

Tip: Always ensure the post types you specify are registered and available to prevent issues with the meta box display. Test changes in a staging environment before deployment.

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.