Documentation · Technical Documentation
Lead Storage And Processing
This document describes how the ADP Car Market Hub plugin captures contact-form and test-drive submissions, where they are stored, how their workflow status is managed and which automated emails are sent.
When to use this document
Read this document if you need to:
- Understand the schema and life cycle of a lead generated by the plugin's contact form.
- Map lead data to an external CRM via the leads admin screen or
the
_as24ci_lead_*post-meta fields. - Diagnose missing notifications or stuck workflow statuses.
- Migrate leads between environments.
For inbound REST/AJAX endpoints, see REST API Endpoints and AJAX Actions. For outbound notifications, see Webhooks.
Overview
Leads are stored as posts of the custom post type as24ci_lead,
implemented in AS24CI\Leads_CPT. The CPT is registered as
public => false, show_ui => false and show_in_rest => false,
so it is not exposed to the front-end or to the WordPress REST
API. The admin Leads tab provides a custom list table for
viewing, searching, status changes and deletion.
Each submission flows through the contact form
(AS24CI\Contact_Form), which:
- Validates and sanitises the form input.
- Sends the dealer notification email and the customer confirmation email (using either the configured custom templates or the built-in defaults).
- Calls
Leads_CPT::save_lead()to persist a new lead record. - Records a
lead_sentanalytics event when a vehicle ID is present.
Lead post fields
Leads_CPT::save_lead() writes the following meta keys:
| Meta key | Source | Sanitiser |
|---|---|---|
_as24ci_lead_name | Form Name | sanitize_text_field |
_as24ci_lead_email | Form Email | sanitize_email |
_as24ci_lead_phone | Form Phone | sanitize_text_field |
_as24ci_lead_message | Form Message | wp_kses_post |
_as24ci_lead_vehicle_id | Vehicle post ID | absint |
_as24ci_lead_vehicle_title | Vehicle title at submission time | sanitize_text_field |
_as24ci_lead_vehicle_listing_id | Source listing identifier | sanitize_text_field |
_as24ci_lead_vehicle_url | Vehicle permalink | sanitize_url |
_as24ci_lead_source_url | HTTP referer or vehicle URL | sanitize_url |
_as24ci_lead_date | UTC submission timestamp (Y-m-d H:i:s) | — |
_as24ci_lead_email_sent | 1 when both emails were dispatched, otherwise 0 | — |
_as24ci_lead_status | Workflow status (defaults to new) | — |
_as24ci_lead_appointment_date | Test-drive date (Y-m-d or Y-m-d H:i) | Strict format check |
_as24ci_lead_is_test_drive | 1 when the form is a test-drive request | — |
The post_title is set to the contact name and post_status
is publish.
Status workflow
Leads_CPT defines four workflow statuses:
| Constant | Slug | Default label |
|---|---|---|
STATUS_NEW | new | New |
STATUS_CONTACTED | contacted | Contacted |
STATUS_CLOSED | closed | Closed |
STATUS_SPAM | spam | Spam |
get_lead_status() returns the stored status, defaulting to
new when the meta is missing or unrecognised.
update_lead_status() rejects unknown values.
The admin status-change action is exposed via the AJAX handler
as24ci_update_lead_status (capability:
manage_as24_imports, nonce: as24ci_update_lead_status).
Step by step instructions
To review and process a lead:
- Open the Leads admin tab.
- Use the search box to filter by name, email, listing ID or
vehicle title (server-side
LIKEmatching against the corresponding meta keys). - Use the status dropdown to filter by
new,contacted,closedorspam. - Open a lead to view its details, then change the status as the workflow progresses.
- Use the delete action to remove a lead permanently. The
record is removed via
wp_delete_post( $id, true ); there is no trash step foras24ci_lead.
Email behavior
Two emails are sent per submission:
- Dealer notification — sent to the address configured in
as24ci_lead_recipient_email. Uses HTML and includes the vehicle, customer and message details. A custom template can be configured via the Leads admin settings. - Customer confirmation — sent to the visitor's email
address. Has separate templates for standard inquiries and
test-drive bookings, and supports a custom template stored in
the option
as24ci_lead_email_template_customer.
Both emails use wp_mail(). The _as24ci_lead_email_sent meta
records whether both messages were dispatched successfully (the
wp_mail() boolean return values are AND-combined).
Configuration reference
| Option key | Purpose |
|---|---|
as24ci_lead_recipient_email | Recipient address for the dealer notification email. |
as24ci_lead_email_template_customer | Optional custom HTML template for the customer confirmation. |
Additional templating options for the dealer-side email may be exposed in the Leads admin tab. Verify the exact list against the current plugin version before publishing customer-facing copy.
Operational notes
- The CPT is intentionally not exposed in the REST API or the block editor; treat the WP admin Leads tab as the single user interface.
wp_count_posts( 'as24ci_lead' )is used by the dashboard widget to display the total lead count.- Leads are written from the same HTTP request that processed
the form submission. A failed
wp_mail()does not prevent the lead from being stored; the_as24ci_lead_email_sentflag reflects only the email status. - The
lead_sentanalytics event is only recorded when a validvehicle_idis present in the submission. - Webhook integration: an outbound
new_leadwebhook is wired up internally on theas24ci_lead_savedaction. Verify in the current plugin version whether this action is dispatched at lead-save time before relying on it for production integrations.
Troubleshooting
- Lead is saved but no emails arrive — check the
_as24ci_lead_email_sentmeta. If it is0,wp_mail()failed. Verify SMTP/mailer configuration and the recipient address. - Test-drive lead has no appointment date — the appointment
is only stored when the input matches
Y-m-d H:iorY-m-dand represents a real calendar date. Mistyped dates are silently dropped to keep the lead record consistent. - Status changes are reverted on reload — confirm the AJAX
status update returned
success. A403indicates the user lacksmanage_as24_imports; a400/Invalid parametersmeans the lead ID or status was missing or invalid. - Search returns no results despite matching content —
searches use
LIKEagainst four specific meta keys. Search terms that only appear in the message body are not indexed. - Lead totals on the dashboard widget look wrong — the
count is based on
publishstatus only. Spam-marked leads remainpublishbut with_as24ci_lead_status = spam.