Prevent Gravity Forms from sending Webhook given condition

Viewed 132

I'm trying to apply a filter to Gravity Form's Webhook add-on and I just can't wrap my head around it. I have created a function below that from what I have read should prevent the Webhook feed from sending the form on submission but it's just not working.

I'm sure I'm missing something but I could use a second set of eyes, and some expertise. Below is a unit test to disable any web hook on form 8, and then I will expand to make active under specific condition.

// Gravity Forms Webhook Filter
add_filter( 'form_gravityformswebhooks_pre_process_feeds_8', 'disable_webhook_by_field');
function disable_webhook_by_field( $feed, $entry, $form )
{
    $feed['is_active'] = false;
    return $feed;
}
1 Answers

After taking a step back and then reading through documentation again I completely overlooked that it is not one feed, but an array of feeds for the form that get passed, so I have to iterate through and check for each.

Below is my final function that passes the submitted form name fields to a function and disables the Webhook if the name is not recognized.

Hope this is useful to someone.

// Gravity Forms Webhook Name Filter
add_filter( 'form_gravityformswebhooks_pre_process_feeds_8', 'disable_webhook_by_name');
function disable_webhook_by_name( $feeds, $entry, $form )
{
    $firstname = rgar( $entry, '1.3' );
    $lastname = rgar( $entry, '1.6' );

    // Checks user name against database and disables Webhook is not found
    foreach ( $feeds as & $feed )
    {
        if ( ! checkName( $firstname, $lastname ) )
        {
            $feed = rgar( $feed, 'is_active', false );
        }
    }
   
    return $feeds;

}
Related