Hook: mam_geodirectory_add_edit_form_fields

Signature

apply_filters( 'mam_geodirectory_add_edit_form_fields', array $fields );
Parameter Type Description
$fields array Array of field-definition arrays. Each entry is ['title' => ..., 'slug' => ...].

Returns: array — the modified $fields array. You must return it.


Purpose

Lets you extend the field list that mam_geodirectory_admin_settings::create_settings_array() registers for the per-post-type Add/Edit Listing form. The defaults are:

  • Listing Name (listing-name)
  • Photo (listing-photo)
  • Contact Name (contact-name)
  • Description (listing-desc)
  • Category (listing-category)
  • Post Type (post-type)
  • Address (listing-address)
  • Phone (listing-phone)
  • Email (email)
  • Website (listing-website)
  • Social Platforms (social_media)
  • Post ID (postid)

Adding to the array makes the new field appear in the field-visibility manager on the admin settings page and in the form’s expected field set, so the runtime knows to look for it.


When it runs

Inside mam_geodirectory_admin_settings::create_settings_array():

$fields = $this->get_base_listing_fields();
$fields = apply_filters( 'mam_geodirectory_add_edit_form_fields', $fields );

The filter is run once per admin page load, before the per-post-type tab adds its dynamic form settings.


Default values

The default array contains the twelve entries listed above. Each entry’s title is human-readable; each slug is a kebab-case identifier used as the form field’s slug and as the suffix to its option key (geodirectory_form_geodirectory_add_listing_form-{tab}_{slug}).


Example: add a “Hours of operation” tab field

add_filter( 'mam_geodirectory_add_edit_form_fields', 'my_app_add_hours_field' );

function my_app_add_hours_field( $fields ) {
    $fields[] = [
        'title' => 'Hours of operation',
        'slug'  => 'hours',
    ];
    return $fields;
}

After this, the field-visibility manager includes a “Hours of operation” row, and the admin can wire the corresponding Gravity Forms field to it.


Gotchas

  • Slugs must be unique. Two entries with the same slug produce two option keys but only the last one wins on save.
  • This filter does not register form fields by itself. It just extends the list of slot definitions; you still need a Gravity Form field with a matching slug for the runtime to populate it.
  • Always return the array. Forgetting return $fields strips the entire form definition.
  • Runs on every admin page load. Keep the callback fast — no DB queries.

Verification

This article was last verified against:

  • Plugin: mam-geodirectory v2.1.5
  • Source: includes/mam_geodirectory_admin_settings.phpcreate_settings_array(), get_base_listing_fields()

Re-verify whenever the default field list changes or create_settings_array() stops calling this filter.


  • Plugin: mam-geodirectory
  • Recipe: Configure the GeoDirectory settings page
  • Form: Add/Edit Listing
  • Hook: mam_geodirectory_admin_settings_tabs

Metadata

Field Value
Article type Hook Reference
Plugin slug mam-geodirectory
Applies to plugin version 2.1.5+
Category Extending MAM Suite
Hook type filter
Audience PHP developer
Last verified 2026-05-01
Contents

    Need Support?

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