Files
hub-insurance/wp-content/plugins/esp-instanda-integration/esp-instanda-integration.php
T
2026-07-02 15:54:39 -06:00

124 lines
4.5 KiB
PHP

<?php
/**
* Plugin Name: ESP INSTANDA Start Quote Integration
* Plugin URI: https://getfused.com
* Description: Pushes Gravity Forms "Start a Quote" submissions into INSTANDA's Package API with write-ahead transaction logging, native entry recording, admin resubmit, and a test-mode lock. Form-agnostic - attach the feed to any form.
* Version: 1.0.7
* Requires at least: 7.0
* Requires PHP: 8.5
* Author: Getfused
* Author URI: https://getfused.com
* Text Domain: esp-instanda-integration
* License: GPL-2.0-or-later
* Gravity Forms tested up to: 2.10.4
*/
declare(strict_types=1);
namespace ESP\Instanda;
if (!defined('ABSPATH')) {
exit;
}
const MIN_PHP = '8.5';
const MIN_WP = '7.0';
const MIN_GF = '2.10.3';
const PLUGIN_FILE = __FILE__;
const CLEANUP_HOOK = 'esp_instanda_cleanup';
require_once __DIR__ . '/includes/class-guard.php';
require_once __DIR__ . '/includes/class-logger.php';
require_once __DIR__ . '/includes/class-config.php';
require_once __DIR__ . '/includes/class-transaction-store.php';
require_once __DIR__ . '/includes/class-cron-cleanup.php';
/* ------------------------------------------------------------------ activation */
\register_activation_hook(__FILE__, static function (): void {
// Create the write-ahead table; schedule daily retention cleanup.
Transaction_Store::install_table();
if (!\wp_next_scheduled(CLEANUP_HOOK)) {
\wp_schedule_event(time(), 'daily', CLEANUP_HOOK);
}
});
\register_deactivation_hook(__FILE__, static function (): void {
\wp_clear_scheduled_hook(CLEANUP_HOOK);
});
/* ------------------------------------------------------------------ guards (#5) */
/**
* Refuse to initialize on an unsupported platform - but never wp_die(). Show an
* admin notice and bail so the site stays up.
*/
function platform_blockers(): array {
$errors = [];
if (PHP_VERSION_ID < 80500) {
$errors[] = sprintf('PHP %s or newer is required (running %s).', MIN_PHP, PHP_VERSION);
}
$wp_version = $GLOBALS['wp_version'] ?? '0';
if (version_compare((string) $wp_version, MIN_WP, '<')) {
$errors[] = sprintf('WordPress %s or newer is required.', MIN_WP);
}
if (!class_exists('GFForms')) {
$errors[] = 'Gravity Forms is required and is not active.';
} elseif (version_compare((string) \GFForms::$version, MIN_GF, '<')) {
$errors[] = sprintf('Gravity Forms %s or newer is required.', MIN_GF);
}
return $errors;
}
\add_action('admin_init', static function (): void {
// Keep the schema current if the plugin was updated without re-activation.
if (empty(platform_blockers()) && Transaction_Store::needs_migration()) {
Transaction_Store::install_table();
}
});
/* ------------------------------------------------ Gravity Forms Add-On registration */
\add_action('gform_loaded', Guard::wrap(static function (): void {
if (!empty(platform_blockers()) || !method_exists('GFForms', 'include_feed_addon_framework')) {
\add_action('admin_notices', static function (): void {
$errors = platform_blockers();
if (!$errors) {
return;
}
echo '<div class="notice notice-error"><p><strong>ESP INSTANDA Integration is inactive:</strong> '
. esc_html(implode(' ', $errors)) . '</p></div>';
});
return;
}
\GFForms::include_feed_addon_framework();
require_once __DIR__ . '/includes/class-field-mapper.php';
require_once __DIR__ . '/includes/class-api-client.php';
require_once __DIR__ . '/includes/class-transaction-store.php';
require_once __DIR__ . '/includes/class-submission.php';
require_once __DIR__ . '/includes/class-entry-integration.php';
require_once __DIR__ . '/includes/class-failure-surface.php';
require_once __DIR__ . '/includes/class-notifier.php';
require_once __DIR__ . '/includes/class-go-live.php';
require_once __DIR__ . '/includes/class-transactions-table.php';
require_once __DIR__ . '/includes/class-boost-compat.php';
require_once __DIR__ . '/includes/class-instanda-addon.php';
\GFAddOn::register(Instanda_AddOn::class);
}, 5));
/* ----------------------------------------------------------------- cron cleanup */
\add_action(CLEANUP_HOOK, Guard::wrap(static function (): void {
// Retention purge of delivered-only records is implemented in M10.
if (class_exists(__NAMESPACE__ . '\\Cron_Cleanup')) {
Cron_Cleanup::run();
}
}));