From f24cadc7990d420160980f65eda4d37068f9bfc1 Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Fri, 17 Apr 2026 22:42:38 +0500 Subject: [PATCH] feat(flamingo-helper): locate flamingo_inbound posts and extract fields/reason --- includes/class-flamingo-helper.php | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 includes/class-flamingo-helper.php diff --git a/includes/class-flamingo-helper.php b/includes/class-flamingo-helper.php new file mode 100644 index 0000000..2030524 --- /dev/null +++ b/includes/class-flamingo-helper.php @@ -0,0 +1,60 @@ + '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. + * + * @return array + */ + public static function extract_fields(\WP_Post $post): array + { + $fields = get_post_meta($post->ID, '_fields', true); + if (is_array($fields)) return $fields; + // Fallback: meta stored under Flamingo's structure + $meta = get_post_meta($post->ID); + $out = []; + foreach ($meta as $key => $values) { + if (strpos($key, '_field_') === 0) { + $out[substr($key, strlen('_field_'))] = maybe_unserialize($values[0] ?? ''); + } + } + 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 'Неизвестно'; + } +}