Skip to content
Documentation
< All Topics
Print

MAM Main – Hooks Filters

MAM Main – Plugin Documentation

Action: mam_update_current_user

This hook will update the $mam_user, $mam_user_id and $current_id global variables for use in WordPress and other MAM Plugins.

Call any time to update the current user using do_action( mam_update_current_user );

To get individual $user or $user_id values, you can also use the mam_get_user or mam_get_user_id filters.

Action: add_to_tracer

This hook enables troubleshooting for performance when you need to find bottlenecks. Add it to your code where you suspect a bottleneck or where you want to see the execution time to a certain point in your code.  Add a line in your code as follows:

do_action( ‘add_to_tracer’, ‘tag_to_track’ );

Where tag_to_track is a unique string identifier you can use to find the execution time of that line of code in the app refresh process.

Filter: mam_user and mam_user_id

These filters will get the current app user and app user ID.  Use the following in our code to get these values:

$user = apply_filters( ‘mam_get_user’, null  );

$user_id = apply_filters( ‘mam_get_use_id’, 0 );

Filter: convert_datetime_to_user_date_time

This filter will take a date and convert it to the user’s current date and time based on the timezone and daylight savings time offset for their current position.

apply_filters( ‘convert_datetime_to_user_date_time’, $date, $format = ‘Y/M/d’, $original_timezone = ‘UTC’ );

Action: mam_set_plugin_update_info (TSL Only)

This action checks the TSL repo to see if there is an update available for this account for this plugin. Place this at the top of every core and content plugin to check the TSL Repo for updates.

do_action( ‘mam_set_plugin_update_info’, basename(__DIR__), __FILE__ );

Filter: mam_check_required_version

This filter checks to see if the currently installed version of the MAM Main plugin is compatible with the installed plugin.

Notes: this is only available in MAM Main 1.9.1 and above. So it will return an empty string for all instances where MAM Main 1.9 or lower is installed.  In that case you need to handle the alert in your plugin.  This can be done using the following snippet:

add_action( ‘admin_init’, array( $this, ‘check_version’ ) );

function check_version()

{

$isCompatible = apply_filters( ‘mam_check_required_version’, ‘1.9.1’ , {plugin name} );

if( empty( $isCompatible ) )

{

    mamdebug(‘admin_alert’, ‘The plugin {name} requires version {version} or higher.’);

}

}

Action: mam_main_ajax

Most general purpose API calls are through this endpoint.  When called the API call has a subaction which specifies the action to take when consuming this API call.  For example, a call from a forum post to delete an entry will have a subaction of mam_forum_post_delete_manager, along with additional parameters.

App features that include an API call will use this endpoint.  See the documentation for individual UI elements for handling those API calls.

Filter: mam_tab_manager

This is a commonly used filter to manipulate the button and item json information. The filter has one parameter, $data_array, that contains either a button or a content json (also called an item json).  You can edit the data in these objects to fit a specific use case.

Need examples for button and item json 

Filter: mam_get_phone_data_before_send

This filter allows you to change any settings before the data is sent back to the phone for a general purpose API call.  The filter has one parameter $data_array, which contents the entire main json.  You can add, edit or delete elements in this filter. Note that most use case plugins should set the priority of this to 1000 so that it is called after all other plugins manipulate the data.

Need example for mam_get_phone_data_before_send

Note: this is a clone of tsl_get_phone_data_before_send which is slowly being renamed.

Action: mam_initial_phone_data

This hook is called at the beginning of the main json creation process.  It allows you to modify any request variables, or process anything prior to the main json getting built.  For example, this can be helpful if you want to modify the user lat and lon, or if you want to track when users hit the API. 

Action: mam_main_iap_subscription_has_changed

This is called when the main json is built and the user has changed their selected subscription via In App Purchase on the app.

Filter: mam_required_plugins

This filter will notify the admin that they are missing a plugin, or don’t have it activated.

add_filter( ‘mam_required_plugins’, array( $this, ‘mam_required_plugins’ ) );

function mam_required_plugins( $plugins )

{

     $plugins[] = array(

         ‘name’ => ‘WooCommerce’,

         ‘slug’ => ‘woocommerce/woocommerce.php’,

         ‘required’ => true,

         ‘url’ => ‘https://wordpress.org/plugins/woocommerce/’,

     );

     return $plugins;

}

App Settings

General

  • Track Page Views: this will turn on click tracking for detail screens on the app. When a user taps a detail listing item, then we increment the total_views post meta key for the related post.  Note that the total_views is not updated if the user tapping the item is the post author. This also sets the post read status for the user to ‘Read’ so that if you have plugins that use track_unread to track the read status, then it will show this item as having been read by the user.

Debug Functions

Function: mamdebug( ‘tag’, $value )

This allows you to add messages to the debug log.  the debug log can be found in Mobile App Manager -> Admin Log 

Tag – is any string that will identify the log entry.  Best when 20 characters or less.

$value – can be any string, array or object.

Note: if you set the tag to ‘delete’, then it will clear the log.  This is sometimes useful when you want to clear the log automatically during testing.

General Functions

Function: mam_distance_between( $lat, $lon, $to_lat, $to_lon );

This function can be utilized to get the distance between two points.

User Latitude and Longitude Management

If the user has GPS permissions turned on, then we get the lat and long coordinates for the user. If they have GPS turned off, then we do not get these coordinates.  To overcome this, you can install this plugin: https://wordpress.org/plugins/geoip-detect/ to use the IP address of the user to get an approximate location.  It’s not perfect, but usually fairly close.  This plugin can be installed by going to Mobile App manager > Software > Recommended.

Managing Cron Jobs for Scheduled Processes using FastCron Manager

To add a process to a cron job, you can use the filter mam_cron_manager.  The filter takes one parameter, $cron_jobs and you can add a cron job as follows:

$cron_jobs[] = array( ‘action’ => {callback_filter}, ‘name’ => {a name to be displayed on the cron dashboard}, ‘frequency’ => {number of minutes between executions}, ‘run_at’ => {time in 24 hour format for example 2330} );.

Callback filter has to be added to your plugin.  This is where your code will reside.  Return $results to be added to the API results when the task is executed when the specified time to run the task arrives..

Run_at is optional, if not present, then the cron job will run all the time between the specified periods.

Table of Contents