Developer documentation for the Notes module in the WPResidence real estate CRM. Notes are polymorphic. A single table stores notes for contacts, leads, enquiries, deals, and tasks.
Storage – wp_wpresidence_crm_notes
Created in libs/db-setup.php. Columns:
| Column | Purpose |
|---|---|
| note_id | Primary key |
| entity_type | One of: contact, lead, enquiry, deal, task |
| entity_id | Foreign key into the matching entity table |
| user_id | Note author (WP user ID) |
| note_text | longtext – the note body |
| created_at | Timestamp |
Index on (entity_type, entity_id) for fast per-record lookups.
CRUD API – libs/notes-crud.php
| Function | Purpose |
|---|---|
| wpestate_crm_insert_note($data) | Insert; required: entity_type, entity_id, user_id, content (mapped to note_text) |
| wpestate_crm_get_notes($entity_type, $entity_id, $args) | Fetch notes for one record; supports limit (default 20), offset, order (default DESC) |
| wpestate_crm_delete_note($note_id) | Delete one |
| wpestate_crm_bulk_delete_notes($ids) | Bulk delete; returns int count |
| wpestate_crm_sanitize_note_data($data) | Sanitizer – maps content to note_text, applies sanitize_textarea_field(), casts IDs with absint() |
Mirror to Activities Table
Each note insert also creates a note-type row in wp_wpresidence_crm_activities via wpestate_crm_record_activity_v2(). This is what makes notes appear in the unified timeline alongside system events.
Hooks
- wpestate_crm_after_add_note – fired after insert. Consumed by the automations engine (triggers note_added event) and downstream analytics.
Permissions
Gated by wpestate_crm_user_can($entity_type_plural, $action). Delete enforces authorship: only the note’s user_id or an administrator can delete. All users with view access to the parent record can read notes.
Usage From Other Modules
The contact detail page (templates/crm_contact_detail.php) includes an Add Note form. The form submits via an AJAX action that wraps wpestate_crm_insert_note(). Render loops use wpestate_crm_get_notes(‘contact’, $contact_id).
Extending
- Add your own entity types by writing an entity_type string. The table is not constrained to the five defaults. Just make sure your render loop knows how to resolve the entity_id.
- For rich text or attachments, store markup in note_text and escape with wp_kses_post() on output. The default sanitizer uses sanitize_textarea_field(), which strips tags, so customize in a child plugin if you need HTML notes.