WP Residence Help WP Residence Help

  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / 13. WPResidence / WPEstate CRM / WPResidence CRM Automations — Developer Reference

WPResidence CRM Automations — Developer Reference

14 views 0

The automations engine is the workflow layer of the WPResidence real estate CRM. This article documents the rule storage, the condition evaluator, the 8 action handlers, and the cron architecture.

Files

  • libs/automations.php – CRUD, condition evaluator, action executor, AJAX handlers, default seeder.
  • libs/automations-cron.php – hourly batch processor, event dispatcher, queued executor.
  • page-templates/wpestate-crm-dashboard_automations.php – list template.
  • templates/crm_add_automation.php – add/edit form.
  • templates/dashboard_automation_unit.php – single rule card.

Storage – wp_wpresidence_crm_automations

12 columns: automation_id, user_id, title, trigger_type (time_based or event_based), trigger_event, conditions (longtext JSON), action_type, action_config (longtext JSON), status (active or paused), last_run_at, created_at, updated_at.

Indexes on status, trigger_type.

CRUD API

Function Purpose
wpestate_crm_insert_automation($data) Insert; required: title, trigger_type, action_type
wpestate_crm_get_automation($id) Fetch one with JSON-decoded conditions/action_config
wpestate_crm_get_automations($args) Filters: status, trigger_type, pagination
wpestate_crm_update_automation($id, $data) Partial update, stamps updated_at
wpestate_crm_delete_automation($id) Delete
wpestate_crm_toggle_automation($id) Flip between active and paused

AJAX Endpoints

Action Nonce
wpestate_crm_save_automation wpestate_crm_save_automation
wpestate_crm_delete_automation wpestate_crm_delete_automation
wpestate_crm_toggle_automation wpestate_crm_toggle_automation

Condition Evaluator

The evaluator supports 18 fields (mix of direct columns and computed metrics) and 10 operators: equals, not_equals, greater_than, less_than, contains, not_contains, is_empty, is_not_empty, in, not_in. Conditions are combined with AND – all must pass for the rule to fire.

Supported Fields

  • Direct columns: lifecycle_stage, lead_source, lead_type, status, assigned_agent_id.
  • Computed: days_since_created, days_since_last_activity, days_since_stage_change, activity_count, has_deal, deal_stage, deal_value, deal_days_in_stage, task_overdue_count, has_tasks_due_this_week, tags_contain, has_buyer_preferences, viewed_listing_count_last_24h.

Action Executor – 8 Types

  1. send_email – resolves placeholders via wpestate_crm_resolve_placeholders(), picks recipient (contact/agent/admin), sends via wpestate_send_emails() with wp_mail() fallback.
  2. send_sms – resolves placeholders, sends via Twilio if configured.
  3. change_stage – updates contact’s lifecycle_stage.
  4. create_task – builds task row from action_config (title, type, priority, due_days offset), resolves placeholders, calls wpestate_crm_insert_task().
  5. assign_agent – updates assigned_agent_id.
  6. add_tag – appends to contact’s tags CSV (no duplicates).
  7. run_matching – calls wpestate_crm_match_properties() and optionally notifies agent.
  8. send_digest – compiles tasks-due-this-week for the agent and emails a digest.

Cron Architecture

Event Schedule Handler
wpestate_crm_process_automations Hourly Time-based batch processor
wpestate_crm_execute_queued_action One-time Event-based executor (args: automation_id, contact_id)
wpestate_crm_match_new_listing One-time Buyer matching when a listing is published (arg: post_id)
wpestate_crm_weekly_digest Weekly Weekly task digest

Event-Based Dispatcher

wpestate_crm_process_event_automation() is attached to CRM entity hooks. It scans active rules whose trigger_type=event_based and trigger_event matches the fired event, evaluates conditions, then schedules one wpestate_crm_execute_queued_action cron per match (1-minute delay) to keep the triggering request fast.

Event Sources

  • wpestate_crm_after_insert_contact → contact_created
  • wpestate_crm_after_add_note → note_added
  • wpestate_crm_after_record_activity (type=’call’) → call_logged
  • wpestate_crm_after_insert_deal → deal_created
  • wpestate_crm_after_update_deal → deal_stage_changed (and sub-events for specific stages)
  • wpestate_crm_after_viewed_listing → viewed_listing
  • publish_estate_property → schedules buyer matching

Time-Based Dedup

Hourly batch processing compares last_run_at and cross-checks the activities table for an automation_triggered row with matching automation_id + contact_id since last_run_at. Prevents the same rule firing on the same contact twice.

27 Default Rules

Seeded on activation by wpestate_crm_seed_default_automations(). All start status=’paused’. Categories and counts:

  • Speed-to-Lead – 4
  • Stale Lead Recovery – 7
  • Deal Pipeline – 6
  • Task Management – 2
  • Contact Lifecycle Auto-Progression – 5
  • Property Matching – 3

Permissions

wpestate_crm_user_can(‘automations’, $action). Default: all for administrators, none for everyone else.

13. WPResidence / WPEstate CRM

Related Articles

  • WPResidence CRM Security Model — Developer Reference
  • CRM Security and Data Privacy
  • WPResidence CRM Installation and Updates — Developer Reference
  • Installing and Updating the WPResidence CRM

WP Residence Documentation

  • 01. Getting Started
    • How to Get Support
    • Get your buyer license code.
    • Use SSL / https
    • Server / Theme Requirements
  • 02. Installation & Setup
  • 03. Installation FAQ
  • 06. Search & Filtering
    • Advanced Search Display Settings
    • Advanced Search Form
    • Geolocation Search for Half Map
    • Save Search Theme Options
    • Advanced Search Colors
  • 09. Agent, Agency & Developers
  • 08. Property Pages & Layouts
  • 07. Property Lists, Categories & Archive
  • 14. WPResidence Elementor Studio
  • 10. Blog Posts & Blog List
  • 11. Shortcodes
    • Contact Form
    • Featured Agency/Developer
    • Membership Packages
    • Testimonials
    • Google Map with Property Marker
    • Listings per Agent, Agency or Developer
    • Display Categories
    • Agent List
    • Recent Items Slider
    • Recent items
    • List Properties or Articles by ID
    • Featured Agent
    • Featured Article
    • Featured Property
    • Login & Register Form
    • Icon Content Box Shortcode
  • 12. Widgets
  • 04. Theme Options & Global Settings
    • General Settings
    • User Types Settings
    • Appearance
    • Logos & Favicon
    • Header
    • Footer Style and Colors
    • Price & Currency
    • Property Custom Fields
    • Features & Amenities
    • Listing Labels
    • Theme Slider
    • Permalinks
    • Splash Page
    • Social & Contact
    • Map Settings
    • Pin Management
    • How read from file works
    • General Design Settings
    • Custom Colors Settings
    • Header Design & Colors
    • Mobile Menu Colors
    • User Dashboard Colors
    • Print PDF Design
    • Property, Agent, Blog Lists Design Settings
    • Sidebar Widget Design
    • Font management
    • How to add custom CSS
    • Custom Property Card Unit – Beta version
    • Email Management
    • Import & Export theme options
    • reCaptcha settings
    • YELP API Integration
    • iHomefinder Optima Express IDX
    • MEMBERSHIP & PAYMENT Settings
    • Property Submission Page
    • PayPal Setup
    • Stripe Setup
    • Wire Transfer Payment Method
  • 20. Translations & Languages
  • 26. FAQ
  • 10. Pages
  • 11. Header
  • 12. Footer
  • 05. Maps & Location Settings
  • 18. Payments & Monetization
  • Plugins
    • 19. Included Plugins
    • 22. Third Party Plugins – IDX Compatibility
    • 21. Third-Party Plugins – Multi-Language
    • 23. Third party Plugins – Other
  • Technical
    • 24. Technical how to | Custom Code Required
    • 25. Technical: Child Theme

Join Us On

Powered by WP Estate - All Rights Reserved
  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API