The Activity module is the audit log of the WPResidence real estate CRM. This article documents the schema, the write API, the triggers, and the valid activity types.
Storage — wp_wpresidence_crm_activities
14 columns. Created in libs/db-setup.php. The schema mirrors legacy and new column names during the ongoing rename:
| Legacy | New |
|---|---|
| entity_id | contact_id |
| action | type |
Other columns: activity_id, user_id, entity_type, deal_id, task_id, listing_id, subject, message, meta (JSON longtext), created_at.
Indexes on (entity_type, entity_id), user_id, contact_id, deal_id, type, created_at.
Write API — libs/activity-crud.php
| Function | Purpose |
|---|---|
| wpestate_crm_record_activity() | Legacy schema writer (entity_type + entity_id + action) |
| wpestate_crm_record_activity_v2() | New preferred writer (contact_id / deal_id / task_id / listing_id + type) |
| wpestate_crm_add_note($entity_type, $entity_id, $note) | Convenience for adding a note |
| wpestate_crm_get_activities($args) | Filters: user_id, contact_id, deal_id, task_id, type (scalar or array), date range, search |
Valid Activity Types
From the source code:
- note
- form_submission
- email_sent
- call / call_logged
- contact_created
- lifecycle_changed
- status_changed
- deal_created
- deal_stage_changed
- deal_won
- deal_lost
- task_created
- task_completed
- property_matched
- listing_email_sent
- contact_assigned
- viewed_listing
- automation_triggered
Automatic Triggers
| Source | Resulting activity |
|---|---|
| wpestate_crm_after_insert_contact | contact_created |
| wpestate_crm_after_update_contact | lifecycle_changed (when stage differs), contact_assigned (when assigned_agent_id changes) |
| wpestate_crm_after_insert_deal | deal_created |
| wpestate_crm_after_update_deal | deal_stage_changed, deal_won, deal_lost |
| wpestate_crm_after_insert_task | task_created |
| wpestate_crm_after_complete_task | task_completed |
| libs/auto-create.php | form_submission |
| libs/matching-functions.php | property_matched, listing_email_sent |
| libs/viewed-functions.php | viewed_listing |
| libs/automations.php | automation_triggered |
| libs/notifications.php | email_sent (on successful send) |
| libs/twilio.php | sms_sent |
Templates
- page-templates/wpestate-crm-dashboard_activity.php — site-wide timeline.
- templates/crm_activity_unit.php — single row partial. Reused on contact/deal detail pages.
Downstream Hook
wpestate_crm_after_record_activity fires after every insert. Subscribers include the automations engine (looks for call_logged to auto-promote contacts) and the webhooks dispatcher (emits form_submitted webhook for form_submission activities).
Meta Column
Activities can store structured extra data in meta as JSON. Examples: form_submission stores {form_type, listing_id}; listing_email_sent stores {listing_count, listing_ids}; property_matched stores {match_count, criteria_summary}. Read via json_decode($row->meta, true).
Permissions
Gated by wpestate_crm_user_can(‘activities’, $action). Non-admin queries scoped to the user’s contacts via joins on contact_id.