General hooks
Deze inhoud is nog niet vertaald.
These hooks cover the core behaviour of CampaignSuite Forms: the extra attributes on the form tag, what happens when a visitor comes back from a payment, how field values are resolved for feeds and add-ons, and how the admin finds out which posts embed a form.
Form output
Section titled “Form output”cs_forms_form_tag_data_attributes
Section titled “cs_forms_form_tag_data_attributes”Filter · includes/class-gravityforms.php
Filters the data-cs-* attributes added to the opening <form> tag of every Gravity Forms form. Use it to expose extra data to your front-end scripts. It runs on gform_form_tag, and only when the form tag is not empty.
| Parameter | Type | Description |
|---|---|---|
$attributes |
array<string, scalar> |
Attribute values keyed by name, without the data-cs- prefix. Defaults: form-id, form-title, number-of-pages and current-page. |
$form |
array |
The Gravity Forms form object. |
Returns: array<string, scalar> — the attributes. Each key becomes data-cs-{key}, and each value is escaped with esc_attr().
add_filter('cs_forms_form_tag_data_attributes', function ($attributes, $form) { $attributes['campaign'] = rgar($form, 'cs_campaign', 'default'); return $attributes;}, 10, 2);Confirmation and failed payments
Section titled “Confirmation and failed payments”cs_forms_confirmation_loaded
Section titled “cs_forms_confirmation_loaded”Action · includes/class-gravityforms.php
Fires when the visitor returns to the site after a successful payment and the form confirmation has been prepared. It runs before a redirect confirmation is followed, so you can still read or log the confirmation. It fires on every visit to the return URL, a reload included. The confirmation itself is prepared only once per entry. The Gravity Forms gform_confirmation filters run on the first return, and later visits get the stored confirmation.
| Parameter | Type | Description |
|---|---|---|
$confirmation |
array|string |
The confirmation as returned by Gravity Forms: an array (with a redirect key for a redirect confirmation) or the confirmation message markup. |
$form_id |
int |
The form ID. |
$lead |
array |
The Gravity Forms entry. |
$form |
array |
The form object, with the confirmation of the entry applied. |
add_action('cs_forms_confirmation_loaded', function ($confirmation, $form_id, $lead, $form) { error_log(sprintf('Confirmation shown for entry %d of form %d', rgar($lead, 'id'), $form_id));}, 10, 4);cs_forms_entry_failure_message
Section titled “cs_forms_entry_failure_message”Filter · includes/class-gravityforms.php
Filters the warning shown above the form when a visitor returns after a failed payment and the submitted values have been restored. The default is “It seems there was an issue with your previous submission. We have restored the information you entered, please review and submit again.”
| Parameter | Type | Description |
|---|---|---|
$message |
string |
The warning message. It is output as HTML without further escaping, so escape it yourself. |
$form |
array |
The form object. |
$entry |
\CampaignSuite\Core\Includes\Post_Types\Entry |
The CampaignSuite entry. |
$lead |
array |
The Gravity Forms entry. |
Returns: string — the message to show.
add_filter('cs_forms_entry_failure_message', function ($message, $form, $entry, $lead) { return esc_html__('Your payment did not go through. Your details are still here, please try again.', 'my-theme');}, 10, 4);Field values and entry meta
Section titled “Field values and entry meta”cs_field_value
Section titled “cs_field_value”Filter · includes/class-gravityforms.php
Filters the value of a mapped field when a Gravity Forms add-on, such as a feed, asks for it. It runs on gform_addon_field_value. If the value is still false for a non-numeric ID that is a known entry meta key, it is turned into null.
| Parameter | Type | Description |
|---|---|---|
$value |
mixed |
The value Gravity Forms resolved. |
$entry |
array |
The entry. |
$form |
array |
The form object. |
$field_id |
string|int |
The mapped field ID or entry meta key. |
$args |
array{context: string} |
context is the slug of the add-on that asked for the value. |
Returns: mixed — the value to use.
add_filter('cs_field_value', function ($value, $entry, $form, $field_id, $args) { if ($field_id === 'source_url' && is_string($value)) { return strtok($value, '?'); } return $value;}, 10, 5);cs_field_value_{field_id}
Section titled “cs_field_value_{field_id}”Filter · includes/class-gravityforms.php
The same filter for one specific field or entry meta key, for example cs_field_value_3 or cs_field_value_source_url. It runs right after cs_field_value, with the value that filter returned. Dots in input IDs are kept as they are, so a sub-input such as 3.6 is cs_field_value_3.6.
| Parameter | Type | Description |
|---|---|---|
$value |
mixed |
The value after cs_field_value. |
$entry |
array |
The entry. |
$form |
array |
The form object. |
$args |
array{context: string} |
context is the slug of the add-on that asked for the value. |
Returns: mixed — the value to use.
add_filter('cs_field_value_5', function ($value, $entry, $form, $args) { return preg_replace('/\D+/', '', (string) $value);}, 10, 4);cs_resolve_post_entry_meta_{meta_key}
Section titled “cs_resolve_post_entry_meta_{meta_key}”Filter · includes/class-gravityforms.php
Lets you supply a value for a custom entry meta key that is resolved from the post the form was submitted on. {meta_key} is the entry meta key. The plugin resolves cs_originating_post_slug, cs_originating_post_title and cs_originating_post_campaign_code itself. Any other key registered with the post-meta callback goes through this filter. It doesn’t run when the entry already has a value, or on an entry-detail edit.
| Parameter | Type | Description |
|---|---|---|
$value |
mixed |
The value so far. Default null. |
$post_id |
int |
The ID of the originating post. |
$entry |
array |
The entry. |
$form |
array |
The form object. |
$meta_key |
string |
The entry meta key. |
Returns: mixed — the value to store, or null for none.
add_filter('cs_resolve_post_entry_meta_cs_originating_post_type', function ($value, $post_id, $entry, $form, $meta_key) { return get_post_type($post_id);}, 10, 5);Form references
Section titled “Form references”The form reference table in the admin lists every form with the posts that embed it. The lookup is cached, the list of posts per form for an hour and the whole table for four hours.
cs_forms_form_reference_data
Section titled “cs_forms_form_reference_data”Filter · includes/class-gravityforms.php
Filters the data of the form reference table, after it has been built and before it is cached.
| Parameter | Type | Description |
|---|---|---|
$data |
array |
An array with a forms list (each form has id, title, reference_data and links with edit, entries and preview) and an addons map of add-on labels to lists of form IDs. |
$forms |
array[] |
The form objects the data was built from. |
Returns: array — the data.
add_filter('cs_forms_form_reference_data', function ($data, $forms) { foreach ($data['forms'] as &$form) { $form['title'] = sprintf('#%d %s', $form['id'], $form['title']); } return $data;}, 10, 2);cs_forms_reference_meta_keys
Section titled “cs_forms_reference_meta_keys”Filter · includes/class-gravityforms.php
Filters the post meta keys that are checked for a form ID. A post whose meta value for one of these keys equals the form ID counts as embedding the form. The default is ['gf_form_id'].
| Parameter | Type | Description |
|---|---|---|
$meta_keys |
string[] |
The meta keys. Default ['gf_form_id']. |
Returns: string[] — the meta keys. Return an empty array to skip the meta lookup.
add_filter('cs_forms_reference_meta_keys', function ($meta_keys) { $meta_keys[] = 'donation_form_id'; return $meta_keys;});cs_forms_reference_block_references
Section titled “cs_forms_reference_block_references”Filter · includes/class-gravityforms.php
Filters the SQL conditions used to find the form in post_content. Each condition is a LIKE fragment with one %d placeholder for the form ID, and a literal percent sign is written as %%. The conditions are combined with OR. The defaults match the [gravityform id="…"] and [gravityforms id="…"] shortcodes and the Gravity Forms block.
| Parameter | Type | Description |
|---|---|---|
$conditions |
string[] |
The SQL conditions. |
Returns: string[] — the conditions. Return an empty array to skip the content lookup. Each entry must contain exactly one %d and no unescaped user input.
add_filter('cs_forms_reference_block_references', function ($conditions) { $conditions[] = "post_content LIKE '%%wp:my-theme/donation-form {\"formId\":%d%%'"; return $conditions;});cs_forms_reference_post_types
Section titled “cs_forms_reference_post_types”Filter · includes/class-gravityforms.php
Filters the post types searched for form references. The default is ['page', 'post'].
| Parameter | Type | Description |
|---|---|---|
$post_types |
string[] |
Post type names. Default ['page', 'post']. |
Returns: string[] — the post types.
add_filter('cs_forms_reference_post_types', function ($post_types) { $post_types[] = 'campaign'; return $post_types;});cs_forms_reference_post_statuses
Section titled “cs_forms_reference_post_statuses”Filter · includes/class-gravityforms.php
Filters the post statuses searched for form references. The default is ['publish'].
| Parameter | Type | Description |
|---|---|---|
$post_statuses |
string[] |
Post statuses. Default ['publish']. |
Returns: string[] — the post statuses.
add_filter('cs_forms_reference_post_statuses', function ($post_statuses) { $post_statuses[] = 'draft'; return $post_statuses;});