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

ParameterTypeDescription
$feed_idsnull | integer | arrayOptional. The ID of the Feed or an array of Feed IDs.
$form_idsnull | string | arrayOptional. 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_slugnull | stringOptional. 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_activebooleanOptional. 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

ReturnTypeDescription
$resultarray | WP_ErrorAn array of Feed Objects or a WP_Error instance.

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

ParameterTypeDescription
$feed_idintegerThe ID of the feed to retrieve.

Returns

ReturnTypeDescription
$resultarray | WP_ErrorThe Feed Object or a WP_Error instance.

Usage Examples

$result = GFAPI::get_feed( 1 );

get_feed_name

GFAPI::get_feedname() was added in Gravity Forms version 2.9.9, it retrieves the name of the given feed.

public static function get_feed_name( $feed, $key = '' ) {}

Parameters

ParameterTypeDescription
$feedarrayThe feed. Required
$keystringThe key used to store the name

Returns

ReturnDescription
stringThe feed name

Usage Examples

$feed = GFAPI::get_feed( 123 );
$feed_name = GFAPI::get_feed_name( $feed );

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

ParameterTypeDescription
$form_idintegerThe ID of the form to which the feed belongs.
$feed_metaarrayThe feed properties, see the meta property of the Feed Object.
$addon_slugstringThe 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

ReturnTypeDescription
$resultWP_Error | integerA 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

ParameterTypeDescription
$feed_idintegerThe ID of the Feed Object to be deleted.

Returns

ReturnTypeDescription
$resultboolean | WP_Errortrue for success or a WP_Error instance.

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

ParameterTypeDescription
$feed_idintegerThe ID of the Feed Object to be updated.
$feed_metaarrayThe feed properties, see the meta property of the Feed Object.
$form_idintegerThe ID of the form to which the feed belongs.

Returns

ReturnTypeDescription
$resultboolean | WP_Errortrue for success or a WP_Error instance.

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

ParameterTypeDescription
$feed_idintegerThe ID to be checked.
  • $feed_id integer

    The ID to be checked.

Returns

ReturnTypeDescription
$resultbooleanWhether or not a Feed Object exists for the supplied ID.

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

ParameterTypeDescription
$feed_idintegerThe ID of the Feed Object to be updated.
$property_namestringThe name of the property (column) being updated. Supported: form_id, is_active, feed_order, meta, and addon_slug.
$property_valuestring | integer | arrayThe new value of the specified property. The meta property can be passed as an associative array or JSON.

Returns

ReturnTypeDescription
$resultboolean | WP_Errortrue for success or a WP_Error instance.

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

ParameterTypeDescription
$entryEntry ObjectThe entry to be processed.
$formForm ObjectThe form the entry belongs to.
$addon_slugstringA specific add-on slug, or an empty string for all non-payment add-on feeds to be processed.
$reset_metabooleanIndicates if the processed feeds meta for the entry should be reset.

Returns

ReturnTypeDescription
$resultboolean | Entry ObjectThe 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

ParameterTypeDescription
$entry_idintegerThe ID of the entry the meta is to be retrieved for.
$addon_slugstringA 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

ReturnTypeDescription
$metaarrayAn 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

ParameterTypeDescription
$entry_idintegerThe ID of the entry the meta is to be updated for.
$addon_slugstringAn add-on slug when updating the meta for a specific add-on, or an empty string to update the meta for all add-ons.
$valueinteger | array | nullThe 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_idnull | integerThe 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

ParameterTypeDescription
$entry_idintThe ID of the entry.
$feed_idintThe ID of the feed.
$statusarray | nullThe status array to append to the metadata, or null 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_idnull | intThe 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

ParameterTypeDescription
$entry_idintThe ID of the entry.
$feed_idintThe ID of the feed.
$return_latestboolIf true, returns only the latest processing attempt. Default is false (returns all attempts).
$return_latest_detailsboolIf 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

ReturnTypeDescription
—array | stringAn array of all processing attempts, the latest attempt’s status string, or the latest attempt’s full details array, 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

ParameterTypeDescription
$feed_idintThe ID of the feed.

Returns

ReturnTypeDescription
—stringThe 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 );