2 Commits

Author SHA1 Message Date
josh
c690c0f8cf Put email last in contact exports
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 18s
2026-11-02 12:00:46 -05:00
josh
0fe8914981 Make CRM exports download reliably
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 19s
2026-11-02 11:56:28 -05:00
5 changed files with 62 additions and 17 deletions

View File

@@ -1,3 +1,13 @@
## 1.5.0
- Move phone columns before Email and make Email the final column in both CSV exports.
- Build and validate the plugin package on every push; published stable Gitea releases remain the WordPress update source.
## 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 ## 1.3.0
- Enable the plugin on the approved Jen Home production site as well as staging. - Enable the plugin on the approved Jen Home production site as well as staging.

View File

@@ -27,14 +27,18 @@ Inquiries CSV columns, in order:
4. Last Name 4. Last Name
5. Referral Source 5. Referral Source
6. Referrer Name 6. Referrer Name
7. Email 7. Mobile
8. Mobile 8. Email
Submission dates use America/New_York with an explicit UTC offset. Leads exports Submission dates use America/New_York with an explicit UTC offset. Email is the
omit Source Link and retain their other existing fields. CRM views still show inquiry/property details even last column in both exports; phone fields come before it. Leads exports omit
Source Link and retain their other existing fields. CRM views still show inquiry/property details even
though the shorter Inquiries CSV omits them. Historical records are not backfilled though the shorter Inquiries CSV omits them. Historical records are not backfilled
or split; relationships use IDs, never email matching. 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 The plugin creates a prefixed `jenhome_contact_fields` extension table for middle
names and exact submission provenance. Native Houzez tables and vendor files are names and exact submission provenance. Native Houzez tables and vendor files are
not modified. Keep this table when rolling back or deactivating the plugin. not modified. Keep this table when rolling back or deactivating the plugin.
@@ -83,8 +87,10 @@ repository's Settings → Actions → Runners if retiring the computer.
1. Edit code and `CHANGELOG.md`; update both the plugin header Version and 1. Edit code and `CHANGELOG.md`; update both the plugin header Version and
`Jenhome_Contact_Exports::VERSION`. `Jenhome_Contact_Exports::VERSION`.
2. Commit and push to `main`. The workflow lints PHP, runs the standalone updater 2. Commit and push to `main`. Each push runs PHP lint, the standalone updater and
and CSV tests, and builds the ZIP. CSV tests, and builds the ZIP. WordPress checks the latest published stable
Gitea release, so a pushed commit is available to the updater after it is
validated on staging and published with its matching version tag.
3. After checks and staging validation pass, create and push a matching tag: 3. After checks and staging validation pass, create and push a matching tag:
`git tag v1.2.3` then `git push origin v1.2.3`. `git tag v1.2.3` then `git push origin v1.2.3`.
4. The tag workflow repeats checks, builds the package, uploads both assets to a 4. The tag workflow repeats checks, builds the package, uploads both assets to a

View File

@@ -121,7 +121,35 @@
document.addEventListener('submit', event => { document.addEventListener('submit', event => {
if (relevant(event.target)) { enhance(event.target); sync(event.target); } if (relevant(event.target)) { enhance(event.target); sync(event.target); }
}, true); }, 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) { $.ajaxPrefilter(function (options) {
const url = new URL(options.url, location.href); const url = new URL(options.url, location.href);
if (url.origin !== location.origin || !url.pathname.endsWith('/admin-ajax.php')) return; if (url.origin !== location.origin || !url.pathname.endsWith('/admin-ajax.php')) return;

View File

@@ -4,7 +4,7 @@
* Plugin URI: https://hostlabs.pro/ * Plugin URI: https://hostlabs.pro/
* Update URI: https://git.labs.casa/josh/jenhomeforms * Update URI: https://git.labs.casa/josh/jenhomeforms
* Description: Jen Home Houzez contact fields, inquiry ownership and protected CSV exports. * Description: Jen Home Houzez contact fields, inquiry ownership and protected CSV exports.
* Version: 1.3.0 * Version: 1.5.0
* Requires at least: 6.2 * Requires at least: 6.2
* Requires PHP: 8.1 * Requires PHP: 8.1
* Author: Josh Stevens Sr * Author: Josh Stevens Sr
@@ -13,7 +13,7 @@
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
final class Jenhome_Contact_Exports { final class Jenhome_Contact_Exports {
const VERSION = '1.3.0'; const VERSION = '1.5.0';
const INQUIRY_OWNER_ID = 7; 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']; 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. // 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', [ wp_localize_script('jenhome-contact-exports', 'JenhomeContact', [
'actions' => self::ACTIONS, 'referralForms' => self::REFERRAL_FORMS, 'actions' => self::ACTIONS, 'referralForms' => self::REFERRAL_FORMS,
'referrals' => self::referrals(), 'nonce' => wp_create_nonce('jenhome_contact'), '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') : '', 'exportNonce' => is_user_logged_in() ? wp_create_nonce('jenhome_export') : '',
]); ]);
wp_register_style('jenhome-contact-exports', false, [], self::VERSION); wp_register_style('jenhome-contact-exports', false, [], self::VERSION);
@@ -358,7 +359,7 @@ final class Jenhome_Contact_Exports {
public static function lead_rows($user_id) { public static function lead_rows($user_id) {
global $wpdb; global $wpdb;
$fields = ['time', 'first_name', 'middle_name', 'last_name', 'source', 'referrer_name', 'prefix', 'display_name', 'email', 'mobile', 'home_phone', 'work_phone', 'address', 'city', 'state', 'country', 'zipcode', 'type', 'twitter_url', 'linkedin_url', 'facebook_url', 'private_note', 'message', 'inquiry_street_address']; $fields = ['time', 'first_name', 'middle_name', 'last_name', 'source', 'referrer_name', 'prefix', 'display_name', 'mobile', 'home_phone', 'work_phone', 'address', 'city', 'state', 'country', 'zipcode', 'type', 'twitter_url', 'linkedin_url', 'facebook_url', 'private_note', 'message', 'inquiry_street_address', 'email'];
$rows = $wpdb->get_results($wpdb->prepare("SELECT l.*, f.middle_name FROM {$wpdb->prefix}houzez_crm_leads l LEFT JOIN {$wpdb->prefix}jenhome_contact_fields f ON f.lead_id=l.lead_id WHERE l.user_id = %d ORDER BY l.lead_id", $user_id), ARRAY_A); $rows = $wpdb->get_results($wpdb->prepare("SELECT l.*, f.middle_name FROM {$wpdb->prefix}houzez_crm_leads l LEFT JOIN {$wpdb->prefix}jenhome_contact_fields f ON f.lead_id=l.lead_id WHERE l.user_id = %d ORDER BY l.lead_id", $user_id), ARRAY_A);
$related = []; $related = [];
foreach (self::inquiry_records($user_id) as $inquiry) { foreach (self::inquiry_records($user_id) as $inquiry) {
@@ -377,7 +378,7 @@ final class Jenhome_Contact_Exports {
public static function export_leads() { public static function export_leads() {
self::authorize_export(); self::authorize_export();
self::write_csv('leads.csv', ['Submission Date', 'First Name', 'Middle Name', 'Last Name', 'Referral Source', 'Referrer Name', 'Prefix', 'Full Name', 'Email', 'Mobile', 'Home Phone', 'Work Phone', 'Address', 'City', 'County / State', 'Country', 'Postal Code / Zip', 'Type', 'Twitter', 'Linkedin', 'Facebook', 'Private Note', 'Message', 'Inquiry Street Address'], self::lead_rows(get_current_user_id())); self::write_csv('leads.csv', ['Submission Date', 'First Name', 'Middle Name', 'Last Name', 'Referral Source', 'Referrer Name', 'Prefix', 'Full Name', 'Mobile', 'Home Phone', 'Work Phone', 'Address', 'City', 'County / State', 'Country', 'Postal Code / Zip', 'Type', 'Twitter', 'Linkedin', 'Facebook', 'Private Note', 'Message', 'Inquiry Street Address', 'Email'], self::lead_rows(get_current_user_id()));
} }
public static function inquiry_records($user_id, $ids = null) { public static function inquiry_records($user_id, $ids = null) {
@@ -405,14 +406,14 @@ final class Jenhome_Contact_Exports {
self::submission_date($row['time'] ?? ''), self::submission_date($row['time'] ?? ''),
$row['first_name'] ?? '', $row['middle_name'] ?? '', $row['last_name'] ?? '', $row['first_name'] ?? '', $row['middle_name'] ?? '', $row['last_name'] ?? '',
self::referral_source($row), self::referrer_name($row, $meta), self::referral_source($row), self::referrer_name($row, $meta),
$row['email'] ?? '', $row['mobile'] ?? '', $row['mobile'] ?? '', $row['email'] ?? '',
]; ];
}, $rows); }, $rows);
} }
public static function export_inquiries() { public static function export_inquiries() {
self::authorize_export(); self::authorize_export();
self::write_csv('inquiries.csv', ['Submission Date', 'First Name', 'Middle Name', 'Last Name', 'Referral Source', 'Referrer Name', 'Email', 'Mobile'], self::inquiry_rows(get_current_user_id())); self::write_csv('inquiries.csv', ['Submission Date', 'First Name', 'Middle Name', 'Last Name', 'Referral Source', 'Referrer Name', 'Mobile', 'Email'], self::inquiry_rows(get_current_user_id()));
} }
} }
add_action('plugins_loaded', ['Jenhome_Contact_Exports', 'boot']); add_action('plugins_loaded', ['Jenhome_Contact_Exports', 'boot']);

View File

@@ -125,16 +125,16 @@ try {
ob_start(); try { Jenhome_Contact_Exports::export_inquiries(); } catch(Test_Die $e) {} $csv=ob_get_clean(); ob_start(); try { Jenhome_Contact_Exports::export_inquiries(); } catch(Test_Die $e) {} $csv=ob_get_clean();
$rows=explode("\r\n",substr($csv,3)); $rows=explode("\r\n",substr($csv,3));
$header=str_getcsv($rows[0],',','"',''); $row=str_getcsv($rows[1],',','"',''); $header=str_getcsv($rows[0],',','"',''); $row=str_getcsv($rows[1],',','"','');
check($header===['Submission Date','First Name','Middle Name','Last Name','Referral Source','Referrer Name','Email','Mobile'],'requested eight-column inquiry export'); check($header===['Submission Date','First Name','Middle Name','Last Name','Referral Source','Referrer Name','Mobile','Email'],'requested eight-column inquiry export with Email last');
check(count($row)===8 && $row[2]==='Anaïs' && $row[5]==='María' && $row[6]==='synthetic@example.invalid' && $row[7]==='2025550100','export values align with headings'); check(count($row)===8 && $row[2]==='Anaïs' && $row[5]==='María' && $row[6]==='2025550100' && $row[7]==='synthetic@example.invalid','export values align with headings');
check(!str_contains($csv,'DO NOT EXPORT') && !str_contains($csv,'https://staging.jenhome.net/contact/'),'removed fields and source URL absent from inquiry CSV'); check(!str_contains($csv,'DO NOT EXPORT') && !str_contains($csv,'https://staging.jenhome.net/contact/'),'removed fields and source URL absent from inquiry CSV');
check($row[0]==='2026-10-28 11:30:00 -04:00','submission date remains first and localized'); check($row[0]==='2026-10-28 11:30:00 -04:00','submission date remains first and localized');
ob_start(); try { Jenhome_Contact_Exports::export_leads(); } catch(Test_Die $e) {} $csv=ob_get_clean(); ob_start(); try { Jenhome_Contact_Exports::export_leads(); } catch(Test_Die $e) {} $csv=ob_get_clean();
$rows=explode("\r\n",substr($csv,3)); $rows=explode("\r\n",substr($csv,3));
$header=str_getcsv($rows[0],',','"',''); $row=str_getcsv($rows[1],',','"',''); $header=str_getcsv($rows[0],',','"',''); $row=str_getcsv($rows[1],',','"','');
check(count($header)===24 && count($row)===24 && !in_array('Source Link',$header,true),'lead export omits Source Link heading and value'); check($header===['Submission Date','First Name','Middle Name','Last Name','Referral Source','Referrer Name','Prefix','Full Name','Mobile','Home Phone','Work Phone','Address','City','County / State','Country','Postal Code / Zip','Type','Twitter','Linkedin','Facebook','Private Note','Message','Inquiry Street Address','Email'] && count($row)===24 && !in_array('Source Link',$header,true),'lead export has Email last and omits Source Link');
check(!str_contains($csv,'https://staging.jenhome.net/contact/'),'source URL absent from lead CSV'); check(!str_contains($csv,'https://staging.jenhome.net/contact/'),'source URL absent from lead CSV');
$lead=array_combine($header,$row); $lead=array_combine($header,$row);
check($lead['Referral Source']==='Friend' && $lead['Referrer Name']==='María' && $lead['Email']==='synthetic@example.invalid' && $lead['Mobile']==='2025550100','lead referral and contact values stay aligned'); check($lead['Referral Source']==='Friend' && $lead['Referrer Name']==='María' && $lead['Email']==='synthetic@example.invalid' && $lead['Mobile']==='2025550100' && end($row)==='synthetic@example.invalid','lead referral and contact values stay aligned with Email last');
echo "PASS: $checks updater and CSV checks\n"; echo "PASS: $checks updater and CSV checks\n";
} finally { foreach($paths as $p) if(file_exists($p)) unlink($p); } } finally { foreach($paths as $p) if(file_exists($p)) unlink($p); }