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:
$_REQUEST['radius']if present (the mobile app can override per request)- The per-role setting
tsl-setting-geofilter_radius(read viamam_app_settings_get_setting) - The default of
25 - 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
intonce 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 explicitradiusquery parameter.- This filter does not control whether geofilters are on. A radius of
0does not turn the picker off; for that, see Hook: mam_force_geofilters.
Verification
This article was last verified against:
- Plugin:
mam-geofiltersv2.1.1 - Source:
mam-geofilters/mam-geofilters.php(mam_geofilter_radiuscallback)
Re-verify whenever the precedence chain ($_REQUEST → per-role setting → default → cap) changes, the cap value changes, or the default value changes.
Related articles
- 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 |
