Hook: mam_force_geofilters

Signature

apply_filters( 'mam_force_geofilters', bool $use_geofilters );
Parameter Type Description
$use_geofilters bool The on/off decision the plugin already arrived at by reading the role and settings.

Returns: bool — your final answer. You must return it.


Purpose

Provides a last-word override on whether geofilters are on for the current request. The plugin’s mam_use_geofilters callback first checks the role-based settings (tsl-use_geofilters and tsl-geofilters_show_as_icon), then runs that result through mam_force_geofilters to give code a chance to override.

Common reasons to register this filter:

  • Force-enable geofilters during local development without changing role settings
  • Disable geofilters on a specific page, role, or feature flag while leaving the global setting on
  • Toggle geofilters based on something the role-settings UI can’t express (a query parameter, a cookie, a custom user meta)

When it runs

Inside mam_geofilters_manager::mam_use_geofilters() (mam-geofilters.php):

$use_geofilters = ( 'yes' === $use_geofilters || 'yes' === $use_geofiltersAsIcon );
return apply_filters( 'mam_force_geofilters', $use_geofilters );

It is the very last step of the on/off decision. Whatever you return is what the rest of the platform sees.


Examples

Force-enable for a specific role

add_filter( 'mam_force_geofilters', 'my_app_geofilters_for_premium' );

function my_app_geofilters_for_premium( $use_geofilters ) {
    if ( current_user_can( 'premium_member' ) ) {
        return true;
    }
    return $use_geofilters;
}

Disable for a feature flag

add_filter( 'mam_force_geofilters', 'my_app_geofilters_kill_switch' );

function my_app_geofilters_kill_switch( $use_geofilters ) {
    if ( get_option( 'my_app_geofilters_disabled' ) === 'yes' ) {
        return false;
    }
    return $use_geofilters;
}

Gotchas

  • The name is misleading — this filter can also turn things off. Despite “force” in the name, it’s a plain filter. Returning false overrides a true upstream. If you only ever want to force-enable, structure your callback so it returns $use_geofilters unchanged in every other branch (as the examples above do).
  • Always return a bool. Returning null, an empty string, or omitting the return strips the on/off decision — downstream code casts to bool and may behave differently than expected.
  • Don’t read $_REQUEST here without sanitizing. If you’re toggling on a query parameter, validate it. The on/off decision is consulted on every phone-data request.
  • No interaction with the list. This filter only flips the picker UI on or off. It doesn’t affect what’s in the list — for that, see Hook: mam_wc_geofilters_locations or Hook: mam_geofilter_list.

Verification

This article was last verified against:

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

Re-verify whenever the on/off resolution chain in mam_geofilters_manager::mam_use_geofilters() changes, the role/setting precedence changes, or mam_force_geofilters is moved out of mam_use_geofilters.


  • Plugin overview: mam-geofilters
  • Recipe: Enable geofilters — admin-side equivalent
  • Hook: mam_geofilter_radius
  • 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!