Hook: mam_geofilter_radius

Signature

apply_filters( 'mam_geofilter_radius', int $radius );
Parameter Type Description
$radius int Suggested default radius in miles. Often 0, in which case the plugin’s own callback substitutes 25.

Returns: int — the resolved radius in miles. You must return it.


Purpose

Returns the geofilter search radius in miles for the current request. The plugin registers its own callback at default priority that resolves the radius from a chain of sources:

  1. $_REQUEST['radius'] if present (the mobile app can override per request)
  2. The per-role setting tsl-setting-geofilter_radius (read via mam_app_settings_get_setting)
  3. The default of 25
  4. Capped at 3000

Subscribing to this filter at a later priority lets you override that resolved value — e.g., to bump the radius for premium users, clamp it tighter for a regional app, or shrink it on slow connections.


Default behavior

The callback that ships with the plugin is mam_geofilters_manager::mam_geofilter_radius() in mam-geofilters.php. Its precedence is:

$_REQUEST['radius']  >  per-role setting  >  25  >  capped at 3000

If you want the same resolution but with a different cap or a different default, the simplest path is to register a callback at a later priority and accept the value the core callback returned.


Examples

Bump the radius for one role

add_filter( 'mam_geofilter_radius', 'my_app_premium_radius', 20 );

function my_app_premium_radius( $radius ) {
    if ( current_user_can( 'premium_member' ) ) {
        return min( 100, max( $radius, 50 ) );
    }
    return $radius;
}

Tighten the cap to 200 miles

add_filter( 'mam_geofilter_radius', 'my_app_clamp_radius', 20 );

function my_app_clamp_radius( $radius ) {
    return min( 200, (int) $radius );
}

Gotchas

  • The 3000-mile cap only fires inside the core callback. A filter that runs later can return any positive integer. If your callback computes a wider radius and you still want the cap respected, re-apply min( 3000, $radius ) yourself.
  • Negative or non-integer values pass through. The core callback casts to int once at the very end; callbacks running after that don’t get the cast for free. Sanitize your own input.
  • $_REQUEST['radius'] short-circuits the per-role setting. If you’re debugging “why is this user getting a different radius than their role configures,” check whether the mobile client is sending an explicit radius query parameter.
  • This filter does not control whether geofilters are on. A radius of 0 does not turn the picker off; for that, see Hook: mam_force_geofilters.

Verification

This article was last verified against:

  • Plugin: mam-geofilters v2.1.1
  • Source: mam-geofilters/mam-geofilters.php (mam_geofilter_radius callback)

Re-verify whenever the precedence chain ($_REQUEST → per-role setting → default → cap) changes, the cap value changes, or the default value changes.


  • Plugin overview: mam-geofilters
  • Recipe: Enable geofilters — admin-side equivalent for setting the role default
  • Hook: mam_force_geofilters
  • Hook: mam_wc_geofilters_locations
  • Hook: mam_geofilter_list

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!