PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.2
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Helpers / AuditHelper.php

AuditHelper.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.3.2, at includes/Helpers/AuditHelper.php

49 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Audit helper — the shared spine that every Easy Invoice / Pro / Addon
4 * write-path can call to record a meaningful action.
5 *
6 * Design:
7 * • Free plugin owns the calling surface (`easy_invoice_audit_log(...)`).
8 * • The call fires an action hook (`easy_invoice_audit_event`).
9 * • The Team Roles addon's AuditLogger subscribes to that hook to write
10 * a row to its custom table — but only when the addon is active.
11 * • Webhooks (and any future addon) can subscribe to the same hook to
12 * fan out to webhook subscribers / SIEM forwarders / Slack alerts.
13 *
14 * Sites without the Team Roles addon never gain a wp_easy_invoice_audit_log
15 * table — the call becomes a no-op write but the action still fires for
16 * other listeners. Behaviour identical to before for those sites.
17 */
18
19 if (!defined('ABSPATH')) {
20 exit;
21 }
22
23 if (!function_exists('easy_invoice_audit_log')) {
24 /**
25 * Record an auditable event.
26 *
27 * @param string $action Short verb key, e.g. 'invoice_sent', 'payment_refunded'. ≤ 60 chars.
28 * @param string $resource_type e.g. 'invoice', 'quote', 'payment', 'client', 'user', 'system'.
29 * @param int|string|null $resource_id Optional resource id (post ID, user ID, etc.).
30 * @param array<string,mixed> $details Free-form context. Anything sensitive (PII, card numbers) MUST be redacted by the caller.
31 */
32 function easy_invoice_audit_log(string $action, string $resource_type = '', $resource_id = null, array $details = []): void {
33 /**
34 * Fired once per auditable event.
35 *
36 * Subscribers (in order of expected interest):
37 * • EasyInvoicePro\Addons\TeamRoles\AuditLogger::log — writes the row
38 * • EasyInvoicePro\Addons\Webhooks\EventBridge — fans out 'audit.event_logged'
39 * • SIEM / Slack / external forwarders — user-installed
40 *
41 * @param string $action
42 * @param string $resource_type
43 * @param int|string|null $resource_id
44 * @param array<string,mixed> $details
45 */
46 do_action('easy_invoice_audit_event', $action, $resource_type, $resource_id, $details);
47 }
48 }
49