Hook: mam_form_photo_finalized (a form photo was kept)

Purpose

When someone picks a photo in a form on the app, the app uploads it right away (subaction mam_form_upload_temp_image). mam-main saves it as a private attachment tagged _is_temp_upload, because the person may still cancel the form. When the form is submitted, mam-main removes that tag and the photo is kept.

mam_form_photo_finalized fires at that moment, once per photo. It is the right place to post-process photos that app users took or chose themselves, for example to resize, sharpen, moderate, or log them.

Images that reach the site any other way (imported, sideloaded from an outside service, uploaded in wp-admin) never pass through this hook.


Signature

do_action( 'mam_form_photo_finalized', int $attachment_id, array $form_context );
Parameter Type Description
$attachment_id int The attachment post ID of the kept photo.
$form_context array Where the photo was submitted. See below.

$form_context keys:

Key Type Meaning
form_id int The Gravity Forms form ID, or 0 when it is not known.
field_id string The form field ID the photo was submitted in (a string, it can look like "5.1").
post_id int The post_id sent with the submission, or 0 when none was sent.

When it fires (and when it does not)

  • Fires when a submitted file upload field carries a photo_id that still had the _is_temp_upload tag.
  • Does not fire when the field says the photo is unchanged (image_state = same_photo).
  • Does not fire for an ID that was already kept, so resubmitting a form never fires it twice for the same photo.
  • Does not fire for signatures, gallery arrays, or raw base64 values sent inside the submission.

It runs inside the form submission request. Keep the callback quick, or defer heavy work (for example to shutdown or a scheduled event), so the app is not kept waiting.

The attachment is still private and still carries _hide_from_library when the hook runs. Do not change its URL: the submission refers to it by ID and other code may already have stored its URL.


Example

add_action( 'mam_form_photo_finalized', function ( int $attachment_id, array $form_context ) {
    if ( 12 !== $form_context['form_id'] ) {
        return;
    }
    update_post_meta( $attachment_id, 'my_plugin_source_form', $form_context['form_id'] );
}, 10, 2 );

Verification

  • Source: includes/forms-manager/form-data-manager.php, handle_file_upload() (the “already-uploaded photo” case)
  • Upload side: includes/forms-manager/form-image-manager.php, upload_hold_image()

  • Hook: mam_form_manager_process_fieldtype{type}
  • Image enhance for app photos (mam-ai-manager)

Metadata

Field Value
Article type Hook Reference
Plugin slug mam-main
Applies to plugin version 26.40.9+ (beta)
Category Extending MAM Suite
Hook type action
Audience PHP developer / integrator
Last verified 2026-10-02
Was this article helpful?
Contents

    Need Support?

    Can't find the answer you're looking for? Don't worry we're here to help!