fix(flamingo-helper): extract field values from _field_* meta, not _fields
Flamingo's '_fields' meta stores only the list of field NAMES with null values; the actual values live in separate per-field meta keys prefixed with '_field_'. The old extract_fields() returned the null-valued '_fields' array on the first branch and never fell through to the '_field_*' collector, so every retro Telegram message showed '(не указан)' / '(пусто)' for every slot. Also collect '_from_name' / '_from_email' (set by Akismet) as convenience mappings to 'your-name' / 'your-email' so the formatter's standard slots are populated for most submissions even when the form uses custom field names like text-211 / name_user. Pilot on washanyanya.ru caught this (retro delivered empty skeletons). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1922,20 +1922,34 @@ final class FlamingoHelper
|
|||||||
/**
|
/**
|
||||||
* Extract fields from a Flamingo inbound post.
|
* 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<string,mixed>
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public static function extract_fields(\WP_Post $post): 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);
|
$meta = get_post_meta($post->ID);
|
||||||
$out = [];
|
$out = [];
|
||||||
foreach ($meta as $key => $values) {
|
foreach ($meta as $key => $values) {
|
||||||
if (strpos($key, '_field_') === 0) {
|
if (strpos($key, '_field_') !== 0) continue;
|
||||||
$out[substr($key, strlen('_field_'))] = maybe_unserialize($values[0] ?? '');
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Convenience: expose Akismet's "from" name / email so the formatter's
|
||||||
|
// standard slots aren't empty for most submissions.
|
||||||
|
$from_name = (string)get_post_meta($post->ID, '_from_name', true);
|
||||||
|
$from_email = (string)get_post_meta($post->ID, '_from_email', true);
|
||||||
|
if ($from_name !== '' && !isset($out['your-name'])) $out['your-name'] = $from_name;
|
||||||
|
if ($from_email !== '' && !isset($out['your-email'])) $out['your-email'] = $from_email;
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,20 +34,34 @@ final class FlamingoHelper
|
|||||||
/**
|
/**
|
||||||
* Extract fields from a Flamingo inbound post.
|
* 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<string,mixed>
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public static function extract_fields(\WP_Post $post): 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);
|
$meta = get_post_meta($post->ID);
|
||||||
$out = [];
|
$out = [];
|
||||||
foreach ($meta as $key => $values) {
|
foreach ($meta as $key => $values) {
|
||||||
if (strpos($key, '_field_') === 0) {
|
if (strpos($key, '_field_') !== 0) continue;
|
||||||
$out[substr($key, strlen('_field_'))] = maybe_unserialize($values[0] ?? '');
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Convenience: expose Akismet's "from" name / email so the formatter's
|
||||||
|
// standard slots aren't empty for most submissions.
|
||||||
|
$from_name = (string)get_post_meta($post->ID, '_from_name', true);
|
||||||
|
$from_email = (string)get_post_meta($post->ID, '_from_email', true);
|
||||||
|
if ($from_name !== '' && !isset($out['your-name'])) $out['your-name'] = $from_name;
|
||||||
|
if ($from_email !== '' && !isset($out['your-email'])) $out['your-email'] = $from_email;
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user