Filters

Wordpress filters are built in at various places in the CampaignSuite code. These make it possible as a developer in the theme to influence the data that is currently used by CampaignSuite. All filters are best placed in the functions.php of your theme. Click on the articles below to view the different filters.

cs_validate_contact_account

Description

This filter allows you to manipulate the contact and account array when this data is created just before a form is validated.

Use

				
					add_filter( 'cs_validate_contact_account', 'custom_contact_account' );

//You can also use a Gravity Forms form ID to target a specific form
add_filter( 'cs_validate_contact_account_6', 'custom_contact_account' );				
			

Parameters

  • $contact_account ( array )
    This array passes the displayed contact and account arrays. This value must be returned in the filter function.
  • $payer ( object )
    This is the full object of the CampaignSuite Payer class. This object contains various additional information about the payer.

Example

				
					add_filter('cs_validate_contact_account', 'validate_contact_account', 10, 2);
function validate_contact_account($contact_account, $payer)
{
    [$contact, $account] = $contact_account;
    if (isset($contact['Phone']) && !empty($contact['Phone'])) {
        if (isMobile($contact['Phone'])) {
            $contact['MobilePhone'] = $contact['Phone'];
            unset($contact['Phone']);
        }
    }
    
    if ($payer->accountRecordType != 'Household') {
        $contact['soco__Assign_Donations_to_Parent_Account__c'] = true;
    } else {
        $contact['soco__Assign_Donations_to_Parent_Account__c'] = false;
    }
    
    return [$contact, $account];
}				
			

cs_post_submit

Description

This filter allows you to take actions after a successful submission to the Campaign Suite API.

Use

				
					add_filter('cs_post_submit', 'post_submit', 10, 1);				
			

Parameters

  • $response ( object ) < / div>

    This is the complete CampaignSuite\CampaignSuite\Render_response() class object. This object contains information about the response returned by the CS API.

Example

The example below writes a $_SESSION[‘orig_campaign’] value to the Salesforce Contact object.

				
					function post_submit($response)
{
  if (isset($_SESSION['orig_campaign'])) {
        $sf_client = instance('Client_Salesforce');
        $sf_client->update(
            'Contact',
            $_SESSION['orig_campaign']['contact_id'],
            [
                'soco__Originating_Campaign__c' => $_SESSION['orig_campaign']['campaign_id']
            ]
        );
        unset($_SESSION['orig_campaign']);
    }
    return $response;
}				
			

cs_get_feed_actions

Description

This filter allows you to add custom feed actions to Gravity Forms.

Use

				
					add_filter('cs_get_feed_actions', 'get_feed_actions', 10, 1);				
			

Parameters

  • $actions (array)
    This is an array of the available actions. You can add more elements to this array for custom actions.

Example

				
					function get_feed_actions($actions)
{
  $extraActions = [[
    'label' => 'Maak een nieuwe Lead aan',
    'value' => 'custom_lead',
    'object' => 'Lead',
    'objectName' => 'Lead'
  ]];
  return array_merge($actions, $extraActions);
}				
			

cs_get_contact_filter_fields

Description

With this filter, you can add more Salesforce contact fields to monitor when a contact ID is passed in the URL. By default, a contact is only found based on a contact ID. For more security it is possible to add more fields to this check.

Use

				
					add_filter('cs_get_contact_filter_fields', 'get_contact_filter_fields', 10, 1);
				
			

Parameters

None

Example

The example below adds the Contact.Email field as an extra check in the URL.

				
					function cs_get_contact_filter_fields(){
    return ['Email'];
}				
			

cs_add_custom_json

Description

With this filter you can add your own custom JSON to the API call to Findock or Converse. This JSON will be added to the root of the JSON object.

Use

				
					add_filter('cs_add_custom_json', 'custom_json', 10);				
			

Example

The example below loops through Woocommerce items in a shopping cart and checks whether Destination IDs have been set. If so, these will be passed in the JSON call to the CampaignSuite API.

				
					function custom_json()
{
    global $woocommerce;
    if ($woocommerce) {
        $items = $woocommerce->cart->get_cart();
        if ($items) {
            $jsonItems = [];
            foreach ($items as $values) {
                $price = get_post_meta($values['product_id'], '_price',true);
                $destination_id = get_post_meta($values['product_id'], '_sf_destination_id', true);
                if ($destination_id) {
                    $jsonItems[] = [
                        'DestinationId' => $destination_id,
                        'Amount' => $price
                    ];
                }
            }
            if ($jsonItems) {
                return [
                    'TransactionInfo' => [
                        'Gifts' => $jsonItems
                    ]
                ];
            }
        }
    }
    return [];
}				
			

Actions

cs_post_webhook_action

Description

With this action you can catch the webhook call yourself so that you can determine in your own action whether additional code needs to be executed as soon as a webhook call takes place from Salesforce/Findock

Use

				
					function do_custom_stuf( $payment ) {
    die(print_r($payment));
}
add_action( 'cs_post_webhook_action', 'do_custom_stuff', 10, 1 );				
			

Parameters

  • $payment (object)
    This object contains all information about the modified Payment object from the database table wp_gp_donations.

URL parameters

You can add various parameters in the URL of your website to activate debugging options of CampaignSuite. This makes it possible, for example, to debug the call to the CampaignSuite API or Converse and Findock.

Possible parameters are:

?cs_debug

				
					https://www.website.nl/formulier?cs_debug=true				
			
When this parameter is added, a form is automatically loaded without ajax. When the form is completed, you will see the JSON sent to the CampaignSuite API. It also shows you the JSON sent from the API to Salesforce. All this before Gravity Forms actually makes the input.

?cs_post=true

				
					https://www.website.nl/formulier?cs_post=true				
			
When this parameter is added, each page will show you the posted values. This can be useful if you want to know the exact field names posted. These names can be used in text area and HTML fields to prefill with those field values.

?cs_ajax

				
					https://www.website.nl/formulier?cs_ajax=false				
			

Use this parameter to overrule a Gravity Forms Ajax setting with true or false.

?contact=0030E00000dRyVKQA0

				
					https://www.website.nl/formulier?contact=0030E00000dRyVKQA0				
			
The ID passed in this parameter must be a Salesforce contact ID. If the contact is found in Salesforce, all assigned contact and account fields are pre-populated with the Salesforce values.

Client connections

As a developer you have the disposal to use the authorized connections in your own theme. There are a number of predefined functions that you can use per connection. Always start each connection in the following way first:

				
					//Salesforce connection
$salesforce = instance('Client_Salesforce');

//Mautic connection
$mautic = instance('Client_Mautic');

//Pardot connection
$pardot = instance('Client_Pardot');

//Dynamics connection
$dynamics = instance('Client_Dynamics');
				
			

View the articles below to see the available function per connection.

Salesforce

getObjects

This function can be used to get a list of objects from SalesForce or a single one when an ID is passed.

				
					/**
    * @param string $objectType Name of the Salesforce object
    * @param string $id Optional Salesforce ID of the object
    * @param array $fields Optional array with fields to return from the object
    * @param array $where Optional array with filters
*/
function getObjects($objectType = '', $id = '', $fields = [], $where = []){}				
			

getObjectStructure

This function can be used to get the structure of a Salesforce object.
				
					/**
   * @param string $objectType The name of the Salesforce object
   * @return object $response The API response
   *
   */
  function getObjectStructure($objectType = ''){}				
			

createCampaignMember

This function makes a Post request to the API for a new CampaignMember object in Salesforce.

				
					/**
   * @param string $campaign_id Id of the Campaign
   * @param string $contact_id Id of the Contact
   * @return mixed
   */
  function createCampaignMember($campaign_id, $contact_id){}				
			

create

Function to create a new record of an object in Salesforce.
				
					/**
 * @param string $object Name of the Salesforce object
 * @param array $data Data to save
 */
function create($object, $data){}				
			

update

Function to update a record of an object in Salesforce.
				
					/**
   * @param string $object Name of the Salesforce object
   * @param string $id Id of the Salesforce object
   * @param array $data Data to save
   */
  function update($object, $id, $data){}				
			

delete

Function to delete a record from an object in Salesforce.
				
					/**
   * @param string $object Name of the Salesforce object
   * @param string $id Id of the object to delete
   */
  function delete($object, $id){}				
			

Mautic

getForms

Function to retrieve all Mautic forms. When $id is passed, only one form is returned.
				
					/**
   * Function to retrieve all Mautic forms. When $id is passed, only one form is returned
   *
   * @param $id int Id of a Mautic form
   * @return array $forms Returns an array of Mautic forms
   */
  public function getForms($id = ''){}				
			

createForm

This function will create a new Mautic form from a Gravity Forms form and its fields.
				
					/**
   * @param $type string Type can be Campaign or Standalone
   * @param $form array The gravity Forms form as an array
   */
  public function createForm($type, $form){}				
			

postFormEntry

This function sends a wp_remote_post () request directly to Mautic. This is necessary because Mautic needs the visitor’s IP address to identify the contact.
				
					/**
   * @param $form_id int Id of the Mautic form
   * @param $data array Array of the data to post to the form
   */
  public function postFormEntry($form_id, $data){}				
			

updateEntry

This feature updates a Mautic form submission based on certain conditions.
				
					/**
   * @param int $mautic_form_id The Mautic form ID
   * @param array $where Array of conditions
   * @param array $updates Array of fields to update
   */
  function updateEntry($mautic_form_id, $where, $updates){}				
			

Endpoints

When CampaignSuite is activated, a number of new endpoints will be added within Wordpress. These endpoints can be accessed by third party software. These endpoints are explained below with the associated parameters.

gp_webhook_path

This endpoint can be accessed by Findock and handles all webhook calls related to changes to a payment (or in the case of Findock 2 changes in the PaymentIntent). CampaignSuite automatically determines whether it is for Findock v1 or v2 based on the content of the call. With every API call to Findock, CampaignSuite automatically adds this URL as WebhookURL. Example
				
					{root_url}/wp-json/campaignsuite/v1/gp_webhook_path				
			

update_mautic_integration

This endpoint can be used to remove a Mautic Lead Integration. This endpoint can only be accessed with a POST request with the following parameters:

Parameter Description
email
The email address of a Mautic lead
entityId
The Mautic entity to delete
entityId
The Salesforce entity ID (eg, Campaign ID)
Example
				
					{root_url}wp-json/campaignsuite/v1/update_mautic_integration				
			

update_lead_field

This endpoint can be used to remove a Mautic Lead Integration. This endpoint can only be accessed with a POST request with the following parameters:

Parameter Description
email
The email address of a Mautic lead
field
The Mautic field alias to update
value
The new value to save
action
Choose from 'add' or 'remove' here

Example

				
					{root_url}wp-json/campaignsuite/v1/update_lead_field				
			

One-click-payment

One-click payment is a way to make a direct donation via a URL where the visitor is redirected to his / her bank page in one go. The advantage of this is that the complete flow is identical to filling in a donation form, but without going through the page containing the form. In order for One-Click-Payment to work, you must at least meet the following points:
  1. A form must be created which is fully linked to a Salesforce payment
  2. The form must be on a page (hidden if necessary) in case the donor terminates his / her donation.
  3. A thank you message or thank you page must be set up for successful donor capture.
  4. The fields of the form you want to fill must be set to be filled dynamically. Read more information about this at this website .
If the above points are set, the URL for a One-Click-Payment can look like this:
				
					https://www.website.nl/oneclick?amount=5&form_id=1&email=donateur@website.nl&bank=INGBNL2A&firstname=Voornaam&lastname=achternaam				
			
There are a number of mandatory parameters in the URL:
  • amount Enter the amount for the donation here
  • form_id Enter the ID of the Gravity Forms form where the payment should be handled here
  • contact (optional) Enter an ID of a Salesforce Contact
  • here
If you do not include a Salesforce Contact ID in the URL, a first name, last name, and email address are also required to include in the URL. As soon as you click on the link, the form will be pre-filled with the required values and sent via the API. If fields are missing or errors occur, they will be displayed immediately.