WP Residence Help WP Residence Help

  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / 13. WPResidence / WPEstate CRM / WPResidence CRM CSV Import and Export — Developer Reference

WPResidence CRM CSV Import and Export — Developer Reference

14 views 0

Developer documentation for the CSV subsystem of the WPResidence real estate CRM. Entry point: libs/csv-functions.php.

Supported Entities

Contacts, leads, enquiries, deals, tasks. Export is gated to contacts, deals, tasks in the hardcoded whitelist; import supports all five.

Export

Property Value
AJAX action wpestate_crm_export_csv
Nonce wpestate_crm_nonce (security param)
Capability wpestate_crm_user_can(‘import_export’, ‘view’)
Function wpestate_crm_export_csv($entity_type, $args)

CSV Output

  • Prepends UTF-8 BOM (\xEF\xBB\xBF) so Excel opens correctly on non-Latin columns.
  • Every value wrapped in double quotes; internal double quotes escaped by doubling.
  • HTTP headers: Content-Type: text/csv; charset=utf-8, Content-Disposition: attachment; filename=crm_{entity}_{YYYY-MM-DD}.csv.
  • Terminates with die() to prevent WordPress from appending its own output.
  • Record limit: 10000 per export.

Ownership Scoping

Non-admins have their user_id injected into the query args, so they only export their own records.

Import — Upload Phase

Property Value
AJAX action wpestate_crm_upload_csv
Nonce wpestate_crm_nonce
Capability wpestate_crm_user_can(‘import_export’, ‘create’)

Flow:

  1. Validate $_FILES[‘csv_file’].
  2. Ensure /wp-content/uploads/wpestate-crm/ exists.
  3. wp_unique_filename() to produce a safe filename.
  4. Move the upload into the CRM directory.
  5. Parse header row, stripping BOM if present.
  6. Read first 5 data rows for preview.
  7. Return JSON: file_path (basename only), headers, preview_rows, total_rows.

Column Mapping

wpestate_crm_map_csv_columns( $csv_headers, $entity_type )

Normalization: lowercase, trim, replace spaces with underscores. Direct match against valid columns first, then alias map. Common aliases: name → first_name, e-mail → email, tel → phone, cell → mobile, zip → zipcode, title → deal_title, value → deal_value, stage → deal_stage, priority → task_priority, type → task_type.

Import — Batch Phase

Property Value
AJAX action wpestate_crm_import_csv_batch
Nonce wpestate_crm_nonce
Capability wpestate_crm_user_can(‘import_export’, ‘create’)
Params file_path (basename), offset, batch_size (default 100), duplicate_action (skip or update)

Path-Traversal Safeguards

The batch handler accepts only a bare filename and reconstructs the full path server-side:

  1. sanitize_file_name() + basename().
  2. Reject filenames with path separators or colons.
  3. Construct path from known base /wp-content/uploads/wpestate-crm/.
  4. realpath() validates the resolved path stays inside the allowed directory (defends against symlink escapes).
  5. MIME / extension check: only .csv or .txt accepted.
  6. is_file() rejects directories and device nodes.

Per-Row Processing

  1. Read row.
  2. For contacts: wpestate_crm_find_contact_by_email() to detect duplicates.
  3. For leads/enquiries: wpestate_crm_detect_duplicate($entity_type, $email).
  4. If duplicate + skip: increment skipped counter.
  5. If duplicate + update: call wpestate_crm_update_contact() (merge mode).
  6. If no duplicate: call wpestate_crm_insert_contact().

Response

{ imported: int, updated: int, skipped: int, errors: [{row, message}, ...], done: bool, next_offset: int }

Duplicate Detection

wpestate_crm_detect_duplicate( $entity_type, $email )

Queries the relevant table by email column: contacts use email; leads use from_email; enquiries use from_email. Returns the matching ID or false.

Hooks Fire Per Row

Each inserted contact fires wpestate_crm_after_insert_contact. That cascades into email notifications, HubSpot sync, webhooks, automations. For large imports, either pause automations first or suspend the hooks temporarily in your import wrapper.

Extending

  • Add new entity type support by extending the validator whitelist and mapping the entity’s CRUD functions into the batch processor.
  • Replace the alias map with a filter hook if you want to expose it to customers.
  • For very large imports (>100K rows), write a WP-CLI command that reads the CSV and calls the CRUD functions directly, bypassing the AJAX batching.
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