Managing Add-On Feeds with the GFAPI

Introduction

The following GFAPI methods are used to manage form Feeds. Each Feed contains the properties which determine if and how the form submission is processed by an add-on.

See the GFAPI article for other available methods.

get_feeds

GFAPI::get_feeds() was added in Gravity Forms version 1.8, it is used to get all feeds which match the given search criteria.

public static function get_feeds( $feed_ids = null, $form_id = null, $addon_slug = null, $is_active = true ) {}

Parameters

  • $feed_ids null|integer|array

    Optional. The ID of the Feed or an array of Feed IDs.

  • $form_ids null|string|array

    Optional. The ID of the Form to which the Feeds belong. Since 2.6.1 an array of IDs can be used to return feeds for multiple forms.

  • $addon_slug null|string

    Optional. The slug of the add-on to which the Feeds belong, including the gravityforms prefix. See the Gravity Forms Add-On Slugs article for a list of possible slugs.

  • $is_active boolean

    Optional. Default true. Indicates if only active or inactive feeds should be returned. Since 2.4.23.4 null can be used to return both.

Returns

Usage Examples

Getting all active feeds.

$result = GFAPI::get_feeds();

Getting a specific feed.

$result = GFAPI::get_feeds( 1 );

Getting multiple specific feeds.

$result = GFAPI::get_feeds( array( 1, 5 ) );

Getting all active feeds for a specific form.

$result = GFAPI::get_feeds( null, 2 );

Getting all active feeds for a specific add-on.

$result = GFAPI::get_feeds( null, null, 'gravityformszapier' );

get_feed

GFAPI::get_feed() was added in Gravity Forms version 2.4.23.4, it is used to get a specific feed.

public static function get_feed( $feed_id ) {}

Parameters

  • $feed_id integer

    The ID of the feed to retrieve.

Returns

Usage Examples

$result = GFAPI::get_feed( 1 );

add_feed

GFAPI::add_feed() was added in Gravity Forms version 1.8, it is used to add a new feed to the specified form with the given configuration.

public static function add_feed( $form_id, $feed_meta, $addon_slug ) {}

Parameters

  • $form_id integer

    The ID of the form to which the feed belongs.

  • $feed_meta array

    The feed properties, see the meta property of the Feed Object.

  • $addon_slug string

    The slug of the add-on to which the Feed belongs, including the gravityforms prefix. See the Gravity Forms Add-On Slugs article for a list of possible slugs.

Returns

  • $result WP_Error|integer

    A WP_Error if an error occurs or the ID of the Feed returned by the database.

Usage Examples

$result = GFAPI::add_feed( $form_id, $feed_meta, $addon_slug );

delete_feed

GFAPI::delete_feed() was added in Gravity Forms version 1.8, it is used to delete a specific Feed.

public static function delete_feed( $feed_id ) {}

Parameters

Returns

Usage Examples

$result = GFAPI::delete_feed( $feed_id );

update_feed

GFAPI::update_feed() was added in Gravity Forms version 1.8, it is used to update the meta for a specific Feed.

public static function update_feed( $feed_id, $feed_meta, $form_id = null ) {}

Parameters

Returns

Usage Examples

$result = GFAPI::update_feed( $feed_id, $feed_meta, $form_id );

feed_exists

GFAPI::feed_exists() was added in Gravity Forms version 2.4.24, it is used to check if a Feed exists for the given ID.

public static function feed_exists( $feed_id ) {}

Parameters

  • $feed_id integer

    The ID to be checked.

Returns

Usage Examples

$result = GFAPI::feed_exists( $feed_id );

update_feed_property

GFAPI::update_feed_property() was added in Gravity Forms version 2.4.24, it is used to update the properties of a specific Feed.

public static function update_feed_property( $feed_id, $property_name, $property_value ) {}

Parameters

  • $feed_id integer

    The ID of the Feed Object to be updated.

  • $property_name string

    The name of the property (column) being updated. Supported: form_id, is_active, feed_order, meta, and addon_slug

  • $property_value string|integer|array

    The new value of the specified property. The meta property can be passed as an associative array or JSON.

Returns

Usage Examples

$result = GFAPI::update_feed_property( $feed_id, $property_name, $property_value );
$result = GFAPI::update_feed_property( 1, 'is_active', 0 );

maybe_process_feeds

GFAPI::maybe_process_feeds() was added in Gravity Forms 2.9.2, it can be used to trigger processing of non-payment add-on feeds for the given entry by all or a specific feed add-on.

public static function maybe_process_feeds( $entry, $form, $addon_slug = '', $reset_meta = false ) {}

Parameters

  • $entry Entry Object

    The entry to be processed.

  • $form Form Object

    The form the entry belongs to.

  • $addon_slug string

    A specific add-on slug, or an empty string for all non-payment add-on feeds to be processed.

  • $reset_meta boolean

    Indicates if the processed feeds meta for the entry should be reset.

Returns

  • $result boolean|Entry Object

    The entry returned by the add-ons that processed the feed, or false when there isn’t an active feed add-on, or if an instance of the specified add-on does not exist.

Usage Examples

This example would trigger processing of all non-payment add-on feeds for the given entry and form.

$result = GFAPI::maybe_process_feeds( $entry, $form );

This example would trigger processing of feeds for a specific add-on.

$result = GFAPI::maybe_process_feeds( $entry, $form, 'gravityformswebhooks' );

This example would delete the processed feeds meta before triggering processing of feeds for all non-payment add-ons.

$result = GFAPI::maybe_process_feeds( $entry, $form, '', true );

get_processed_feeds_meta

GFAPI::get_processed_feeds_meta() was added in Gravity Forms 2.9.2, it can be used to retrieve the value of the processed_feeds meta for the specified entry.

public static function get_processed_feeds_meta( $entry_id, $addon_slug = '' ) {}

Parameters

  • $entry_id integer

    The ID of the entry the meta is to be retrieved for.

  • $addon_slug string

    A specific add-on slug to return the IDs for a specific add-on, or an empty string to return the meta for all add-ons.

Returns

  • $meta array

    An array of feed IDs for a specific add-on, or an array using the add-on slugs as the keys to the arrays of feed IDs.

Usage Examples

The following example would retrieve the meta for a specific add-on for the specified entry.

$feed_ids = GFAPI::get_processed_feeds_meta( $entry_id, 'gravityformswebhooks' );

The following example would retrieve the entire value of the processed_feeds meta for the specified entry.

$meta = GFAPI::get_processed_feeds_meta( $entry_id );

update_processed_feeds_meta

GFAPI::update_processed_feeds_meta() was added in Gravity Forms 2.9.2, it can be used to update the value of the processed_feeds meta for the specified entry.

public static function update_processed_feeds_meta( $entry_id, $addon_slug, $value, $form_id = null ) {}

Parameters

  • $entry_id integer

    The ID of the entry the meta is to be updated for.

  • $addon_slug string

    An add-on slug when updating the meta for a specific add-on, or an empty string to update the meta for all add-ons.

  • $value integer|array|null

    The ID of a processed feed for a specific add-on, an array of processed feed IDs for a specific add-on, an array using add-on slugs as the keys to arrays of processed feed IDs, or null to clear the meta.

  • $form_id null|integer

    The form ID of the entry (optional, saves extra query if passed when creating the metadata).

Returns

GFAPI::update_processed_feeds_meta() does not return a result.

Usage Examples

The following example would delete the feed IDs of the specified add-on from the process_feeds meta of the specified add-on.

GFAPI::update_processed_feeds_meta( $entry_id, 'gravityformswebhooks', null );

update_entry_feed_status

GFAPI::update_entry_feed_status() was added in Gravity Forms version 2.9.4, updates or deletes the feed processing status metadata (feed_{$feed_id}_status) for a specific entry.

public static function update_entry_feed_status( $entry_id, $feed_id, $status, $form_id = null ) {}

Parameters

  • $entry_id int
    The ID of the entry.
  • $feed_id int
    The ID of the feed.
  • $status array|null
    The status array is to append to the metadata, or null is to delete the metadata. The array includes:
    • $timestamp int – The timestamp of the feed processing attempt.
    • $status string – The status: success or failed.
    • $code int|string – The error code.
    • $message string – The error message.
    • $data array – Additional data related to the error.
  • $form_id null|int
    The form ID of the entry. This avoids extra queries when creating metadata.

Returns

  • void

Usage Examples

Logs a failed feed processing attempt with details or deletes the status metadata for an entry.

$entry_id = 5;
$feed_id  = 1;
$status   = array(
    'timestamp' => time(),
    'status'    => 'failed',
    'code'      => 403,
    'message'   => 'Invalid API key provided.',
    'data'      => array( 'retry_after' => 3600 ),
);
$form_id  = 2;

GFAPI::update_entry_feed_status( $entry_id, $feed_id, $status, $form_id );

// To delete the status metadata:
GFAPI::update_entry_feed_status( $entry_id, $feed_id, null );

get_entry_feed_status

GFAPI::get_entry_feed_status() was added in Gravity Forms version 2.9.4, retrieves the feed processing status for a specified entry from the feed_{$feed_id}_status metadata.

public static function get_entry_feed_status( $entry_id, $feed_id, $return_latest = false, $return_latest_details = false ) {}

Parameters

  • $entry_id int
    The ID of the entry.
  • $feed_id int
    The ID of the feed.
  • $return_latest bool
    If true, returns only the latest processing attempt. Default is false (returns all attempts).
  • $return_latest_details bool
    If true and $return_latest is true, returns the full details array of the latest attempt instead of just the status string. Default is false.

Returns

  • array|string
    An array of all processing attempts, the latest attempt’s status string, or the latest attempt’s full details, depending on the parameters.

Usage Examples

Retrieves all feed processing attempts, the latest status, or full details of the latest attempt for an entry.

$entry_id = 5;
$feed_id  = 1;

// Get all processing attempts
$all_statuses = GFAPI::get_entry_feed_status( $entry_id, $feed_id );
print_r( $all_statuses );

// Get the latest status (e.g., "success" or "failed")
$latest_status = GFAPI::get_entry_feed_status( $entry_id, $feed_id, true );
echo $latest_status;

// Get the full details of the latest attempt
$latest_details = GFAPI::get_entry_feed_status( $entry_id, $feed_id, true, true );
print_r( $latest_details );

get_entry_feed_status_key

GFAPI::get_entry_feed_status_key() was added in Gravity Forms version 2.9.4, returns the metadata key used to save or retrieve the feed status for a given feed.

public static function get_entry_feed_status_key( $feed_id ) {}

Parameters

  • $feed_id int
    The ID of the feed.

Returns

  • string
    The metadata key (e.g., feed_1_status).

Usage Examples

Generates the metadata key to access a feed’s status directly from an entry’s metadata.

$feed_id = 1;
$key = GFAPI::get_entry_feed_status_key( $feed_id );
echo $key; // Outputs: "feed_1_status"

// Use the key with other function
$entry_id = 5;
$status = gform_get_meta( $entry_id, $key );