WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / WPResidence / WPEstate CRM / WPResidence CRM Installation and Updates — Developer Reference

WPResidence CRM Installation and Updates — Developer Reference

73 views 0

Developer documentation for the activation and migration lifecycle of the WPResidence real estate CRM. Key files: wpestate-crm.php, libs/db-setup.php, libs/migration.php, uninstall.php.

Plugin Constants

WPESTATE_CRM_URL WPESTATE_CRM_DIR_URL WPESTATE_CRM_PATH WPESTATE_CRM_BASE WPESTATE_CRM_VERSION = '5.2.2'

Activation Routine

wpestate_crm_functionality() // lines 331-376 of wpestate-crm.php

Runs on register_activation_hook and is also invoked by wpestate_crm_check_plugin_functionality_loaded() on plugins_loaded when the stored DB version differs from WPESTATE_CRM_VERSION.

Steps

  1. wpestate_crm_create_tables() – create all 9 tables via dbDelta.
  2. wpestate_crm_seed_defaults() – seed default settings, skipping existing non-empty values.
  3. wpestate_crm_migrate_cpt_data() – migrate legacy CPT posts, guarded by wpestate_crm_cpt_migrated flag.
  4. Register manage_crm on the administrator role.
  5. wpestate_crm_seed_permissions() – seed the role-based matrix.
  6. wpestate_crm_migrate_hubspot_settings() – copy legacy Redux keys to CRM settings.
  7. wpestate_crm_seed_default_automations() – insert 27 rules if none exist, all paused.
  8. Schedule 3 cron events if not already scheduled.
  9. update_option(‘wpestate_crm_db_version’, WPESTATE_CRM_VERSION).

Cron Events

Hook Schedule
wpestate_crm_process_automations hourly
wpestate_crm_daily_notifications daily
wpestate_crm_weekly_digest weekly

Deactivation

wpestate_crm_deactivate() // lines 323-328

Clears the three scheduled cron events. Leaves tables and options intact.

Update Detection

wpestate_crm_check_plugin_functionality_loaded() hooks plugins_loaded, compares get_option(‘wpestate_crm_db_version’) against WPESTATE_CRM_VERSION, and re-runs the activation routine on mismatch. This handles the case where the plugin file is replaced via SFTP and no activation hook fires.

Schema Migrations

CPT-to-Table Migration

wpestate_crm_migrate_cpt_data() // libs/migration.php
  • Guard: wpestate_crm_cpt_migrated flag.
  • Inline if total posts <= 500; otherwise batched via WP-Cron at 100 posts per batch.
  • Migrates wpestate_crm_contact posts into wp_wpresidence_crm_contacts, skipping duplicates by email.
  • Migrates wpestate_crm_lead posts into the leads table and creates a form_submission activity per post.
  • Migrates WP comments on the legacy CPT posts into note activities.
  • Leaves original CPT posts in place as reference and does not delete them.

Schema v2 (Column Rename)

wpestate_crm_migrate_schema_v2() // libs/db-setup.php
  • Guard: wpestate_crm_schema_v2_migrated flag.
  • Copies data from legacy column names to new planned column names, such as deal_title → title, deal_stage → stage, and task_title → title.
  • Copies activities with entity_type=’contact’ so they set contact_id instead of entity_id.
  • Does not drop old columns. Both remain for safety.

HubSpot Settings Migration

wpestate_crm_migrate_hubspot_settings() // libs/settings.php
  • Guard: wpestate_crm_hubspot_migrated flag.
  • Copies wp_estate_* Redux keys into the wpestate_crm_settings array under crm_hubspot_* keys.

Viewed Listings Column Rename

In wpestate_crm_create_tables(), if the table has an old user_id column, it renames it to contact_id and drops the old index.

Page Auto-Creation

wpresidence_create_crm_helper_content() // lines 1159-1257

Hooked to wp_loaded. Compares stored setup version, currently 2.1, against the code version and creates any missing CRM pages with the correct _wp_page_template meta.

Uninstall

uninstall.php:

  1. DROP TABLE for all 9 custom tables.
  2. DELETE OPTION for CRM options: wpestate_crm_settings, wpestate_crm_db_version, wpestate_crm_cpt_migrated, wpestate_crm_schema_v2_migrated, wpestate_crm_hubspot_migrated, wpestate_crm_permissions, wpestate_crm_webhooks.
  3. Remove manage_crm capability from all roles.
  4. Delete CRM dashboard pages identified by their _wp_page_template meta value.
  5. Recursively delete the /uploads/wpestate-crm/ directory.
  6. Clear all CRM cron events.

DB Version Option

Key: wpestate_crm_db_version. Value: plugin version string, for example 5.2.2. Updated at the end of every activation run.

Development Tips

  • To force a re-run of activation during development, delete the wpestate_crm_db_version option and reload any admin page.
  • To rewind a migration flag, for example to re-run CPT migration for testing, delete the corresponding *_migrated option.
  • Never edit table schemas directly. Edit libs/db-setup.php and let dbDelta reconcile on the next activation run.
WPResidence / WPEstate CRM

Related Articles

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

Help Categories

  • 18Agent, Agency & Developers
  • 5Blog Posts & Blog Lists
  • 38Elementor Shortcodes Built-In
  • 45FAQ
  • 15Footer
  • 5Getting Started
  • 37Header
  • 2IDX & MLSImport
  • 6Installation & Setup
  • 23Installation FAQ
  • 23Maps & Location Settings
  • 21Multi-Language Third Party Plugins
  • 6Other Third party Plugins
  • 19Pages
  • 4Payments & Monetization
  • 20Property Lists, Categories & Archive
  • 36Property Pages & Layouts
  • 31Search & Filtering
  • 162Technical how to | Custom Code Required
  • 8Technical: Actions and filters
  • 6Technical: Child Theme
  • 86Theme Options & Global Settings
  • 6Translations & Languages
  • 16WPBakery Shortcodes
  • 51WPResidence / WPEstate CRM
  • 50WPResidence 5.0 Documentation
  • 8WPResidence Elementor Studio
  • 50WPResidence Translate Plugin

Join Us On

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