1. Home
  2. Knowledge Base
  3. Document Library Pro
  4. Developer Documentation

Lead capture developer guide

Document Library Pro provides action hooks and filters that allow developers to send lead capture data to external systems such as CRMs, email marketing platforms, or automation tools.

These instructions are aimed at developers and if you don't know how to use them then please ask a developer or request a quote from our Services team.

Main action hook

Use the following action hook to receive the submitted lead data:

add_action( 'dlp_lead_capture_submitted', function( $lead_data ) {

    // Do something with the lead capture data.

});

$lead_data structure

[
  "documents" => [
    0 => [
      "id" => 8950,
      "title" => "My Document",
      "url" => "http://mywebsite/document/my-document/"
    ],
  ],
  "first_name" => "John",
  "last_name" => "Dow",
  "email" => "[email protected]",
  "privacy_consent" => "Yes",
]

Example: Send to ActiveCampaign via WP Fusion

add_action( 'dlp_lead_capture_submitted', 'my_wpf_ac_lead_capture', 10, 1 );

function my_wpf_ac_lead_capture( $lead_data ) {

    if ( ! function_exists( 'wp_fusion' ) ) {
        return;
    }

    $email = sanitize_email( $lead_data['email'] );

    if ( empty( $email ) ) {
        return;
    }

    $contact_data = array(
        'email'           => $email,
        'first_name'      => sanitize_text_field( $lead_data['first_name'] ),
        'last_name'       => sanitize_text_field( $lead_data['last_name'] ),
        'privacy_consent' => sanitize_text_field( $lead_data['privacy_consent'] ),
    );

    $tags = array( 'Document Download' );

    if ( ! empty( $lead_data['documents'] ) ) {

        $doc_titles = array();
        $doc_urls   = array();

        foreach ( $lead_data['documents'] as $doc ) {

            $title = sanitize_text_field( $doc['title'] );
            $url   = esc_url_raw( $doc['url'] );

            $doc_titles[] = $title;
            $doc_urls[]   = $url;

            $tags[] = 'Downloaded: ' . $title;
        }

        $contact_data['downloaded_documents']     = implode( ', ', $doc_titles );
        $contact_data['downloaded_document_urls'] = implode( ', ', $doc_urls );
    }

    $contact_id = wp_fusion()->crm->add_contact( $contact_data );

    if ( ! empty( $contact_id ) && ! empty( $tags ) ) {
        wp_fusion()->crm->apply_tags( $tags, $contact_id );
    }
}

Example: Trigger Uncanny Automator

add_action( 'dlp_lead_capture_submitted', 'my_dlp_prepare_for_automator', 10, 1 );

function my_dlp_prepare_for_automator( $lead_data ) {

    if ( empty( $lead_data['email'] ) ) {
        return;
    }

    $email      = sanitize_email( $lead_data['email'] );
    $first_name = sanitize_text_field( $lead_data['first_name'] ?? '' );
    $last_name  = sanitize_text_field( $lead_data['last_name'] ?? '' );
    $consent    = sanitize_text_field( $lead_data['privacy_consent'] ?? '' );

    $doc_titles = array();
    $doc_urls   = array();
    $doc_ids    = array();

    if ( ! empty( $lead_data['documents'] ) ) {
        foreach ( $lead_data['documents'] as $doc ) {
            $doc_titles[] = sanitize_text_field( $doc['title'] );
            $doc_urls[]   = esc_url_raw( $doc['url'] );
            $doc_ids[]    = intval( $doc['id'] );
        }
    }

    $prepared_data = array(
        'email'           => $email,
        'first_name'      => $first_name,
        'last_name'       => $last_name,
        'privacy_consent' => $consent,
        'document_titles' => implode( ', ', $doc_titles ),
        'document_urls'   => implode( ', ', $doc_urls ),
        'document_ids'    => implode( ', ', $doc_ids ),
        'document_count'  => count( $doc_ids ),
    );

    do_action( 'my_dlp_lead_submitted_for_automator', $prepared_data );
}

Additional hooks and filters

  • dlp_lead_capture_before_submission – Validate form data before submission.
  • dlp_lead_capture_email_config – Modify email configuration.
  • dlp_lead_capture_cookie_expiration – Change lead capture cookie duration.
  • document_library_pro_lead_capture_form_vars – Modify form template variables.

These hooks allow full customization and integration with any external system.

Adding extra CAPTCHA fields to the form

The lead capture form already has built-in anti-spam protection. However, if required then you can use the action hook dlp_lead_capture_form to add an extra captcha field. You should then use the action hook dlp_lead_capture_before_submission to verify if the submitted CAPTCHA is correct.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.