'flamingo_inbound', 'post_status' => ['flamingo-spam', 'flamingo-inbound', 'publish'], 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', 'date_query' => [[ 'after' => gmdate('Y-m-d H:i:s', time() - 30), 'inclusive' => true, ]], ]); if (!$posts) return null; // Prefer the first (most recent) — Flamingo writes one row per submission. return (int)$posts[0]->ID; } /** * Extract fields from a Flamingo inbound post. * * Flamingo's '_fields' meta stores only the field *names* with null values; * the actual values live in per-field meta keys prefixed with '_field_'. * Collect them directly. * * @return array */ public static function extract_fields(\WP_Post $post): array { $meta = get_post_meta($post->ID); $out = []; foreach ($meta as $key => $values) { if (strpos($key, '_field_') !== 0) continue; $name = substr($key, strlen('_field_')); $raw = $values[0] ?? ''; $val = maybe_unserialize($raw); if (is_array($val)) { $val = implode(', ', array_map('strval', $val)); } if ((string)$val !== '') { $out[$name] = $val; } } // Flamingo's "_from_name" and "_from_email" are derived heuristically // from whatever field the plugin considers the "first" — on custom // forms without dedicated email / name fields this produces garbage // (e.g. phone number under _from_email). Only trust _from_email if // it actually looks like an email; _from_name is not trustworthy at // all, so leave it to FieldDetector (run by Classifier / Message- // Formatter) to identify a name from any field value. $from_email = (string)get_post_meta($post->ID, '_from_email', true); if ($from_email !== '' && strpos($from_email, '@') !== false && !isset($out['your-email'])) { $out['your-email'] = $from_email; } return $out; } public static function extract_reason(\WP_Post $post): string { $log = (string)get_post_meta($post->ID, '_akismet', true); if ($log !== '') return 'Akismet'; return 'Неизвестно'; } }