Settings and admin hooks
CampaignSuite Core builds all its admin screens from a registry of settings pages. A page is identified by its slug, for example cs-general, cs-analytics, cs-debug, cs-salesforce or cs-mautic, and every slug is also the name of the option that stores the page’s values. With the hooks below an add-on can register its own page, adjust the fields of an existing page, validate what is saved, and add content, notices and diagnostics around the pages.
Settings registry
Section titled “Settings registry”A settings field is an array keyed by its field key (conventionally upper case, for example MEASUREMENT_ID). Common options are title, type (header, separator, text, toggle, hidden, and others), description, placeholder, default_value, class, dependency (['field' => 'OTHER_KEY', 'value' => 'checked']) and pre_save_callback.
cs_settings
Section titled “cs_settings”Filter · includes/class-settings.php
Filters the settings fields of all CampaignSuite pages. This is the main way to register a settings page: add an entry keyed by your page slug. It runs every time the fields are requested and starts from an empty array. Core and the built-in clients add their pages through it too.
| Parameter | Type | Description |
|---|---|---|
$settings |
array |
The settings fields per page, keyed by page slug. Each value is an array of fields keyed by field key. |
Returns: array — the settings, including your page.
add_filter('cs_settings', function ($settings) { $settings['cs-my-addon'] = [ 'MY_HEADER' => [ 'title' => __('My add-on', 'my-addon'), 'type' => 'header', 'class' => 'compact', ], 'MY_OPTION' => [ 'title' => __('My option', 'my-addon'), 'type' => 'text', 'description' => __('Shown below the field.', 'my-addon'), ], ];
return $settings;});To show the page in the menu, also add it with cs_submenu_pages.
cs_general_settings
Section titled “cs_general_settings”Filter · includes/class-settings.php
Filters the fields of the general settings page (cs-general) after Core has built them.
| Parameter | Type | Description |
|---|---|---|
$fields |
array |
The fields of the general page, keyed by field key. |
Returns: array — the fields.
add_filter('cs_general_settings', function ($fields) { $fields['MY_GENERAL_OPTION'] = [ 'title' => __('My general option', 'my-addon'), 'type' => 'text', ];
return $fields;});cs_analytics_settings
Section titled “cs_analytics_settings”Filter · includes/class-settings.php
Filters the fields of the analytics settings page (cs-analytics). The page, and with it this filter, only exists when the connected key includes analytics access. By default the page has a MEASUREMENT_ID field.
| Parameter | Type | Description |
|---|---|---|
$fields |
array |
The fields of the analytics page, keyed by field key. |
Returns: array — the fields.
add_filter('cs_analytics_settings', function ($fields) { $fields['MY_PIXEL_ID'] = [ 'title' => __('Pixel ID', 'my-addon'), 'type' => 'text', ];
return $fields;});cs_debug_settings
Section titled “cs_debug_settings”Filter · includes/class-settings.php
Filters the fields of the debug settings page (cs-debug). By default the page has the toggles SHOW_DEBUG_SETTINGS, BYPASS_ACTION_SCHEDULER and ALWAYS_ENABLE_DEBUG_FOR_ENTRIES, and the last two only show when the first is on.
| Parameter | Type | Description |
|---|---|---|
$fields |
array |
The fields of the debug page, keyed by field key. |
Returns: array — the fields.
add_filter('cs_debug_settings', function ($fields) { $fields['MY_VERBOSE_LOGGING'] = [ 'title' => __('Verbose logging', 'my-addon'), 'type' => 'toggle', 'label' => __('Verbose logging', 'my-addon'), 'dependency' => [ 'field' => 'SHOW_DEBUG_SETTINGS', 'value' => 'checked', ], ];
return $fields;});cs_settings_validations
Section titled “cs_settings_validations”Filter · includes/class-settings.php
Filters the validation rules that run when a settings page is saved. Rules are keyed by field key, and each key holds a list of checks. If any check fails, the whole page keeps its previous values and an error notice lists the messages. There are two check types:
not_inrejects a value that is invalues.callbackrejects a value unless the callback returnstrue. A returnedWP_Errorsupplies the error message.
Each check can have an error_message. The default is “Invalid value”.
| Parameter | Type | Description |
|---|---|---|
$validations |
array |
The rules, keyed by field key. Default: an empty array. |
Returns: array — the rules, keyed by field key.
add_filter('cs_settings_validations', function ($validations) { $validations['MY_OPTION'] = [ [ 'type' => 'not_in', 'values' => ['', 'admin'], 'error_message' => __('Choose another value.', 'my-addon'), ], [ 'type' => 'callback', 'callback' => function ($value) { return strlen($value) <= 20 ?: new WP_Error('too_long', __('Maximum 20 characters.', 'my-addon')); }, ], ];
return $validations;});cs_set_setting_field_value
Section titled “cs_set_setting_field_value”Filter · includes/class-settings.php
Filters the complete set of values of a settings page right before it is stored, after the built-in normalization and validation. It runs for every CampaignSuite settings page.
| Parameter | Type | Description |
|---|---|---|
$value |
array |
The values to save, keyed by field key. When validation failed this is the previous value. |
Returns: array — the values to save.
add_filter('cs_set_setting_field_value', function ($value) { if (isset($value['MY_OPTION'])) { $value['MY_OPTION'] = strtolower($value['MY_OPTION']); }
return $value;});cs_{page}_page_settings
Section titled “cs_{page}_page_settings”Filter · admin/class-admin.php
Filters the settings fields definition of one specific admin page while the page is rendered. The dynamic part {page} is the page slug, for example cs_cs-general_page_settings for the general page. Known values: cs-general, cs-analytics, cs-debug, cs-salesforce, cs-mautic, plus any page slug you add with cs_settings and cs_submenu_pages.
Unlike cs_settings, this filter gets the render definition, an array keyed by the page slug whose values hold the page, section and the fields to render. It is mostly useful for rendering fields that the settings registry doesn’t store.
| Parameter | Type | Description |
|---|---|---|
$setting_fields |
array |
The render definition, keyed by option name. Each item has page (cs-settings), section (cs_settings_section) and fields. |
Returns: array — the render definition.
add_filter('cs_cs-debug_page_settings', function ($setting_fields) { if (isset($setting_fields['cs-debug'])) { unset($setting_fields['cs-debug']['fields']['MY_VERBOSE_LOGGING']); }
return $setting_fields;});cs_current_page_settings
Section titled “cs_current_page_settings”Filter · admin/class-admin.php
The same as cs_{page}_page_settings, but for every page, with the current page slug as an extra argument. It runs after the page specific filter.
| Parameter | Type | Description |
|---|---|---|
$setting_fields |
array |
The render definition, keyed by option name. |
$current_page |
string |
The slug of the page that is rendered. |
Returns: array — the render definition.
add_filter('cs_current_page_settings', function ($setting_fields, $current_page) { if ($current_page === 'cs-general') { // Adjust the general page only. }
return $setting_fields;}, 10, 2);Admin menu and pages
Section titled “Admin menu and pages”cs_submenu_pages
Section titled “cs_submenu_pages”Filter · admin/class-admin.php
Filters the sub pages of the CampaignSuite admin menu. Add your page here, keyed by its slug, to show it in the menu on the left of the settings screen. The cs-debug page is always added after this filter, so you can’t remove it.
Each page supports these options:
| Option | Type | Description |
|---|---|---|
title |
string |
The menu label. |
has_permission |
bool |
Whether the page is shown. |
type |
string |
The group, used for the ordering: see cs_submenu_pages_priority. |
path |
string |
Optional absolute path to a PHP template that is included on the page. |
template_position |
string |
top (default) or bottom: include the template above or below the settings form. |
show_form |
bool |
Optional. Set to false to hide the settings form. Default true. |
capability |
string |
Optional capability needed for the page. Defaults to the settings capability. |
| Parameter | Type | Description |
|---|---|---|
$sub_pages |
array |
The sub pages keyed by page slug. By default it holds cs-analytics, which is only visible when the key has analytics access. |
Returns: array — the sub pages keyed by page slug.
add_filter('cs_submenu_pages', function ($sub_pages) { $sub_pages['cs-my-addon'] = [ 'title' => __('My add-on', 'my-addon'), 'has_permission' => true, 'type' => 'addon', ];
return $sub_pages;});cs_submenu_pages_priority
Section titled “cs_submenu_pages_priority”Filter · admin/class-admin.php
Filters the order of the sub page groups. Sub pages are sorted by the priority of their type, lowest number first.
| Parameter | Type | Description |
|---|---|---|
$priorities |
array<string, int> |
The priority per type. Default: crm 1, marketing-automation 2, addon 3, other 998, debug 999. |
Returns: array<string, int> — the priority per type.
add_filter('cs_submenu_pages_priority', function ($priorities) { $priorities['payments'] = 2;
return $priorities;});cs_settings_page_capability
Section titled “cs_settings_page_capability”Filter · admin/class-admin.php
Filters the capability required to open the CampaignSuite settings pages and run their admin actions. It also decides who sees the CampaignSuite admin notices.
| Parameter | Type | Description |
|---|---|---|
$capability |
string |
The capability. Default: manage_options. |
Returns: string — the capability.
add_filter('cs_settings_page_capability', function ($capability) { return 'manage_network_options';});cs_settings_page_pre_{page_id}
Section titled “cs_settings_page_pre_{page_id}”Action · admin/templates/admin-display.php
Fires on a settings page before the page content is rendered, below the page’s error messages. The dynamic part {page_id} is the slug of the current page, for example cs_settings_page_pre_cs-general. The action has no parameters. Use it to print a notice or intro for a single page.
add_action('cs_settings_page_pre_cs-my-addon', function () { echo '<p>' . esc_html__('Configure the add-on below.', 'my-addon') . '</p>';});cs_settings_page_pre
Section titled “cs_settings_page_pre”Action · admin/templates/admin-display.php
Fires on every settings page before the page content is rendered. It runs after cs_settings_page_pre_{page_id}.
| Parameter | Type | Description |
|---|---|---|
$page_id |
string |
The slug of the current page. |
add_action('cs_settings_page_pre', function ($page_id) { if ($page_id === 'cs-general') { echo '<p>' . esc_html__('Need help? Contact support.', 'my-addon') . '</p>'; }});cs_settings_page_post_{page_id}
Section titled “cs_settings_page_post_{page_id}”Action · admin/templates/admin-display.php
Fires on a settings page after the page content, including the form and any template, is rendered. The dynamic part {page_id} is the slug of the current page, for example cs_settings_page_post_cs-general. The action has no parameters. Core uses it on the general page to show the license block.
add_action('cs_settings_page_post_cs-my-addon', function () { echo '<p>' . esc_html__('Add-on version 1.0', 'my-addon') . '</p>';});cs_settings_page_post
Section titled “cs_settings_page_post”Action · admin/templates/admin-display.php
Fires on every settings page after the page content is rendered. It runs after cs_settings_page_post_{page_id}.
| Parameter | Type | Description |
|---|---|---|
$page_id |
string |
The slug of the current page. |
add_action('cs_settings_page_post', function ($page_id) { if ($page_id === 'cs-debug') { echo '<p>' . esc_html__('Debug output is stored for 14 days.', 'my-addon') . '</p>'; }});Notices and diagnostics
Section titled “Notices and diagnostics”cs_admin_notice_{message}
Section titled “cs_admin_notice_{message}”Filter · admin/class-admin.php
Provides the notice for a CampaignSuite admin message. A CampaignSuite page shows a notice when the URL has a cs-message query argument. The dynamic part {message} is that value, lower-cased and sanitized with sanitize_key(). The messages cache-cleared and entries-protected are built in and do not run this filter. Core registers the connection messages of its clients, for example sf-connection-setup, sf-connection-removed, mtc-connection-setup and mtc-connection-removed. Only users with the settings capability see the notice. The text may contain safe HTML (wp_kses_post()).
| Parameter | Type | Description |
|---|---|---|
$info |
array |
The notice, with type (success, info, warning or error; anything else becomes info), text and dismissible. Default: ['type' => '', 'text' => '', 'dismissible' => true]. An empty text shows no notice. |
Returns: array — the notice with type, text and dismissible.
// Shown after redirecting to admin.php?page=cs-general&cs-message=my-addon-savedadd_filter('cs_admin_notice_my-addon-saved', function ($info) { return [ 'type' => 'success', 'text' => __('My add-on settings were saved.', 'my-addon'), 'dismissible' => true, ];});cs_debug_information
Section titled “cs_debug_information”Filter · admin/class-admin.php
Filters the fields of the “CampaignSuite” section in Site Health, under Tools, Site Health, Info. Add your own diagnostics here, for example the version of your add-on.
| Parameter | Type | Description |
|---|---|---|
$fields |
array |
The fields keyed by an ID such as core/version. Each field has label, value and private, and optionally debug, as in the WordPress debug_information filter. |
Returns: array — the fields.
add_filter('cs_debug_information', function ($fields) { $fields['my-addon/version'] = [ 'label' => __('My add-on version', 'my-addon'), 'value' => MY_ADDON_VERSION, 'private' => false, ];
return $fields;});cs_debug_hidden_cookie_patterns
Section titled “cs_debug_hidden_cookie_patterns”Filter · admin/templates/partials/debug.php
Filters the cookie name patterns whose values are hidden on the CampaignSuite debug page, so they don’t end up in what you share with support.
| Parameter | Type | Description |
|---|---|---|
$patterns |
string[] |
Regular expressions that are matched against the cookie name. Default: /^wordpress_/, /^PHPSESSID$/ and /session|token|auth|pass|secret/i. |
Returns: string[] — the regular expressions.
add_filter('cs_debug_hidden_cookie_patterns', function ($patterns) { $patterns[] = '/^my_addon_/';
return $patterns;});Connection popup
Section titled “Connection popup”Connectable services (such as Salesforce and Mautic) are connected in a popup window of the CampaignSuite admin. These hooks let an add-on provide a popup for its own connection type. In every hook name, {type} is the connection type (the popup’s type query argument). The built-in values are salesforce and mautic.
cs_authentication_title_{type}
Section titled “cs_authentication_title_{type}”Filter · admin/templates/authentication-display.php
Provides the name that is shown in the title of the connection popup (“Authentication for …”).
| Parameter | Type | Description |
|---|---|---|
$title |
string |
The name of the service. Default: an empty string. |
Returns: string — the name of the service.
add_filter('cs_authentication_title_my-service', function ($title) { return 'My Service';});cs_authentication_fields_{type}
Section titled “cs_authentication_fields_{type}”Filter · admin/templates/authentication-display.php
Provides the form fields of the connection popup. Each field is keyed by its input name and supports title, type (text, password, url or select), placeholder, description, required, value and, for select, options (value => label).
| Parameter | Type | Description |
|---|---|---|
$fields |
array |
The fields keyed by input name. Default: an empty array. |
Returns: array — the fields keyed by input name.
add_filter('cs_authentication_fields_my-service', function ($fields) { $fields['account'] = [ 'title' => __('Account', 'my-addon'), 'type' => 'text', 'required' => true, ];
return $fields;});cs_authentication_error_{type}
Section titled “cs_authentication_error_{type}”Filter · admin/templates/authentication-display.php
Provides an error message that is shown at the top of the connection popup form, for example after a failed attempt. Add the filter during the cs_authentication_authenticate_{type} action to show the error in the same request. The message may contain safe HTML (wp_kses_post()).
| Parameter | Type | Description |
|---|---|---|
$error |
string |
The error message. Default: an empty string, which shows no error. |
Returns: string — the error message.
add_action('cs_authentication_authenticate_my-service', function ($request) { add_filter('cs_authentication_error_my-service', function ($error) { return esc_html__('The account could not be found.', 'my-addon'); });});cs_authentication_authenticate_{type}
Section titled “cs_authentication_authenticate_{type}”Action · admin/class-admin.php
Fires when the connection popup form is submitted with a valid nonce. Handle the submitted values here. If no callback is registered for the type, the request is refused with an error.
| Parameter | Type | Description |
|---|---|---|
$request |
array |
The submitted form, unslashed $_POST. |
add_action('cs_authentication_authenticate_my-service', function ($request) { $account = sanitize_text_field($request['account'] ?? ''); // Start the connection for $account.});cs_store_connection_{type}
Section titled “cs_store_connection_{type}”Action · admin/templates/authentication-display.php
Fires in the connection popup when a user returns from the external flow with a connection ID that belongs to a flow the current user started. Store the connection here and print the result, which then shows in the popup.
| Parameter | Type | Description |
|---|---|---|
$id |
string |
The connection ID. |
add_action('cs_store_connection_my-service', function ($id) { update_option('my_service_connection', sanitize_text_field($id)); echo '<h1>' . esc_html__('Connected', 'my-addon') . '</h1>';});cs_preload_connection_details
Section titled “cs_preload_connection_details”Action · admin/class-admin.php
Fires in the admin at most once a day per site, so connected services can refresh their connection details. It does not fire during AJAX requests. The action has no parameters.
add_action('cs_preload_connection_details', function () { // Refresh and cache the details of your connection.});Deprecated hooks
Section titled “Deprecated hooks”These actions still fire so existing code keeps working, but they log a deprecation notice. They will be removed in CampaignSuite 3.1.0, so switch to the replacements before then.
custom_cs_setting_pre
Section titled “custom_cs_setting_pre”Action · admin/templates/admin-display.php
Deprecated, and will be removed in 3.1.0. Use cs_settings_page_pre instead. Fires before the settings page content is rendered.
| Parameter | Type | Description |
|---|---|---|
$page_id |
string |
The slug of the current page. |
add_action('custom_cs_setting_pre', function ($page_id) { // Deprecated: use cs_settings_page_pre.});custom_cs_setting
Section titled “custom_cs_setting”Action · admin/templates/admin-display.php
Deprecated, and will be removed in 3.1.0. Use cs_settings_page_post instead. Fires after the settings page content is rendered.
| Parameter | Type | Description |
|---|---|---|
$page_id |
string |
The slug of the current page. |
add_action('custom_cs_setting', function ($page_id) { // Deprecated: use cs_settings_page_post.});custom_cs_setting_post
Section titled “custom_cs_setting_post”Action · admin/templates/admin-display.php
Deprecated, and will be removed in 3.1.0. Use cs_settings_page_post instead. Fires after the settings page content is rendered, right after custom_cs_setting.
| Parameter | Type | Description |
|---|---|---|
$page_id |
string |
The slug of the current page. |
add_action('custom_cs_setting_post', function ($page_id) { // Deprecated: use cs_settings_page_post.});