Docs

Build a Custom IntegrationNew

5 min readUpdated November 24, 2026

Connect any plugin, form or signup flow to WP Smart Consent in about 30 lines of PHP. Your integration gets its own card with an Enable switch in the dashboard, its entries appear in the Customers Log under their own source, and every opt-in you send goes to all the CRMs, email platforms and webhooks the site owner has set up, with the same field mapping, lists and tags as the built-in integrations.

This guide builds a complete example plugin step by step. The full reference for every function and hook is in the Developer API.

Before you start#

  • WP Smart Consent 1.5.3 or newer, active.
  • A place in your code where you know the person’s email address and whether they agreed to marketing (your own checkbox, or a form that is an explicit newsletter signup).
  • Somewhere to put PHP: your own plugin (recommended) or a must-use plugin. Avoid the theme’s functions.php for anything you want to keep.
Warning

Only send consent => true when the person actively agreed to receive marketing. WP Smart Consent records exactly what you pass in, and that record is what you’ll rely on if you’re ever asked to prove consent.

What you’ll build#

A plugin called My Signups that:

  1. Adds a My Signups card to WP Smart Consent → Forms, with an Enable switch.
  2. Shows WP Smart Consent’s opt-in checkbox (same label and geo pre-check rules as everywhere else) on its own signup form.
  3. Sends every submission to WP Smart Consent: logged always, forwarded to CRMs only when the box was ticked.

Step 1: Create the plugin file#

Create wp-content/plugins/my-signups/my-signups.php:

my-signups.php
<?php
/**
 * Plugin Name: My Signups
 * Description: Sends signups to WP Smart Consent.
 * Version:     1.0.0
 */

defined( 'ABSPATH' ) || exit;

Step 2: Register the integration#

Registering adds the dashboard card and the Customers Log source filter entry. Add the filter at the top level of your plugin file, so it’s in place before WP Smart Consent builds its list of integrations (on init, priority 1):

my-signups.php
add_filter( 'wpsc_register_integrations', function ( array $integrations ) {
    $integrations[] = [
        'slug' => 'my-signups',      // lowercase letters, numbers, - and _
        'name' => 'My Signups',      // shown on the card and in the log filter
        'logo' => plugins_url( 'logo.png', __FILE__ ), // optional, square works best
    ];
    return $integrations;
} );
KeyRequiredNotes
slugYesUnique. Built-in slugs such as wpforms or mailchimp are refused. This is also the source shown in the log and sent to webhooks.
nameYesDisplay name.
logoNoAbsolute image URL.
groupNosources (default) or checkout.

Reload WP Smart Consent → Forms: a My Signups card appears at the end of the list, switched off. Registering doesn’t send anything by itself.

If your form needs a marketing checkbox, reuse WP Smart Consent’s label and pre-check rules so it matches the rest of the site:

my-signups.php
function my_signups_consent_checkbox(): string {
    if ( ! class_exists( '\WPSmartConsent\Helper\Utils' ) ) {
        return '';
    }
    $utils   = '\WPSmartConsent\Helper\Utils';
    $checked = $utils::get_prechecked_state() ? ' checked' : '';

    return '<label class="my-signups-optin">'
        . '<input type="checkbox" name="my_signups_optin" value="1" data-wpsc-optin="1"' . $checked . '> '
        . $utils::get_optin_label_html()
        . '</label>';
}
  • get_optin_label_html() returns the label from General → Label text, translated with WPML or Polylang and cleaned, so links such as your privacy policy work.
  • get_prechecked_state() applies Pre-checked by default and the Geo rules for the current visitor.
  • data-wpsc-optin="1" lets WP Smart Consent correct the starting state in the browser when the page is served from a cache. A box the visitor has already clicked is never changed.
  • Because the input sits directly inside the <label>, the checkbox picks up the Checkbox color and Checkbox text size settings automatically. See Checkbox Color and Text Size.

Step 4: Send each submission#

Call WP Smart Consent where your form is processed. Use the wpsc_forward_optin action (not the function) so your plugin keeps working if WP Smart Consent is deactivated, and check the card’s Enable switch first:

my-signups.php
add_action( 'my_signups_form_submitted', function ( array $data ) {

    // Respect the site owner's switch on the My Signups card.
    if ( ! class_exists( '\WPSmartConsent\Settings\Settings' )
        || ! \WPSmartConsent\Settings\Settings::get_integration_option( 'my-signups', 'enabled' ) ) {
        return;
    }

    do_action( 'wpsc_forward_optin', [
        'email'      => $data['email'],
        'first_name' => $data['first_name'] ?? '',
        'last_name'  => $data['last_name'] ?? '',
        'phone'      => $data['phone'] ?? '',
        'country'    => $data['country'] ?? '',        // two-letter code, e.g. "DE"
        'consent'    => ! empty( $_POST['my_signups_optin'] ),
        'source'     => 'my-signups',                 // same as your slug
        'extra'      => [ 'plan' => $data['plan'] ?? '' ],
    ] );
} );
my-signups.php
add_action( 'my_signups_form_submitted', function ( array $data ) {

    // Respect the site owner's switch on the My Signups card.
    if ( ! class_exists( '\WPSmartConsent\Settings\Settings' )
        || ! \WPSmartConsent\Settings\Settings::get_integration_option( 'my-signups', 'enabled' ) ) {
        return;
    }

    do_action( 'wpsc_forward_optin', [
        'email'      => $data['email'],
        'first_name' => $data['first_name'] ?? '',
        'last_name'  => $data['last_name'] ?? '',
        'phone'      => $data['phone'] ?? '',
        'country'    => $data['country'] ?? '',        // two-letter code, e.g. "DE"
        'consent'    => ! empty( $_POST['my_signups_optin'] ),
        'source'     => 'my-signups',                 // same as your slug
        'extra'      => [ 'plan' => $data['plan'] ?? '' ],
    ] );
} );

Replace my_signups_form_submitted with the hook or function where your plugin has validated a submission.

What happens next:

consentCustomers LogCRMs, email platforms, webhooks
trueLogged as Yes, signed by the Audit Trail (Beta)Sent to every enabled destination, with its field mapping, lists and tags
falseLogged as NoNothing is sent

An invalid or missing email does nothing (the function form returns false).

Step 5: Send extra data (optional)#

Anything in extra is stored with the log entry and added to the contact data under its key (lower-cased). To send it to a CRM, the site owner adds a row on that CRM’s Custom fields tab with the key as the Source key. Webhooks without a field map receive it automatically.

To send a contact to specific lists or tags in one CRM, regardless of the card’s settings, add crm_overrides:

'crm_overrides' => [
    'mailchimp' => [ 'list_ids' => [ 'abc123' ], 'tags' => [ 'my-signups' ] ],
    'fluent_crm' => [ 'list_ids' => [ '4' ] ],
],

The CRM slugs and which ones support lists or tags are listed in the Developer API under Forward an opt-in.

Step 6: Test it#

  1. Activate your plugin, open WP Smart Consent → Forms, switch on My Signups and save.
  2. Submit your form once with the box ticked and once without.
  3. Open WP Smart Consent → Logs and pick My Signups in the source filter. You should see both entries, one Yes and one No.
  4. Check your CRM for the ticked submission only.

If something doesn’t arrive, turn on debug logging and look at the PHP error log:

add_filter( 'wpsc_debug_log', '__return_true' );

The complete plugin#

my-signups.php
<?php
/**
 * Plugin Name: My Signups
 * Description: Sends signups to WP Smart Consent.
 * Version:     1.0.0
 */

defined( 'ABSPATH' ) || exit;

// 1. Dashboard card + log source.
add_filter( 'wpsc_register_integrations', function ( array $integrations ) {
    $integrations[] = [ 'slug' => 'my-signups', 'name' => 'My Signups' ];
    return $integrations;
} );

// 2. Consent checkbox markup for your form.
function my_signups_consent_checkbox(): string {
    if ( ! class_exists( '\WPSmartConsent\Helper\Utils' ) ) {
        return '';
    }
    $utils   = '\WPSmartConsent\Helper\Utils';
    $checked = $utils::get_prechecked_state() ? ' checked' : '';
    return '<label><input type="checkbox" name="my_signups_optin" value="1" data-wpsc-optin="1"'
        . $checked . '> ' . $utils::get_optin_label_html() . '</label>';
}

// 3. Send each validated submission.
add_action( 'my_signups_form_submitted', function ( array $data ) {
    if ( ! class_exists( '\WPSmartConsent\Settings\Settings' )
        || ! \WPSmartConsent\Settings\Settings::get_integration_option( 'my-signups', 'enabled' ) ) {
        return;
    }
    do_action( 'wpsc_forward_optin', [
        'email'      => $data['email'],
        'first_name' => $data['first_name'] ?? '',
        'consent'    => ! empty( $_POST['my_signups_optin'] ),
        'source'     => 'my-signups',
    ] );
} );
my-signups.php
<?php
/**
 * Plugin Name: My Signups
 * Description: Sends signups to WP Smart Consent.
 * Version:     1.0.0
 */

defined( 'ABSPATH' ) || exit;

// 1. Dashboard card + log source.
add_filter( 'wpsc_register_integrations', function ( array $integrations ) {
    $integrations[] = [ 'slug' => 'my-signups', 'name' => 'My Signups' ];
    return $integrations;
} );

// 2. Consent checkbox markup for your form.
function my_signups_consent_checkbox(): string {
    if ( ! class_exists( '\WPSmartConsent\Helper\Utils' ) ) {
        return '';
    }
    $utils   = '\WPSmartConsent\Helper\Utils';
    $checked = $utils::get_prechecked_state() ? ' checked' : '';
    return '<label><input type="checkbox" name="my_signups_optin" value="1" data-wpsc-optin="1"'
        . $checked . '> ' . $utils::get_optin_label_html() . '</label>';
}

// 3. Send each validated submission.
add_action( 'my_signups_form_submitted', function ( array $data ) {
    if ( ! class_exists( '\WPSmartConsent\Settings\Settings' )
        || ! \WPSmartConsent\Settings\Settings::get_integration_option( 'my-signups', 'enabled' ) ) {
        return;
    }
    do_action( 'wpsc_forward_optin', [
        'email'      => $data['email'],
        'first_name' => $data['first_name'] ?? '',
        'consent'    => ! empty( $_POST['my_signups_optin'] ),
        'source'     => 'my-signups',
    ] );
} );

Troubleshooting#

ProblemCause and fix
No card in FormsThe filter was added too late. Add wpsc_register_integrations at the top level of your plugin file (or on plugins_loaded), not inside an init callback. Also check the slug isn’t a built-in one.
Nothing in the logThe email was empty or invalid, or your code returned early because the card is switched off.
Logged but not in the CRMThe submission had consent => false, the CRM isn’t enabled, or a CRM that needs a list has none selected. Turn on wpsc_debug_log to see the reason.
Works on the live site but the box starts in the wrong state on cached pagesAdd data-wpsc-optin="1" to your checkbox.
Site breaks when WP Smart Consent is deactivatedUse do_action( 'wpsc_forward_optin', … ) and the class_exists() checks shown above, not direct function calls.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only