wpsl_map_controls

  1. Description
  2. Usage
  3. Changelog
  4. Source File
  5. Related

Description

This filter changes the HTML of the buttons in the corner of the store locator map: the “Reset the map” button and the “Use my current location” button. The buttons are made for the map of the [wpsl] shortcode.

Which buttons are in the HTML depends on the settings:

  • The reset button is added when “Show a reset map button?” is enabled on Store Locator > Settings > User Experience. It stays hidden until the first search, which includes the search that loads the locations on page load.
  • The location button is added when “Attempt to auto-locate the user” is enabled on Store Locator > Settings > Search, and the site uses HTTPS. Browsers only allow geolocation on secure pages.

When neither button is added, the filter receives an empty string.

The icon codes changed in 3.0. The reset icon is now  and the location icon is . In 2.x they were  and , which are now the house and marker icons. Code written for 2.x shows the wrong icons.

Usage

Each button is a <button> with the class wpsl-icon-reset or wpsl-icon-direction, an aria-label, and a <span> that holds the icon. The buttons are wrapped in <div id="wpsl-map-controls">. Keep these classes and the id when you change the HTML, because the plugin uses them to show, hide and bind the buttons.

This example shows the house icon on the reset button, and adds the class my-reset-button so you can style it with CSS.

add_filter( 'wpsl_map_controls', 'custom_map_controls' );
function custom_map_controls( $map_controls ) {
// Show the house icon on the reset button instead of the circular arrows.
$map_controls = str_replace( '&#xe807;', '&#xe801;', $map_controls );
// Add a class to the reset button, so you can style it with CSS.
$map_controls = str_replace( 'class="wpsl-icon-reset"', 'class="wpsl-icon-reset my-reset-button"', $map_controls );
return $map_controls;
}

This example removes the “Use my current location” button. Auto-locate on page load keeps working.

add_filter( 'wpsl_map_controls', 'custom_map_controls_no_location_button' );
function custom_map_controls_no_location_button( $map_controls ) {
// Remove the "Use my current location" button. Auto-locate on page load keeps working.
$map_controls = preg_replace( '#<button class="wpsl-icon-direction".*?</button>#s', '', $map_controls );
// Don't output an empty container when no buttons are left.
if ( false === strpos( $map_controls, '<button' ) ) {
$map_controls = '';
}
return $map_controls;
}

The icons come from the plugin’s icon font. These are the other icons you can use:

Code Icon
&#xe800; Marker
&#xe801; House
&#xe802; Building
&#xe803; Clock
&#xe807; Circular arrows (the default reset icon)
&#xe808; Direction arrow (the default location icon)
&#xe80b; Search

Changelog

VersionDescription
3.0Moved to includes/frontend/maps/class-manager.php. The buttons are now <button> elements with an aria-label. New icon codes: reset &#xe807;, location &#xe808;. The location button is only added when "Attempt to auto-locate the user" is enabled and the site uses HTTPS.
2.0Introduced.

Source File

This filter is located in /includes/frontend/maps/class-manager.php.

Placement

The code needs to be placed in the functions.php file inside your active theme folder.