Signature
apply_filters(
'mam_for_gravity_forms_web_form_result_form_' . $form_id,
int $form_id,
int $post_id
);
| Parameter | Type | Description |
|---|---|---|
$form_id |
int | The Gravity Forms form ID of the just-submitted form. Same value embedded in the hook name. |
$post_id |
int | The ID of the post mam-gravity-forms-manager just created or updated from the entry. |
Returns: ignored. The plugin discards the return value. You must still return something (return $form_id by convention) because the dispatcher uses apply_filters() and skipping the return strips the value upstream listeners might inspect — see Gotchas.
Purpose
Per-form callback point that fires once a Gravity Forms web submission has been turned into a custom-post-type post. Consumers use it to do the work that depends on the post existing: set a status, geocode an address, send a custom notification, mark the user as having submitted, propagate to a downstream feature, etc.
The hook is dynamic — its name embeds the GF form ID. This lets a single callback target one specific form without filtering on $form_id inside the body. Two consumers wiring different forms never collide.
If no callback is registered for a given form ID, the entire gform_after_submission body inside this plugin short-circuits via has_filter() — no post is created, no meta is saved. The hook’s presence is the trigger.
When it runs
Inside mam_gf_submit_web_form::after_submission() (includes/submit-web-form.php), at the end of the per-form work:
gform_after_submissionfires (Gravity Forms).- The plugin gates on
has_filter( 'mam_for_gravity_forms_web_form_result_form_{form_id}' ). No subscribers → exit. mam_gf_get_form_settingsis read; the field mapping for this form is resolved.- Entry values are mapped into a
$valuesarray keyed by slug. - The post is created (
wp_insert_post) or updated (wp_update_post). - Each mapped value is saved via
update_post_meta. mam_for_gravity_forms_web_form_result_form_{form_id}runs. ← your callback.
By the time your callback runs, get_post( $post_id ) works and get_post_meta( $post_id, '<your-slug>', true ) returns the submitted value.
This filter does not run on app-submitted forms. Those go through mam_form_manager_send_notifications, which is a different code path. If you need to react to both flows, subscribe to each.
Examples
Send a custom email after the post is created
add_filter( 'mam_for_gravity_forms_web_form_result_form_42', 'my_app_offer_email', 10, 2 );
function my_app_offer_email( $form_id, $post_id ) {
$title = get_post_meta( $post_id, 'offer-title', true );
$author_email = get_the_author_meta( 'user_email', get_post_field( 'post_author', $post_id ) );
wp_mail(
$author_email,
sprintf( 'Your offer "%s" was received', $title ),
"We'll review it shortly. Post ID: {$post_id}"
);
return $form_id;
}
Set the post status after creation
By default the plugin inserts posts as publish. To stage submissions for moderation instead:
add_filter( 'mam_for_gravity_forms_web_form_result_form_42', 'my_app_offer_pending', 10, 2 );
function my_app_offer_pending( $form_id, $post_id ) {
if ( ! current_user_can( 'publish_posts' ) ) {
wp_update_post( [
'ID' => $post_id,
'post_status' => 'pending',
] );
}
return $form_id;
}
Geocode an address field
add_filter( 'mam_for_gravity_forms_web_form_result_form_42', 'my_app_offer_geocode', 10, 2 );
function my_app_offer_geocode( $form_id, $post_id ) {
$address = get_post_meta( $post_id, 'address', true );
if ( empty( $address ) ) {
return $form_id;
}
$coords = my_app_geocode( $address ); // your geocoder
if ( $coords ) {
update_post_meta( $post_id, 'lat', $coords['lat'] );
update_post_meta( $post_id, 'lng', $coords['lng'] );
}
return $form_id;
}
Gotchas
- It’s a filter, not an action.
apply_filters()is used for side-effect dispatch (TD-GF-005). The plugin ignores your return value, but you still must return —apply_filters()chains the return through every subscriber, and a missing return passesnullto the next subscriber. By convention, return$form_id. A future change todo_action()is planned but requires coordinated updates acrossmam-special-offersandmam-geodirectory; until then, treat this hook as an action you’re forced to spelladd_filter. - The gate is
has_filter(), not anything else. Evenadd_filter( 'mam_for_gravity_forms_web_form_result_form_42', '__return_true' )is enough to enable the entire post-creation flow. If posts are appearing unexpectedly,grepfor anyadd_filteragainst the form’s hook name. - No subscribers = no post is created. New developers expect this hook to be a “post-processing” hook, but it’s actually the trigger. If you want web submissions to create posts and you don’t have a consumer subscribed, nothing happens.
- Don’t expect
$entry. The hook signature is($form_id, $post_id)— no entry array. To read submitted values back out, useget_post_meta()against the slugs yourmam_gf_get_form_settingsentry registered. The raw GF entry array is also available in the global$mam_form_entry(set by the plugin earlier in the same request), but relying on a global is brittle — prefer the post meta path. - Runs once per submission. Even though the plugin reads
mam_gf_get_form_settingstwice per submission (a known redundancy noted indocs/CODEBASE_MAP.md), this hook fires exactly once. - The post is
publishby default. If your CPT shouldn’t auto-publish, change the status inside your callback (see the second example above) or use a different CPT whose default status you control. - The post author is the current user.
wp_insert_post()is called with'post_author' => get_current_user_id(). For an unauthenticated submission this is0. Decide explicitly inside your callback what should happen for guest submissions.
Verification
This article was last verified against:
- Plugin:
mam-gravity-forms-managerv2.3 - Source:
mam-gravity-forms-manager/includes/submit-web-form.php(mam_gf_submit_web_form::after_submission()) - Reference subscribers:
mam-special-offers,mam-geodirectory
Re-verify whenever the dispatcher line in after_submission() changes from apply_filters() to do_action() (planned, TD-GF-005), the hook name template (mam_for_gravity_forms_web_form_result_form_ + $form_id) changes, the ($form_id, $post_id) signature changes, or the has_filter() gate moves out of after_submission().
Related articles
- Plugin overview: mam-gravity-forms-manager
- Recipe: Route a web submission to a custom post type — admin-side counterpart to this hook
- Hook: mam_gf_get_form_settings — the provider hook this plugin reads to know how to map the entry to a post
Metadata
| Field | Value |
|---|---|
| Article type | Hook Reference |
| Plugin slug | mam-gravity-forms-manager |
| Applies to plugin version | 2.3+ |
| Category | Extending MAM Suite |
| Hook type | filter (used as action dispatch — see Gotchas) |
| Audience | PHP developer |
| Last verified | 2026-05-01 |
