Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fe8914981 | ||
|
|
f63e052ccd |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,3 +1,14 @@
|
|||||||
|
## 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.
|
||||||
|
- Assign each new inquiry and its unique linked lead to WordPress user ID 7.
|
||||||
|
- Preserve the existing Houzez owner filter and avoid changing historical records.
|
||||||
|
|
||||||
## 1.2.2
|
## 1.2.2
|
||||||
|
|
||||||
- Remove the Source Link column and its values from both Leads and Inquiries CSVs.
|
- Remove the Source Link column and its values from both Leads and Inquiries CSVs.
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -1,6 +1,6 @@
|
|||||||
# Jen Home Contact Fields and Exports
|
# Jen Home Contact Fields and Exports
|
||||||
|
|
||||||
WordPress/Houzez customization for **staging.jenhome.net**.
|
WordPress/Houzez customization for **staging.jenhome.net** and **www.jenhome.net**.
|
||||||
|
|
||||||
Author: **Josh Stevens Sr** · Website: [hostLabs](https://hostlabs.pro/)
|
Author: **Josh Stevens Sr** · Website: [hostLabs](https://hostlabs.pro/)
|
||||||
|
|
||||||
@@ -14,6 +14,11 @@ answer to “How did you hear about us?”. The existing friend-name question is
|
|||||||
identified separately from a property address. Original forms, CRM persistence,
|
identified separately from a property address. Original forms, CRM persistence,
|
||||||
notifications and existing security checks remain in place.
|
notifications and existing security checks remain in place.
|
||||||
|
|
||||||
|
New inquiries are assigned to WordPress user ID 7, with the linked Houzez lead
|
||||||
|
owner updated in the same transaction. The update applies only when the new
|
||||||
|
inquiry is the lead's sole inquiry; ambiguous relationships keep their native
|
||||||
|
ownership and are logged. Existing records are never reassigned automatically.
|
||||||
|
|
||||||
Inquiries CSV columns, in order:
|
Inquiries CSV columns, in order:
|
||||||
|
|
||||||
1. Submission Date
|
1. Submission Date
|
||||||
@@ -30,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
|
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.
|
||||||
@@ -93,14 +101,15 @@ Local checks (PHP 8.1+ with ZIP support, Python 3):
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
php tests/unit.php
|
php tests/unit.php
|
||||||
python3 scripts/build-release.py v1.2.2
|
python3 scripts/build-release.py v1.3.0
|
||||||
```
|
```
|
||||||
|
|
||||||
## Scope and rollback
|
## Scope and rollback
|
||||||
|
|
||||||
The plugin runs only when both the home URL and WordPress directory identify
|
The plugin runs only when the home URL and WordPress directory match one of the
|
||||||
`staging.jenhome.net`. Installing it on production does not enable its behavior or
|
two approved installations: `staging.jenhome.net` in its staging directory or
|
||||||
updater. A production rollout requires a separately reviewed scope change.
|
`www.jenhome.net` in `httpdocs`. It also requires user ID 7 to exist as an
|
||||||
|
administrator. Other hosts and copied installations fail closed.
|
||||||
|
|
||||||
Back up the current plugin directory before the first updater installation.
|
Back up the current plugin directory before the first updater installation.
|
||||||
Deactivate this plugin to return to native behavior, or reinstall the previous
|
Deactivate this plugin to return to native behavior, or reinstall the previous
|
||||||
|
|||||||
30
forms.js
30
forms.js
@@ -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;
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ final class Jenhome_Gitea_Updater {
|
|||||||
'version' => $release['version'], 'author' => 'Josh Stevens Sr', 'author_profile' => 'https://hostlabs.pro/',
|
'version' => $release['version'], 'author' => 'Josh Stevens Sr', 'author_profile' => 'https://hostlabs.pro/',
|
||||||
'homepage' => 'https://hostlabs.pro/', 'requires' => '6.2', 'requires_php' => '8.1', 'tested' => '7.1.3',
|
'homepage' => 'https://hostlabs.pro/', 'requires' => '6.2', 'requires_php' => '8.1', 'tested' => '7.1.3',
|
||||||
'download_link' => $release['package'], 'last_updated' => $release['published_at'],
|
'download_link' => $release['package'], 'last_updated' => $release['published_at'],
|
||||||
'sections' => ['description' => 'Site-specific Houzez contact fields and CSV exports for staging.jenhome.net.',
|
'sections' => ['description' => 'Site-specific Houzez contact fields, account 7 inquiry ownership and CSV exports for Jen Home staging and production.',
|
||||||
'changelog' => wpautop(esc_html($release['body']))],
|
'changelog' => wpautop(esc_html($release['body']))],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
* Plugin Name: Jen Home Contact Fields and Exports
|
* Plugin Name: Jen Home Contact Fields and Exports
|
||||||
* 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: Staging-only Houzez name/referral capture and protected CSV exports.
|
* Description: Jen Home Houzez contact fields, inquiry ownership and protected CSV exports.
|
||||||
* Version: 1.2.2
|
* Version: 1.4.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,8 @@
|
|||||||
defined('ABSPATH') || exit;
|
defined('ABSPATH') || exit;
|
||||||
|
|
||||||
final class Jenhome_Contact_Exports {
|
final class Jenhome_Contact_Exports {
|
||||||
const VERSION = '1.2.2';
|
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'];
|
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.
|
||||||
const REFERRAL_FORMS = ['6o0tsaob0', '1cbfa42a', '2a2beb9b'];
|
const REFERRAL_FORMS = ['6o0tsaob0', '1cbfa42a', '2a2beb9b'];
|
||||||
@@ -24,9 +25,11 @@ final class Jenhome_Contact_Exports {
|
|||||||
private static $collector_wrapped = false;
|
private static $collector_wrapped = false;
|
||||||
|
|
||||||
public static function boot() {
|
public static function boot() {
|
||||||
// Fail closed on production, including if a staging clone is later copied there.
|
// Fail closed outside the two explicitly approved Jen Home installations.
|
||||||
if (wp_parse_url(home_url(), PHP_URL_HOST) !== 'staging.jenhome.net'
|
$host = strtolower((string)wp_parse_url(home_url(), PHP_URL_HOST));
|
||||||
|| basename(untrailingslashit(ABSPATH)) !== 'staging.jenhome.net') return;
|
$roots = ['staging.jenhome.net' => 'staging.jenhome.net', 'www.jenhome.net' => 'httpdocs'];
|
||||||
|
if (!isset($roots[$host]) || basename(untrailingslashit(ABSPATH)) !== $roots[$host]
|
||||||
|
|| !get_userdata(self::INQUIRY_OWNER_ID) || !user_can(self::INQUIRY_OWNER_ID, 'manage_options')) return;
|
||||||
require_once __DIR__ . '/gitea-updater.php';
|
require_once __DIR__ . '/gitea-updater.php';
|
||||||
Jenhome_Gitea_Updater::boot(__FILE__);
|
Jenhome_Gitea_Updater::boot(__FILE__);
|
||||||
self::install_storage();
|
self::install_storage();
|
||||||
@@ -77,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);
|
||||||
@@ -227,11 +231,52 @@ final class Jenhome_Contact_Exports {
|
|||||||
$lead_id = $id;
|
$lead_id = $id;
|
||||||
} else return;
|
} else return;
|
||||||
if (!$lead_id) return;
|
if (!$lead_id) return;
|
||||||
|
if ($enquiry_id) self::assign_inquiry_owner($lead_id, $enquiry_id);
|
||||||
$form = $enquiry_id && self::input('is_estimation') === 'yes' && empty($_POST['listing_id']) ? self::$referrer_form : '';
|
$form = $enquiry_id && self::input('is_estimation') === 'yes' && empty($_POST['listing_id']) ? self::$referrer_form : '';
|
||||||
if (self::$middle_name === '' && $form === '') return;
|
if (self::$middle_name === '' && $form === '') return;
|
||||||
$wpdb->insert($wpdb->prefix . 'jenhome_contact_fields', ['lead_id' => $lead_id, 'enquiry_id' => $enquiry_id, 'middle_name' => self::$middle_name, 'referrer_form' => $form], ['%d', '%d', '%s', '%s']);
|
$wpdb->insert($wpdb->prefix . 'jenhome_contact_fields', ['lead_id' => $lead_id, 'enquiry_id' => $enquiry_id, 'middle_name' => self::$middle_name, 'referrer_form' => $form], ['%d', '%d', '%s', '%s']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Keep the native inquiry/lead relationship intact while assigning only this new inquiry. */
|
||||||
|
private static function assign_inquiry_owner($lead_id, $enquiry_id) {
|
||||||
|
global $wpdb;
|
||||||
|
$leads = $wpdb->prefix . 'houzez_crm_leads';
|
||||||
|
$inquiries = $wpdb->prefix . 'houzez_crm_enquiries';
|
||||||
|
$row = $wpdb->get_row($wpdb->prepare(
|
||||||
|
"SELECT e.user_id AS enquiry_user_id,l.user_id AS lead_user_id,(SELECT COUNT(*) FROM $inquiries x WHERE x.lead_id=e.lead_id) AS inquiry_count FROM $inquiries e JOIN $leads l ON l.lead_id=e.lead_id WHERE e.enquiry_id=%d AND e.lead_id=%d",
|
||||||
|
$enquiry_id, $lead_id
|
||||||
|
));
|
||||||
|
if (!$row || (int)$row->inquiry_count !== 1) {
|
||||||
|
error_log('Jen Home Contact Fields: skipped inquiry ownership update because its new inquiry/lead relationship was not unique.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$old_enquiry_owner = (int)$row->enquiry_user_id;
|
||||||
|
$old_lead_owner = (int)$row->lead_user_id;
|
||||||
|
if ($old_enquiry_owner === self::INQUIRY_OWNER_ID && $old_lead_owner === self::INQUIRY_OWNER_ID) return true;
|
||||||
|
if ($wpdb->query('START TRANSACTION') === false) {
|
||||||
|
error_log('Jen Home Contact Fields: could not start inquiry ownership transaction.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$lead_updated = $old_lead_owner === self::INQUIRY_OWNER_ID ? 0 : $wpdb->update(
|
||||||
|
$leads, ['user_id' => self::INQUIRY_OWNER_ID], ['lead_id' => $lead_id, 'user_id' => $old_lead_owner], ['%d'], ['%d', '%d']
|
||||||
|
);
|
||||||
|
$enquiry_updated = $old_enquiry_owner === self::INQUIRY_OWNER_ID ? 0 : $wpdb->update(
|
||||||
|
$inquiries, ['user_id' => self::INQUIRY_OWNER_ID], ['enquiry_id' => $enquiry_id, 'lead_id' => $lead_id, 'user_id' => $old_enquiry_owner], ['%d'], ['%d', '%d', '%d']
|
||||||
|
);
|
||||||
|
if (($old_lead_owner !== self::INQUIRY_OWNER_ID && $lead_updated !== 1)
|
||||||
|
|| ($old_enquiry_owner !== self::INQUIRY_OWNER_ID && $enquiry_updated !== 1)) {
|
||||||
|
$wpdb->query('ROLLBACK');
|
||||||
|
error_log('Jen Home Contact Fields: inquiry ownership update failed; changes were rolled back.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($wpdb->query('COMMIT') === false) {
|
||||||
|
$wpdb->query('ROLLBACK');
|
||||||
|
error_log('Jen Home Contact Fields: inquiry ownership commit failed.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static function meta($value) {
|
public static function meta($value) {
|
||||||
$meta = is_serialized($value) ? @unserialize(trim($value), ['allowed_classes' => false]) : [];
|
$meta = is_serialized($value) ? @unserialize(trim($value), ['allowed_classes' => false]) : [];
|
||||||
return is_array($meta) ? $meta : [];
|
return is_array($meta) ? $meta : [];
|
||||||
|
|||||||
@@ -93,6 +93,24 @@ try {
|
|||||||
$GLOBALS['responses'][$info['checksum_url']]=['status'=>200,'body'=>'not a checksum']; Jenhome_Gitea_Updater::clear();
|
$GLOBALS['responses'][$info['checksum_url']]=['status'=>200,'body'=>'not a checksum']; Jenhome_Gitea_Updater::clear();
|
||||||
check(Jenhome_Gitea_Updater::latest()===false,'invalid checksum metadata not advertised');
|
check(Jenhome_Gitea_Updater::latest()===false,'invalid checksum metadata not advertised');
|
||||||
|
|
||||||
|
$GLOBALS['wpdb']=new class {
|
||||||
|
public $prefix='test_'; public $state=['enquiry_user_id'=>1,'lead_user_id'=>1,'inquiry_count'=>1]; public $updates=[]; public $transactions=[];
|
||||||
|
public function prepare($query,...$args) { return $query; }
|
||||||
|
public function get_row($query) { return (object)$this->state; }
|
||||||
|
public function query($sql) { $this->transactions[]=$sql; return 1; }
|
||||||
|
public function update($table,$data,$where,$formats,$where_formats) {
|
||||||
|
$this->updates[]=$table;
|
||||||
|
if (str_ends_with($table,'houzez_crm_leads')) $this->state['lead_user_id']=$data['user_id'];
|
||||||
|
if (str_ends_with($table,'houzez_crm_enquiries')) $this->state['enquiry_user_id']=$data['user_id'];
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$assign = new ReflectionMethod(Jenhome_Contact_Exports::class,'assign_inquiry_owner'); $assign->setAccessible(true);
|
||||||
|
check($assign->invoke(null,11,10)===true && $GLOBALS['wpdb']->state['lead_user_id']===7 && $GLOBALS['wpdb']->state['enquiry_user_id']===7,'new inquiry and its unique lead are assigned together');
|
||||||
|
check($GLOBALS['wpdb']->transactions===['START TRANSACTION','COMMIT'],'inquiry owner update commits as one transaction');
|
||||||
|
$GLOBALS['wpdb']->state=['enquiry_user_id'=>1,'lead_user_id'=>1,'inquiry_count'=>2]; $GLOBALS['wpdb']->transactions=[];
|
||||||
|
check($assign->invoke(null,11,10)===false && $GLOBALS['wpdb']->transactions===[],'ambiguous reused lead is not reassigned');
|
||||||
|
|
||||||
$GLOBALS['wpdb']=new class {
|
$GLOBALS['wpdb']=new class {
|
||||||
public $prefix='test_';
|
public $prefix='test_';
|
||||||
public function prepare($query,...$args) { return $query; }
|
public function prepare($query,...$args) { return $query; }
|
||||||
|
|||||||
Reference in New Issue
Block a user