Skip to content

WordPress Filters

Jörn Lund edited this page Dec 23, 2024 · 3 revisions

acf_osm_geocoder_options

Filter init options for leaflet geocoder (JS).

Example

add_filter('acf_osm_geocoder_options', function( $geocoder_options ) {
    // Maps and borders have a colonial connotation. Using 19th century language seems more than appropriate.
    $geocoder_options['errorMessage'] = __('Sapperlot, es ist entzwei!');
    return $geocoder_options;
});

acf_osm_nominatim_options

Filter init options for nominatim geocoder.

Example

add_filter('acf_osm_nominatim_options', function( $nominatim_options ) {
    // most people on earth speak chinese
    $nominatim_options['geocoderQueryParams']['accept-language'] = 'zh';
    $nominatim_options['reverseQueryParams']['accept-language'] = 'zh';
    return $nominatim_options;
});

acf_osm_leaflet_providers

Filter available map layers. Please refer to the Leaflet Providers source.

Examples

Just adding a provider

add_filter('acf_osm_leaflet_providers', function( $providers ) {
    $providers[ 'WorldDominationMap' ] = array(
        'url' => 'https://{s}.dr-evil-maps.luna/{x}/{y}/{z}.png',
        'options' => array(
            'attribution' => '© Me and my Mini-Me, 2001',
        ),
    );
    return $providers;
});

Adding a provider with API-Key

add_filter('acf_osm_leaflet_providers', function( $providers ) {
    $providers[ 'WorldDominationMap' ] = array(
        'url' => 'https://{s}.dr-evil-maps.luna/{x}/{y}/{z}.png?access_token={access_token}',
        'options' => array(
            'attribution' => '© Me and my Mini-Me, 2001',
            'access_token' => 'sdjfw46rxcnw46rw47rxw476n4w7rfn47',
                // replace with your own api key.
        ),
    );
    return $providers;
});

Adding a provider with configurable API-Key

add_filter('acf_osm_leaflet_providers', function( $providers ) {
    $providers[ 'WorldDominationMap' ] = array(
        'url' => 'https://{s}.dr-evil-maps.luna/{x}/{y}/{z}.png?access_token={access_token}',
        'options' => array(
            'attribution' => '© Me and my Mini-Me, 2001',
            'access_token' => '<Insert Access Token Here>',
        ),
    );
    return $providers;
});

acf_osm_force_proxy

Force proxy mode for all tile providers. (@see Map Proxy)

Example

add_filter( 'acf_osm_force_proxy', '__return_true' );

acf_osm_marker_classname

Filters the markers class name.

Example

add_filter( 'acf_osm_marker_classname', function( $classname ) {
    return classname . ' my-marker-classname';
});

acf_osm_marker_html

Override marker HTML.

Example

PHP

add_filter('acf_osm_marker_html', function( $html ){
    return '<div class="my-marker"></div>';
});

CSS

Draw a small red Circle:

.my-marker {
    display:block;
    width:20px;
    height:20px;
    border-radius:10px;
    border:2px solid #f00;
    margin-top:-4px;
    margin-left:-4px;
}

Leaflet marker has a margin top/left of -6px from the map position. We have to subtract another 4px to match the center of the circle with the map position.

acf_osm_marker_icon

Example

Should return the arguments passed to L.icon.

add_filter('acf_osm_marker_icon', function( $icon ) {
    return array(
        'iconUrl'     => 'http://example.com/img/map-marker.svg',
        'iconSize'    => [ 40, 60 ],
        'iconAnchor'  => [ 20, 50 ],
    );
});

Anchor position is relative to the top left corner:

Icon Geometry