Developer documentation for the form-to-CRM pipeline in the WPResidence real estate CRM. Entry point is libs/auto-create.php.
Entry Point
wpestate_crm_process_form_submission( $form_data )
Called by the theme’s form handlers with a structured array that identifies the form, the prospect, and the target property or agent if any.
Expected Form Data
- contact_name – split into first_name, last_name on the first space.
- contact_email – required; validated with is_email().
- contact_mobile – phone number.
- details – message body.
- propid – property post ID (optional).
- agent_id – agent post ID (optional).
- form_type – origin identifier.
Form Type Map
| form_type | Enquiry type |
|---|---|
| property | Property Inquiry |
| schedule_section | Schedule Tour |
| contact_page | General Question |
| agent | Property Inquiry |
| footer | General Question |
Pipeline Steps
- Validate email; abort if invalid.
- Call wpestate_crm_find_contact_by_email($email).
- If matched: update existing contact (merge mode) via wpestate_crm_update_contact().
- If not matched: call wpestate_crm_insert_contact() with lifecycle_stage=’new_lead’, lead_source=’website’.
- Populate buyer preferences from property metadata if propid is present, only on empty preference fields.
- Set tracking cookie wpestate_crm_contact_id (1-year, HttpOnly, SameSite=Lax, Secure on HTTPS) if headers were not sent.
- Insert enquiry row via wpestate_crm_insert_enquiry().
- Record form_submission activity via wpestate_crm_record_activity_v2() with meta: {form_type, listing_id}.
- Hooks fire downstream: email notifications, Twilio, HubSpot, webhooks, automations.
Lead Owner Detection
wpestate_crm_detect_lead_owner( $form_data )
Priority:
- If agent_id is present, resolve the CPT meta user_meda_id (intentional typo preserved) to a WP user ID.
- Else if propid is present, use the property’s post_author.
- Else fallback to the site admin, user ID 1 via wpestate_crm_return_admin_id().
Buyer Preferences Auto-Fill Details
When propid is set, the function reads property attributes and fills the contact’s preference fields if empty:
- property_category tax term → pref_property_type.
- property_city tax term → pref_locations.
- property_bedrooms → pref_min_beds, pref_max_beds.
- property_bathrooms → pref_min_baths, pref_max_baths.
- property_price → 80% to pref_min_price, 120% to pref_max_price.
- property_size → 80% to pref_min_area, 120% to pref_max_area.
No Direct Hooks
This module does not register its own add_action() calls. It is invoked directly by the theme’s contact form handlers. All downstream side effects use the CRM’s own hooks, such as wpestate_crm_after_insert_contact and wpestate_crm_after_record_activity, via other modules.
Tracking Cookie
See the Viewed Tracking developer article for the full cookie lifecycle. Tracking begins the moment process_form_submission completes. The first property page the prospect views after the form submission is attributed to them.
Testing
- Enable the CRM and submit a property contact form as an anonymous visitor.
- Verify: new row in wp_wpresidence_crm_contacts; new row in wp_wpresidence_crm_enquiries; form_submission row in wp_wpresidence_crm_activities; cookie in browser; contact visible in CRM dashboard.
- Re-submit with the same email and verify the existing contact is updated, with no duplicate.
Related
HubSpot sync of auto-created contacts runs via the wpestate_crm_after_insert_contact hook. See the HubSpot CRM integration guide.