diff --git a/includes/Extensions/Batch59.php b/includes/Extensions/Batch59.php index 3afd65c..39857d7 100644 --- a/includes/Extensions/Batch59.php +++ b/includes/Extensions/Batch59.php @@ -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];