fix(Batch59): FluentSMTP stores log to PHP-serialized, not JSON — use maybe_unserialize
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
This commit is contained in:
@@ -38,6 +38,22 @@ class Batch59 {
|
||||
private static function logTable(): string { global $wpdb; return $wpdb->prefix . 'fsmpt_email_logs'; }
|
||||
private static function hasLog(): bool { global $wpdb; $t = self::logTable(); return $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $t)) === $t; }
|
||||
|
||||
/** FluentSMTP stores recipient fields PHP-serialized (sometimes JSON). Normalise to a comma list. */
|
||||
private static function emails($raw): string {
|
||||
if (is_string($raw) && $raw !== '') {
|
||||
$dec = @unserialize($raw);
|
||||
if ($dec === false && $raw !== 'b:0;') $dec = json_decode($raw, true);
|
||||
if (is_array($dec)) $raw = $dec;
|
||||
}
|
||||
if (!is_array($raw)) return (string) $raw;
|
||||
$out = [];
|
||||
foreach ($raw as $x) {
|
||||
if (is_array($x)) $out[] = $x['email'] ?? (is_scalar(reset($x)) ? reset($x) : '');
|
||||
else $out[] = (string) $x;
|
||||
}
|
||||
return implode(', ', array_filter($out));
|
||||
}
|
||||
|
||||
public static function listConnections(array $args): array {
|
||||
$s = get_option('fluentmail-settings');
|
||||
if (!is_array($s) || empty($s['connections']) || !is_array($s['connections'])) {
|
||||
@@ -74,10 +90,7 @@ class Batch59 {
|
||||
$rows = $wpdb->get_results("SELECT id, `to`, subject, status, source, retries, created_at FROM `{$t}` {$where} ORDER BY id DESC LIMIT {$per}", ARRAY_A);
|
||||
$out = [];
|
||||
foreach ((array) $rows as $r) {
|
||||
$to = $r['to'];
|
||||
$dec = json_decode($to, true);
|
||||
if (is_array($dec)) $to = implode(', ', array_map(function ($x) { return is_array($x) ? ($x['email'] ?? reset($x)) : $x; }, $dec));
|
||||
$out[] = ['id' => (int) $r['id'], 'to' => $to, 'subject' => $r['subject'], 'status' => $r['status'],
|
||||
$out[] = ['id' => (int) $r['id'], 'to' => self::emails($r['to']), 'subject' => $r['subject'], 'status' => $r['status'],
|
||||
'source' => $r['source'], 'retries' => (int) $r['retries'], 'created_at' => $r['created_at']];
|
||||
}
|
||||
return ['supported' => true, 'count' => count($out), 'logs' => $out];
|
||||
|
||||
Reference in New Issue
Block a user