How to Track Custom Lead Values with WordPress Leads

Post written by Hudson Atwell
On Monday, January 20th, 2014

wordpress-leads-featuredIf you have started Collecting Advanced Lead Intelligence in WordPress with the WordPress leads plugin, you might be wondering how you can track custom lead fields to the lead profile inside WordPress.

This tutorial will show you how to use our built in WordPress hooks to add additional custom lead intelligence to your lead records and give you even more data on your web leads.

The Scenario

In this case scenario we would like to add special fields to a WordPress Lead. The WordPress Leads plugin only comes with a handful of the most commonly used customer data fields and there are often circumstances when new fields need to be added and populated by field mapping or automation.

The Solution

Currently our default fields are defined in the /leads/modules/wpl.m.userfields.php file (This is location may change as we improve our internal code structure but for now this is where it can be found).

We need to add a filter to hook into the definitions data and add new fields:

The wp_leads_add_lead_field hook

Here’s an example of how we could create a custom hook in a plugin or in our theme’s functions.php folder to add in our extra data:

add_filter( 'wp_leads_add_lead_field' , 'my_custom_function', 10, 1);
function my_custom_function( $lead_fields )
{
    $lead_fields['special_id_here'] =   array(
	        'label' => 'New Field', //will be the label
	        'key'  => 'wpleads_new_field', //will be the meta key
	        'priority' => 235, //defines priority on the render list
	        'type'  => 'text' //defines what kind of field it is -- read more below on acceptable field types
	        );

	return $lead_fields;
}

Acceptable field types:

The code that controls the rendering of fields can be found here: https://github.com/inboundnow/leads/blob/master/functions/wpl.f.admin.php#L71. But this could change very soon as a code overhaul is scheduled for WP Leads and when that happens we will, with your help, update this article as soon as possible.

Acceptable Fields:

  • text
  • textarea
  • links
  • wysiwyg
  • media
  • checkbox
  • radio
  • dropdown
  • dropdown-country

Special notes about adding new fields

  • Fields are cached in a transient for up to 24 hours. To clear this cache and see your new added fields immediately after adding them you will need to access wp-admin with this get parameter: wp-admin/?clear_lead_custom_field_cache=1 in your address bar.
  • If you use a custom filter to add fields to wpleads make sure you add the code to your theme’s functions.php file or create a brand new WordPress plugin extension. If you edit our core files directly they will be overwritten during plugin updates.

About the Author:
Cheers! Hudson Atwell is a co-founder and current administrator of Inbound Now. Consider hiring him through the Codeable.io Agency or connecting with him professionally through LinkedIn.

Signup and get started with Inbound Now

Sign Up for Free

Download

[gravityform id="3" name="Popup Form" title="false" description="false" ajax="true"]