Make CRM exports download reliably
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 19s
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 19s
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
## 1.4.0
|
||||
|
||||
- Make Leads and Inquiries export buttons submit a normal authenticated CSV download instead of relying on asynchronous AJAX/Blob downloads.
|
||||
- Keep the established 24-column Leads and eight-column Inquiries layouts.
|
||||
|
||||
## 1.3.0
|
||||
|
||||
- Enable the plugin on the approved Jen Home production site as well as staging.
|
||||
|
||||
@@ -35,6 +35,9 @@ omit Source Link and retain their other existing fields. CRM views still show in
|
||||
though the shorter Inquiries CSV omits them. Historical records are not backfilled
|
||||
or split; relationships use IDs, never email matching.
|
||||
|
||||
The CRM export buttons submit the protected endpoints as normal browser downloads,
|
||||
so the CSV is not dependent on an asynchronous JavaScript Blob download.
|
||||
|
||||
The plugin creates a prefixed `jenhome_contact_fields` extension table for middle
|
||||
names and exact submission provenance. Native Houzez tables and vendor files are
|
||||
not modified. Keep this table when rolling back or deactivating the plugin.
|
||||
|
||||
30
forms.js
30
forms.js
@@ -121,7 +121,35 @@
|
||||
document.addEventListener('submit', event => {
|
||||
if (relevant(event.target)) { enhance(event.target); sync(event.target); }
|
||||
}, true);
|
||||
// Preserve the vendor export buttons and download behavior while adding CSRF protection.
|
||||
// Submit exports as a normal download. This avoids the vendor AJAX/Blob flow,
|
||||
// which silently fails on browsers that block downloads from async callbacks.
|
||||
document.addEventListener('click', event => {
|
||||
const button = event.target.closest?.('#export-leads, #export-inquiries');
|
||||
if (!button) return;
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
if (!config.ajaxUrl || !config.exportNonce) {
|
||||
window.alert('Please sign in again before exporting.');
|
||||
return;
|
||||
}
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = config.ajaxUrl;
|
||||
form.style.display = 'none';
|
||||
const action = document.createElement('input');
|
||||
action.type = 'hidden';
|
||||
action.name = 'action';
|
||||
action.value = button.id === 'export-leads' ? 'houzez_crm_export_leads' : 'crm_export_inquiries';
|
||||
const nonce = document.createElement('input');
|
||||
nonce.type = 'hidden';
|
||||
nonce.name = 'jenhome_export_nonce';
|
||||
nonce.value = config.exportNonce;
|
||||
form.append(action, nonce);
|
||||
document.body.append(form);
|
||||
form.submit();
|
||||
window.setTimeout(() => form.remove(), 1000);
|
||||
}, true);
|
||||
// Keep the nonce attached if another Houzez view calls these endpoints by AJAX.
|
||||
$.ajaxPrefilter(function (options) {
|
||||
const url = new URL(options.url, location.href);
|
||||
if (url.origin !== location.origin || !url.pathname.endsWith('/admin-ajax.php')) return;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Plugin URI: https://hostlabs.pro/
|
||||
* Update URI: https://git.labs.casa/josh/jenhomeforms
|
||||
* Description: Jen Home Houzez contact fields, inquiry ownership and protected CSV exports.
|
||||
* Version: 1.3.0
|
||||
* Version: 1.4.0
|
||||
* Requires at least: 6.2
|
||||
* Requires PHP: 8.1
|
||||
* Author: Josh Stevens Sr
|
||||
@@ -13,7 +13,7 @@
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Jenhome_Contact_Exports {
|
||||
const VERSION = '1.3.0';
|
||||
const VERSION = '1.4.0';
|
||||
const INQUIRY_OWNER_ID = 7;
|
||||
const ACTIONS = ['houzez_ele_inquiry_form', 'houzez_ele_contact_form', 'houzez_property_agent_contact', 'houzez_schedule_send_message', 'houzez_contact_realtor'];
|
||||
// Verified Elementor widgets: contact page and the two Get Started popups.
|
||||
@@ -80,6 +80,7 @@ final class Jenhome_Contact_Exports {
|
||||
wp_localize_script('jenhome-contact-exports', 'JenhomeContact', [
|
||||
'actions' => self::ACTIONS, 'referralForms' => self::REFERRAL_FORMS,
|
||||
'referrals' => self::referrals(), 'nonce' => wp_create_nonce('jenhome_contact'),
|
||||
'ajaxUrl' => admin_url('admin-ajax.php'),
|
||||
'exportNonce' => is_user_logged_in() ? wp_create_nonce('jenhome_export') : '',
|
||||
]);
|
||||
wp_register_style('jenhome-contact-exports', false, [], self::VERSION);
|
||||
|
||||
Reference in New Issue
Block a user