Purpose
Fires when the mobile app reports a favorite-toggle event (user tapped the star on a row). The Favorites content class provides the renderer + the AJAX endpoint; this action is where sibling plugins persist the change.
The report_favorites = 'yes' JSON flag enables the toggle event. Without it, the app doesn’t fire the AJAX, so the action never fires.
Signature
do_action(
'mam_manage_favorites',
int $post_id,
int $user_id,
bool $is_favorite // true = favorite, false = unfavorite
);
| Parameter | Type | Description |
|---|---|---|
$post_id |
int | The post being favorited / unfavorited |
$user_id |
int | The user toggling |
$is_favorite |
bool | Direction of the toggle |
Example: persist for a sibling plugin
add_action( 'mam_manage_favorites',
function ( int $post_id, int $user_id, bool $is_favorite ) {
// Only handle our post type.
if ( get_post_type( $post_id ) !== 'my_plugin_listing' ) {
return;
}
$favs = (array) get_user_meta( $user_id, 'my_plugin_favorites', true );
if ( $is_favorite ) {
$favs[] = $post_id;
$favs = array_unique( $favs );
} else {
$favs = array_diff( $favs, array( $post_id ) );
}
update_user_meta( $user_id, 'my_plugin_favorites', array_values( $favs ) );
},
10, 3
);
Where favorites are sourced
mam-main itself doesn’t own a single favorites table. Sibling plugins maintain favorites in their own usermeta:
| Plugin | usermeta key |
|---|---|
| mam-geodirectory | gd_user_favourite_post |
| mam-special-offers | (per-plugin) |
| your sibling plugin | (your choice — prefix with plugin slug) |
The Favorites content class assembles the list by walking subscribers via mam_get_phone_data_before_send.
JSON shape (favorites list in phone-data)
{
"favorites": ["123", "456", "789"],
"report_favorites": "yes",
"hide_remove_all_favorites": "yes"
}
favorites is an array of strings — frozen because older mobile parsers reject numeric ids. Don’t return integers.
Gotchas
- Action fires only when
report_favorites = 'yes'is set in the phone-data payload. If your sibling plugin owns the post type but doesn’t set this flag, the toggle never reaches the server. favoritesarray uses strings. Don’t return integers from your contribution to the favorites list.- No de-duplication across plugins. If two plugins both claim the same post id as “their” favorite, both might persist. Coordinate via
get_post_typechecks. - No batch. Each toggle fires the action once. Heavy persistence work blocks the AJAX response.
- No undo. A toggle is immediate — there’s no “queued” or “pending” state.
Related articles
- Content class: Favorites
- Hook: mam_get_phone_data_before_send
- Mobile JSON shape
Metadata
| Field | Value |
|---|---|
| Article type | Hook Reference |
| Plugin slug | mam-main |
| Applies to plugin version | 2.1.11+ |
| Hook type | action |
| Audience | PHP developer |
| Last verified | 2026-05-02 |
