Skip to content

Entry hooks

An entry is a CampaignSuite record stored as a cs-entry post. It has a type (entry or payment), a source (the system that created it, for example a form plugin) and a client (the system it is sent to, for example salesforce). The hooks on this page follow an entry through its life: its title and class, sending it to its client, the visitor’s success and failure returns, events and webhooks, and the entry admin screens.

Several hook names contain the entry’s client or source. The {client} and {source} placeholders are the values stored on the entry with set_client() and set_source(). Core itself handles the client salesforce. Sources and other clients come from the plugins that create the entries.

Filter · includes/post-types/class-entry.php

Filters the title template of a new entry. It runs when an entry object is created without an ID. Core sets the default to Entry %s for entries and Payment %s for payments (at priority 0), so add your filter at the default priority or later to override it. The %s placeholder is replaced with the first 8 characters of the entry hash.

Parameter Type Description
$template string The sprintf() template, with one %s. Default: Entry %s.
$type string The entry type: entry or payment.
$entry Entry The new entry object.

Returns: string — a sprintf() template with exactly one %s.

add_filter('cs_entry_title_template', function ($template, $type, $entry) {
if ($type === 'payment') {
return __('Donation %s', 'my-addon');
}
return $template;
}, 10, 3);

Filter · includes/helpers.php

Lets a plugin return its own entry class for an entry type that Core does not know. cs_get_entry() reads the type of the stored entry. Core handles the types entry and payment, and any other value runs this filter. The dynamic part {type} is that stored type. Return an object that extends Entry (or Payment).

Parameter Type Description
$entry Entry The default object: an Entry loaded for the ID.
$id int The post ID of the entry.

Returns: Entry — the entry object for this type.

add_filter('cs_get_entry_donation', function ($entry, $id) {
return new My_Addon_Donation($id);
}, 10, 2);

Filter · includes/post-types/class-entry.php

Filters the capability needed to see and manage entries and payments. It applies to the cs-entry post type capabilities, the Entries admin pages and the entry actions.

Parameter Type Description
$capability string The capability. Default: edit_others_posts (Editors and Administrators).

Returns: string — the capability.

add_filter('cs_entry_capability', function ($capability) {
return 'manage_options';
});

Filter · includes/class-apicontroller.php

Filters the maximum body size of an incoming entry webhook request. Larger requests are rejected before they are processed.

Parameter Type Description
$max_bytes int The maximum size in bytes. Default: 262144 (256 KB).

Returns: int — the maximum size in bytes.

add_filter('cs_entry_webhook_max_body_size', function ($max_bytes) {
return 512 * KB_IN_BYTES;
});

Filter · includes/post-types/class-entry.php

Sends the entry to its client. It runs when $entry->execute() is called. The dynamic part {client} is the entry’s client, for example cs_entry_execute_salesforce. A client plugin hooks in here, sends the entry and returns the result. If no callback is registered, the value stays a WP_Error with the code not_implemented.

If the result is not an error and has success set to true, the entry stores the id as its client result ID, queues the analytics event and is saved.

Parameter Type Description
$value array|WP_Error The current result. Default: a not_implemented WP_Error.
$entry Entry The entry that is sent.
$type string The entry type: entry or payment.
$source string|null The entry source.

Returns: array|WP_Error — an array with success (bool) and id (the ID at the client), or a WP_Error.

add_filter('cs_entry_execute_my-crm', function ($value, $entry, $type, $source) {
$id = my_crm_send($entry->get_id());
if (!$id) {
return new WP_Error('my_crm_failed', 'Sending to My CRM failed.');
}
return ['success' => true, 'id' => $id];
}, 10, 4);

Filter · includes/post-types/class-entry.php

Handles a visitor who returns to the success URL of an entry, for example after paying. The dynamic part {source} is the entry’s source. Core adds a note to the entry first. If the result is not an error, the entry moves to Processing, and on an error it moves to Errored. A status that is already past Created (for example Completed, set by a webhook) is never changed.

Parameter Type Description
$value mixed|WP_Error The current result. Default: a not_implemented WP_Error.
$entry Entry The entry.
$data array The decoded request body.
$type string The entry type: entry or payment.
$client string|null The entry client.

Returns: mixed|WP_Error — usually the URL to redirect the visitor to, or a WP_Error when the return could not be handled.

add_filter('cs_entry_success_my-form', function ($value, $entry, $data, $type, $client) {
return home_url('/thank-you/');
}, 10, 5);

Filter · includes/post-types/class-entry.php

Handles a visitor who returns to the failure URL of an entry, for example after a cancelled payment. The dynamic part {source} is the entry’s source. Core adds an error note to the entry first, but does not change the entry status.

Parameter Type Description
$value mixed|WP_Error The current result. Default: a not_implemented WP_Error.
$entry Entry The entry.
$data array The decoded request body.
$type string The entry type: entry or payment.
$client string|null The entry client.

Returns: mixed|WP_Error — usually the URL to redirect the visitor to, or a WP_Error.

add_filter('cs_entry_failure_my-form', function ($value, $entry, $data, $type, $client) {
return home_url('/payment-failed/');
}, 10, 5);

Events are changes that the client reports about an entry, for example a payment that is completed. They are processed in the background, one at a time per entry, and each one fires the actions below with the entry and the event.

Action · includes/post-types/class-entry.php

Fires before an event is handled for an entry, ahead of the client and source specific actions.

Parameter Type Description
$entry Entry The entry.
$event_name string The event name.
$data mixed The event data.
add_action('cs_entry_pre_execute_event', function ($entry, $event_name, $data) {
error_log(sprintf('Event %s for entry %d', $event_name, $entry->get_id()));
}, 10, 3);

Action · includes/post-types/class-entry.php

Fires to handle an event for the entry’s client. The dynamic part {client} is the entry’s client, for example cs_entry_execute_event_salesforce_client, which is where Core handles the Salesforce payment events.

Parameter Type Description
$entry Entry The entry.
$event_name string The event name.
$data mixed The event data.
add_action('cs_entry_execute_event_my-crm_client', function ($entry, $event_name, $data) {
if ($event_name === 'payment.completed') {
$entry->add_note('Payment completed at My CRM.', 'system', 'event');
}
}, 10, 3);

Action · includes/post-types/class-entry.php

Fires to handle an event for the entry’s source. The dynamic part {source} is the entry’s source. Use it to let the system that created the entry react to what happened at the client.

Parameter Type Description
$entry Entry The entry.
$event_name string The event name.
$data mixed The event data.
add_action('cs_entry_execute_event_my-form_source', function ($entry, $event_name, $data) {
// Update the submission that belongs to this entry.
}, 10, 3);

Action · includes/post-types/class-entry.php

Fires after an event is handled for an entry, after the client and source specific actions.

Parameter Type Description
$entry Entry The entry.
$event_name string The event name.
$data mixed The event data.
add_action('cs_entry_post_execute_event', function ($entry, $event_name, $data) {
$entry->save();
}, 10, 3);

Filter · includes/post-types/class-entry.php

Filters the entry admin pages and their subpages. Use it to add a list page for an entry type of your own under the CampaignSuite Entries menu.

Each page has label (menu and page title), single (the singular name), type (the entry type the list shows, matched against the stored entry type, or all) and optionally subpages. Subpages are keyed by menu slug and also have parent (the parent menu slug) and id.

Parameter Type Description
$pages array The page configs keyed by menu slug. Default: cs-entries, with the subpages cs-entries-list (type entry) and cs-payments-list (type payment).

Returns: array — the page configs keyed by menu slug.

add_filter('cs_entry_pages', function ($pages) {
$pages['cs-entries']['subpages']['cs-donations-list'] = [
'parent' => 'cs-entries',
'id' => 'donations',
'label' => __('Donations', 'my-addon'),
'single' => __('Donation', 'my-addon'),
'type' => 'donation',
];
return $pages;
});

Filter · includes/post-types/class-entry.php

Provides the heading that is shown at the top of the edit screen of an entry whose type is not entry or payment. Those two types get “Entry details” and “Payment details”. If the title stays empty, no heading is shown.

Parameter Type Description
$title string The heading. Default: an empty string.
$entry Entry The entry that is shown.

Returns: string — the heading text (it is escaped when printed).

add_filter('cs_entry_detail_view_title', function ($title, $entry) {
return $entry->get_type() === 'donation' ? __('Donation details', 'my-addon') : $title;
}, 10, 2);

Action · includes/post-types/class-entry.php

Renders the content of the “Entry details” meta box in the sidebar of the entry edit screen. Echo your markup. It only runs when the entry can be loaded.

Parameter Type Description
$entry Entry The entry that is edited.
add_action('cs_entry_details_side_meta_box', function ($entry) {
printf('<p>%s</p>', esc_html($entry->get_status()));
});

Action · includes/post-types/class-entry.php

Renders the content of the “Entry notes” meta box in the sidebar of the entry edit screen. Echo your markup.

Parameter Type Description
$entry Entry The entry that is edited.
add_action('cs_entry_notes_meta_box', function ($entry) {
echo '<p>' . esc_html__('Notes are listed here.', 'my-addon') . '</p>';
});

Action · includes/post-types/class-entry.php

Renders the content of the main “Entry data” meta box on the entry edit screen. Echo your markup.

Parameter Type Description
$entry Entry The entry that is edited.
add_action('cs_entry_data_normal_meta_box', function ($entry) {
echo '<pre>' . esc_html(wp_json_encode($entry->get_meta_item('my_data'))) . '</pre>';
});

Action · includes/post-types/class-entry.php

Renders the content of the “Debug data” meta box on the entry edit screen. It only runs for entries with debug mode enabled. Other entries show a message that debug data is not available.

Parameter Type Description
$entry Entry The entry that is edited.
add_action('cs_entry_data_debug_meta_box', function ($entry) {
echo '<pre>' . esc_html(wp_json_encode($entry->get_meta_item('my_debug_data'))) . '</pre>';
});