Assign Jen Home inquiries to designated admin
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 23s
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 23s
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
## 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
|
||||
|
||||
- Remove the Source Link column and its values from both Leads and Inquiries CSVs.
|
||||
|
||||
16
README.md
16
README.md
@@ -1,6 +1,6 @@
|
||||
# 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/)
|
||||
|
||||
@@ -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,
|
||||
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:
|
||||
|
||||
1. Submission Date
|
||||
@@ -93,14 +98,15 @@ Local checks (PHP 8.1+ with ZIP support, Python 3):
|
||||
|
||||
```sh
|
||||
php tests/unit.php
|
||||
python3 scripts/build-release.py v1.2.2
|
||||
python3 scripts/build-release.py v1.3.0
|
||||
```
|
||||
|
||||
## Scope and rollback
|
||||
|
||||
The plugin runs only when both the home URL and WordPress directory identify
|
||||
`staging.jenhome.net`. Installing it on production does not enable its behavior or
|
||||
updater. A production rollout requires a separately reviewed scope change.
|
||||
The plugin runs only when the home URL and WordPress directory match one of the
|
||||
two approved installations: `staging.jenhome.net` in its staging directory or
|
||||
`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.
|
||||
Deactivate this plugin to return to native behavior, or reinstall the previous
|
||||
|
||||
@@ -102,7 +102,7 @@ final class Jenhome_Gitea_Updater {
|
||||
'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',
|
||||
'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']))],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Plugin Name: Jen Home Contact Fields and Exports
|
||||
* Plugin URI: https://hostlabs.pro/
|
||||
* Update URI: https://git.labs.casa/josh/jenhomeforms
|
||||
* Description: Staging-only Houzez name/referral capture and protected CSV exports.
|
||||
* Version: 1.2.2
|
||||
* Description: Jen Home Houzez contact fields, inquiry ownership and protected CSV exports.
|
||||
* Version: 1.3.0
|
||||
* Requires at least: 6.2
|
||||
* Requires PHP: 8.1
|
||||
* Author: Josh Stevens Sr
|
||||
@@ -13,7 +13,8 @@
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Jenhome_Contact_Exports {
|
||||
const VERSION = '1.2.2';
|
||||
const VERSION = '1.3.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.
|
||||
const REFERRAL_FORMS = ['6o0tsaob0', '1cbfa42a', '2a2beb9b'];
|
||||
@@ -24,9 +25,11 @@ final class Jenhome_Contact_Exports {
|
||||
private static $collector_wrapped = false;
|
||||
|
||||
public static function boot() {
|
||||
// Fail closed on production, including if a staging clone is later copied there.
|
||||
if (wp_parse_url(home_url(), PHP_URL_HOST) !== 'staging.jenhome.net'
|
||||
|| basename(untrailingslashit(ABSPATH)) !== 'staging.jenhome.net') return;
|
||||
// Fail closed outside the two explicitly approved Jen Home installations.
|
||||
$host = strtolower((string)wp_parse_url(home_url(), PHP_URL_HOST));
|
||||
$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';
|
||||
Jenhome_Gitea_Updater::boot(__FILE__);
|
||||
self::install_storage();
|
||||
@@ -227,11 +230,52 @@ final class Jenhome_Contact_Exports {
|
||||
$lead_id = $id;
|
||||
} else 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 : '';
|
||||
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']);
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
$meta = is_serialized($value) ? @unserialize(trim($value), ['allowed_classes' => false]) : [];
|
||||
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();
|
||||
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 {
|
||||
public $prefix='test_';
|
||||
public function prepare($query,...$args) { return $query; }
|
||||
|
||||
Reference in New Issue
Block a user