Developer documentation for the email notifications module of the WPResidence real estate CRM. Entry point is libs/notifications.php.
Send API
wpestate_crm_send_notification_email( $event, $data )
Flow:
- Read subject and body from settings (wp_estate_subject_crm_notify_{event} and wp_estate_crm_notify_{event}).
- If either is empty, abort — the event is effectively disabled.
- Resolve placeholders via wpestate_crm_resolve_placeholders().
- Determine recipient: $data[‘recipient_email’] → $data[‘agent_email’] → site admin.
- Apply nl2br() to body for HTML.
- Wrap with wpestate_crm_wrap_email_template().
- Send via wpestate_send_emails() with wp_mail() fallback.
- Record email_sent activity on the contact.
Supported Events
- new_contact
- contact_assigned
- deal_stage
- deal_won
- task_overdue
- task_due_today
Placeholder Resolver
wpestate_crm_resolve_placeholders( $template, $data )
Replaces 20 placeholders — see the user-facing article for the full list. Internals:
- {contact_phone} resolves to $data[‘mobile’], falling back to phone, then home_phone.
- {listing_price} uses the theme’s currency label via wpresidence_get_option(‘wp_estate_currency_label_main’).
- {task_due_date} uses date_i18n(get_option(‘date_format’)).
- {crm_contact_url} / {crm_deal_url} generate links to the dashboard pages with ?contact_detail=ID / ?deal_detail=ID.
Template Wrapper
wpestate_crm_wrap_email_template( $subject, $body )
Loads templates/email_templates/base_email_template.php via locate_template(), captures its output with ob_start(), and returns the wrapped HTML. Respects the theme option wpestate_email_type: when set to text, the wrapper is skipped and a plain-text message is returned.
Hook Registrations
| Hook | Priority | Callback |
|---|---|---|
| wpestate_crm_after_insert_contact | 20 | wpestate_crm_on_new_contact_notification() |
| wpestate_crm_after_update_contact | 20 | wpestate_crm_on_contact_assigned_notification() (detects assigned_agent_id change) |
| wpestate_crm_after_update_deal | 10 | wpestate_crm_on_deal_update_notification() (handles stage change and won detection) |
| wpestate_crm_daily_notifications | — | wpestate_crm_daily_task_notifications() |
Daily Task Cron
wpestate_crm_daily_notifications is scheduled on plugin activation. The handler:
- Queries the tasks table for due_date < today AND status not Completed/Cancelled. Groups by user_id.
- Queries tasks where due_date >= today AND due_date < tomorrow AND status not Completed/Cancelled. Groups by user_id.
- Sends one task_overdue email per agent using the first task’s data as template context.
- Sends one task_due_today email per agent.
Settings Keys
Per event, two keys:
- wp_estate_subject_crm_notify_{event}
- wp_estate_crm_notify_{event}
Both are stored in the theme’s Redux option store (not in the CRM’s own settings array). This was a deliberate consolidation so admins manage all email templates in one place — Theme Options → Email Management → CRM Emails.
Extending
- Register a new event by hooking a CRM event and calling wpestate_crm_send_notification_email($new_event, $data).
- Add new placeholders by filtering the resolver output in a child plugin.
- Override the wrapper by placing a base_email_template.php in your child theme’s templates/email_templates/ directory — locate_template() will pick it up first.