Hook: mam_geofilter_list

Use sparingly. This filter is the delegation point — it doesn’t extend the default list, it replaces it. If you only want to add or remove cities, use Hook: mam_wc_geofilters_locations instead. This article is here mainly for plugin authors integrating a different location source (the way mam-geodirectory does).


Signature

apply_filters( 'mam_geofilter_list', array $data_array );
Parameter Type Description
$data_array array The mobile JSON payload. Your callback must add geoFiltersLocations to it and return it.

Returns: array — the modified $data_array. You must return it.


Purpose

Lets a plugin take over the geofilter location list completely. When any callback is attached to this filter, mam-geofilters skips its built-in 55-city default list and the mam_wc_geofilters_locations extension hook, and uses whatever your callback puts into $data_array['geoFiltersLocations'].

The canonical user is mam-geodirectory, which sources locations from GeoDirectory taxonomies instead of a hardcoded list.


How presence is detected

In includes/phone-manager.php:

if ( has_filter( 'mam_geofilter_list' ) ) {
    $data_array = apply_filters( 'mam_geofilter_list', $data_array );
} else {
    $handler    = new mam_geofilters_list();
    $data_array = $handler->add_geofilters( $data_array );
}

has_filter() returns true the moment any callback is attached at any priority. There’s no concept of opting back into the default list once a callback is registered. If you add_filter() and then need to disable it conditionally, do that inside your callback — don’t try to remove_filter() it conditionally elsewhere.


Required output shape

Your callback must populate geoFiltersLocations with an array of entries shaped like:

$data_array['geoFiltersLocations'] = [
    [ 'text' => 'San Jose',     'lat' => '37.33874',  'lon' => '-121.885252', 'active' => 'on' ],
    [ 'text' => 'Oakland',      'lat' => '37.804363', 'lon' => '-122.271111', 'active' => 'on' ],
    [ 'text' => 'San Francisco', 'lat' => '37.7562',  'lon' => '-122.4430',   'active' => 'on' ],
];

The active key is optional but recommended. After your filter returns, the phone-data pipeline drops any entry whose active is set and not equal to 'on'. Entries without an active key are kept.


Example: minimal stub

add_filter( 'mam_geofilter_list', 'my_app_geofilter_list' );

function my_app_geofilter_list( $data_array ) {
    $data_array['geoFiltersLocations'] = [
        [ 'text' => 'Brooklyn',  'lat' => '40.6782', 'lon' => '-73.9442', 'active' => 'on' ],
        [ 'text' => 'Manhattan', 'lat' => '40.7831', 'lon' => '-73.9712', 'active' => 'on' ],
        [ 'text' => 'Queens',    'lat' => '40.7282', 'lon' => '-73.7949', 'active' => 'on' ],
    ];
    return $data_array;
}

After your filter returns, the pipeline still:

  1. Drops entries with active !== 'on'.
  2. Sorts alphabetically by text.
  3. Prepends “Current Location” if GPS is available, or a GeoIP-derived city if no_gps=yes and the GeoIP plugin is installed.
  4. Sets reload_home_on_location_change and home_silent_refresh.

You don’t need to do any of those steps yourself.


Gotchas

  • A no-op callback still disables the default list. Even add_filter( 'mam_geofilter_list', '__return_array' ) (or any other registration) will cause has_filter() to return true and the default-list path to be skipped. If you’re debugging “why are the 55 cities gone?”, check has_filter( 'mam_geofilter_list' ).
  • mam_wc_geofilters_locations is bypassed too. That hook only runs inside the default-list path. Plugins relying on it will silently lose their additions when this filter is registered.
  • Always return $data_array. Forgetting the return strips the whole mobile JSON payload, not just geoFiltersLocations.
  • Don’t pre-sort or pre-prepend “Current Location”. The pipeline does both after your filter returns. Pre-sorting wastes work; pre-prepending creates duplicates.

Verification

This article was last verified against:

  • Plugin: mam-geofilters v2.1.1
  • Source: mam-geofilters/includes/phone-manager.php
  • Reference subscriber: mam-geodirectory

Re-verify whenever the has_filter( 'mam_geofilter_list' ) gating logic changes, the post-filter pipeline (active-flag drop, alphabetical sort, GPS/GeoIP prepend, reload_home_on_location_change flags) changes, or the entry shape (text, lat, lon, active) is renamed.


  • Plugin overview: mam-geofilters
  • Hook: mam_wc_geofilters_locations — use this instead if you only need to add or remove cities
  • Hook: mam_force_geofilters
  • Hook: mam_geofilter_radius

Metadata

Field Value
Article type Hook Reference
Plugin slug mam-geofilters
Applies to plugin version 2.1.1+
Category Extending MAM Suite
Hook type filter
Audience PHP developer
Last verified 2026-04-30
Contents

    Need Support?

    Can’t find the answer you’re looking for? Don’t worry we’re here to help!