General hooks
Deze inhoud is nog niet vertaald.
These hooks cover the plugin as a whole: the moment CampaignSuite Core has finished loading, how the plugin works out the visitor’s IP address, and the limits of the public address lookup (the Address NL autocomplete).
cs_init
Section titled “cs_init”Action · includes/class-campaignsuite.php
Fires at the end of CampaignSuite Core’s own callback on the WordPress init action, after the admin hooks and the built-in clients have been set up and, when the plugin is activated, the entry post type and its hooks are registered. It fires even when the plugin is not activated. Use it to register your own CampaignSuite integrations, such as filters for entry types, clients or settings, once Core is ready.
This action has no parameters.
add_action('cs_init', function () { add_filter('cs_entry_capability', function () { return 'manage_options'; });});cs_ip_headers
Section titled “cs_ip_headers”Filter · includes/class-campaignsuite.php
Filters the list of $_SERVER keys that CampaignSuite::get_ip() reads to find the visitor’s IP address. The first key with a value wins, and if that value is a comma-separated list, the first IP is used. The IP is used for the address lookup rate limit and in connection log lines, among other things.
| Parameter | Type | Description |
|---|---|---|
$headers |
string[] |
The $_SERVER keys to check, in order. Default: ['HTTP_CF_CONNECTING_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR']. |
Returns: string[] — the $_SERVER keys to check, in order of preference.
add_filter('cs_ip_headers', function ($headers) { // Behind a load balancer that sets a trusted header: only trust that one. return ['HTTP_X_REAL_IP', 'REMOTE_ADDR'];});cs_address_check_country
Section titled “cs_address_check_country”Filter · includes/class-services.php
Filters the country that is used for an address lookup, before the lookup runs. The lookup only supports the countries the service can resolve. An address with an unsupported country, or a malformed zipcode or house number, is not looked up at all.
| Parameter | Type | Description |
|---|---|---|
$country |
string |
The country from the address, or an empty string when the address has none. |
$address |
array |
The address parts, for example country, zipcode, number and addition. |
Returns: string — the country to use for the lookup.
add_filter('cs_address_check_country', function ($country, $address) { // Assume the Netherlands when the form has no country field. return $country === '' ? 'NL' : $country;}, 10, 2);cs_address_rate_limit
Section titled “cs_address_rate_limit”Filter · includes/class-services.php
Filters the rate limit of public address lookups per visitor. Only lookups that are actually sent to the address service count, not cached lookups or lookups rejected locally. The visitor is identified by their IP address (see cs_ip_headers). A visitor over the limit gets a result with rate_limited and retry_after instead of an address.
| Parameter | Type | Description |
|---|---|---|
$rate_limit |
array |
limit is the number of lookups per window (0 for no limit) and window is the window length in seconds. Default: ['limit' => 60, 'window' => 300] (60 lookups per 5 minutes). |
Returns: array — the same structure, with limit and window.
add_filter('cs_address_rate_limit', function ($rate_limit) { return [ 'limit' => 120, 'window' => HOUR_IN_SECONDS, ];});