$sources[$id]['source'], 'hide_empty' => false]); if (is_wp_error($terms)) continue; $sources[$id]['terms'] = array_map(static fn($term) => [ 'id' => $term->term_id, 'slug' => $term->slug, 'name' => $term->name, 'parent' => $term->parent, 'count' => $term->count, ], $terms); } return $sources; } /** Resolve native presentation overrides without rewriting saved settings. */ function native_choice_settings($settings, $attributes) { $settings = is_array($settings) ? $settings : []; if (in_array($attributes['presentation'] ?? null, ['dropdown', 'checkbox', 'radio', 'buttons'], true)) { $settings['presentation'] = $attributes['presentation']; } if (is_bool($attributes['multiple'] ?? null)) $settings['multiple'] = $attributes['multiple']; if (str_starts_with($attributes['sourceId'] ?? '', 'taxonomy:') && isset($settings['choices'])) { $settings['choices'] = \Fqbpro\Plugin\Compatibility\Languages\term_values($settings['choices'], substr($attributes['sourceId'], 9)); } return $settings; } /** Recurse through layout blocks, stopping at nested Queries and Headers. */ function native_controls_from_tree($block) { $result = []; $nodes = 0; $walk = static function ($children, $depth = 0) use (&$walk, &$result, &$nodes) { if ($depth > 8) return; foreach ((array) $children as $child) { if (++$nodes > 200 || count($result) >= 48) return; if (!is_array($child)) continue; $name = $child['blockName'] ?? ''; if (in_array($name, ['core/query', 'filter-query-block-pro/filter-header'], true)) continue; $attrs = is_array($child['attrs'] ?? null) ? $child['attrs'] : []; $kind = substr($name, strlen('filter-query-block-pro/filter-')); if (str_starts_with($name, 'filter-query-block-pro/filter-') && in_array($kind, ['choice', 'search', 'date', 'number', 'sort', 'apply', 'reset'], true)) { $settings = $attrs['settings'] ?? []; if ($kind === 'choice') $settings = native_choice_settings($settings, $attrs); $result[] = ['controlId' => $attrs['controlId'] ?? '', 'kind' => $kind, 'sourceId' => $attrs['sourceId'] ?? '', 'label' => $attrs['label'] ?? '', ...(is_string($attrs['urlParameter'] ?? null) && $attrs['urlParameter'] !== '' ? ['urlParameter' => $attrs['urlParameter']] : []), 'settings' => $settings]; } elseif (in_array($name, ['core/group', 'core/columns', 'core/column'], true)) { $walk($child['innerBlocks'] ?? [], $depth + 1); } } }; $walk($block['innerBlocks'] ?? []); return $result; }