Ga naar inhoud

Feed hooks

Deze inhoud is nog niet vertaald.

CampaignSuite feeds run actions for an entry at a chosen moment, such as when the entry is created or after a payment. With these hooks you can register your own feed types and moments, and decide whether a feed that already succeeded may run again.

Filter · includes/gravityforms/addons/class-feedaddon.php

Filters the available feed types. The built-in type is cs_dbg_webhook, and the Salesforce and Mautic integrations add their own types through this filter. A feed type needs value, label and process_callback.

Parameter Type Description
$feed_types array<string, array> Feed types keyed by ID. Each type has value (the ID), label, process_callback, and optionally settings (feed settings sections), format_result_callback, reference_table_label and analytics callbacks.
$form array|null The form object, when known.
$feed array|null The feed being edited, when known.

process_callback is called as ($feed, $entry, $form, $addon) and returns the raw result, or a WP_Error on failure. format_result_callback is called as ($result, $feed, $entry, $form) and returns the text shown in the entry note.

Returns: array<string, array> — the feed types.

add_filter('cs_forms_feed_types', function ($feed_types, $form, $feed) {
$feed_types['my_crm_push'] = [
'value' => 'my_crm_push',
'label' => __('My CRM | Push contact', 'my-plugin'),
'reference_table_label' => __('My CRM', 'my-plugin'),
'process_callback' => function ($feed, $entry, $form, $addon) {
$response = wp_remote_post('https://crm.example.com/contacts', [
'body' => ['email' => rgar($entry, '2')],
]);
return is_wp_error($response) ? $response : wp_remote_retrieve_response_code($response);
},
];
return $feed_types;
}, 10, 3);

Filter · includes/gravityforms/addons/class-feedaddon.php

Filters the moments at which a feed can run. The defaults are post_entry (“When entry is created”) and pre_confirmation (“Before confirmation”). The by_hand moment is always added after this filter, so you cannot remove it. The FinDock integration adds the findock_* moments here.

Parameter Type Description
$moments array<string, array> Moments keyed by ID. Each moment has value, label, description and order (lower is listed first).
$form array|null The form object.
$feed array|null The feed, when one is being edited.

Returns: array<string, array> — the moments.

add_filter('cs_forms_feed_moments', function ($moments, $form, $feed) {
$moments['my_review_done'] = [
'value' => 'my_review_done',
'label' => __('When review is completed', 'my-plugin'),
'description' => __('The feed is processed when your own code runs this moment.', 'my-plugin'),
'order' => 60,
];
return $moments;
}, 10, 3);

Filter · includes/gravityforms/addons/class-feedaddon.php

Decides whether a feed that already finished successfully for an entry may run again. By default it may not, and the feed is skipped with a warning note. The filter isn’t called for forced executions, or when the feed hasn’t succeeded before.

Parameter Type Description
$can_reexecute bool Default false.
$feed array The feed.
$entry array The entry.
$form array The form object.
$previous_result mixed The stored result of the earlier run.

Returns: bool — true to run the feed again.

add_filter('cs_forms_can_reexecute_feed_on_success', function ($can_reexecute, $feed, $entry, $form, $previous_result) {
return rgars($feed, 'meta/feed_name') === 'Newsletter signup' ? true : $can_reexecute;
}, 10, 5);

Filter · includes/class-mautic.php

Filters the Mautic form field types that are left out of the field mapping choices in a Mautic feed. The default is ['product', 'page', 'html', 'button']. The choices are cached for 5 minutes, so a change can take that long to show up.

Parameter Type Description
$types string[] Field types to exclude. Default ['product', 'page', 'html', 'button'].
$form object The Mautic form the fields belong to.

Returns: string[] — the field types to exclude.

add_filter('cs_forms_mautic_excluded_field_types', function ($types) {
$types[] = 'captcha';
return $types;
});