WP Residence Help WP Residence Help

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

WPResidence CRM HubSpot Integration — Developer Reference

13 views 0

Developer documentation for the HubSpot integration in the WPResidence real estate CRM. Code lives in libs/hubspot/, main file libs/hubspot/hubspot.php. Full architectural overview is in the HubSpot CRM integration guide.

API

  • Version: HubSpot CRM v3.
  • Base URL: https://api.hubapi.com/crm/v3/.
  • Auth: Bearer token (Private App access token).
  • HTTP client: wp_remote_post(), wp_remote_get(), wp_remote_request().

Settings (dual source)

Settings are read via wpestate_crm_get_setting() first, falling back to legacy Redux keys via wpresidence_get_option():

CRM key Legacy Redux key
crm_hubspot_enabled wp_estate_enable_hubspot_integration
crm_hubspot_enabled_for_all wp_estate_enable_hubspot_integration_for_all
crm_hubspot_api_token wp_estate_hubspot_api
crm_hubspot_first_stage wp_estate_hubspot_first_stage
hubspot_stage_map (none)

Contact Sync

wpestate_crm_hubspot_sync_contact( $contact_id, $data )

Hooked to wpestate_crm_after_insert_contact and wpestate_crm_after_update_contact at priority 20. Flow:

  1. Check crm_hubspot_enabled and confirm the API token is present.
  2. Build field map: first_name → firstname, last_name → lastname, mobile → phone, plus email, city, state, and country.
  3. Filter out empty values so non-destructive updates do not clear HubSpot fields.
  4. Search HubSpot by email to detect an existing contact.
  5. If found: PATCH /crm/v3/objects/contacts/{id}.
  6. If not found: POST /crm/v3/objects/contacts.

Deal Sync

wpestate_crm_hubspot_sync_deal( $deal_id, $data )

Hooked to wpestate_crm_after_insert_deal and wpestate_crm_after_update_deal at priority 20. Flow:

  1. Check enabled status and token.
  2. Build properties: dealname from deal_title or title, amount from deal_value, dealstage from the hubspot_stage_map lookup, with fallback to sanitize_title() of the CRM stage name or crm_hubspot_first_stage.
  3. Create or PATCH the deal.
  4. If the CRM deal has a contact_id, look up the HubSpot contact by email and associate it via PUT /crm/v3/objects/deals/{deal_id}/associations/contacts/{contact_id}/deal_to_contact.
  5. Store the returned HubSpot deal ID in the CRM deals table as hubspot_deal_id.

Helper Functions

Function Purpose
wpestate_crm_return_api_hubspot($lead_id) Resolves API token from agent, agency, or developer CPT meta first, then CRM settings, then Redux
wpestate_hubspot_enabled($who) Checks the enabled flag; $who=’all’ enforces the global sync-for-all flag

Legacy Functions

Maintained for backward compatibility with older form handlers:

  • wpestate_create_contact_hubspot()
  • wpestate_create_deal_hubspot()
  • wpestate_create_tickets_hubspot()
  • wpestate_hubspot_crm_associate()
  • wpestate_hubspot_sync_deal_stage()
  • wpestate_hubspot_sync_deal_value()

Test Connection AJAX

Property Value
Action wpestate_crm_test_hubspot_connection
Nonce wpestate_crm_test_hubspot (security param)
Capability manage_options

Four checks run sequentially:

  1. GET /crm/v3/objects/contacts?limit=1 – contacts read.
  2. GET /crm/v3/objects/deals?limit=1 – deals read.
  3. GET /crm/v3/pipelines/deals – pipelines; counts stages.
  4. Create a test contact, then immediately DELETE it – contacts write.

Error Handling

  • All HTTP failures are silent. They never block the CRM operation that triggered them.
  • is_wp_error() is checked on every HTTP response.
  • Errors are logged to the plugin’s logs/ directory.

Sync Direction

One-way only: WPResidence CRM → HubSpot. There is no inbound sync path. If you need two-way sync, implement a HubSpot webhook that calls back into a WordPress REST endpoint you write.

Extending

  • Map additional fields by filtering the property array in your child plugin before the wp_remote_post() call. Add an apply_filters() in a fork if needed, or wrap the function.
  • Sync custom CRM objects, such as tasks or activities, by adding new hooks that call the HubSpot API directly using the existing auth token resolver.
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