$value) $css .= '--fqbpro-native-field-' . $property . ':' . $value . ';'; $shared = []; if (in_array($attributes['nativeLabelVisibility'] ?? '', ['show', 'hide'], true)) $shared['data-native-labels'] = $attributes['nativeLabelVisibility']; foreach (['nativeLabelCase' => 'label-case', 'nativeValueCase' => 'value-case'] as $attribute => $token) { if (in_array($attributes[$attribute] ?? '', ['none', 'uppercase', 'lowercase', 'capitalize'], true)) $css .= '--fqbpro-native-' . $token . ':' . $attributes[$attribute] . ';'; } return array_merge($shared, $values ? ['data-native-field-style' => implode(' ', array_keys($values))] : [], $css ? ['style' => $css] : []); } function register_control_renderer($args, $name) { if (in_array($name, array_map(static fn($kind) => 'filter-query-block-pro/filter-' . $kind, CONTROL_NAMES), true)) { $args['render_callback'] = __NAMESPACE__ . '\\render_control'; $args['uses_context'] = array_values(array_unique(array_merge($args['uses_context'] ?? [], [CONFIG_CONTEXT, STATE_CONTEXT, RENDER_CONTEXT]))); } return $args; } /** Unknown/nested query trees must neither render controls nor contribute state. */ function permitted_tree($blocks, $depth = 0, &$count = 0) { if ($depth > 8) return []; $result = []; foreach ($blocks as $parsed) { if (++$count > 200 || !is_array($parsed)) break; $name = $parsed['blockName'] ?? ''; if (in_array($name, ['core/group', 'core/columns', 'core/column'], true)) { $original = $parsed['innerBlocks'] ?? []; // Retain placeholders for omitted children so core layout HTML stays balanced. $children = []; foreach ($original as $child) { $accepted = permitted_tree([$child], $depth + 1, $count); $children[] = $accepted[0] ?? ['blockName' => null, 'attrs' => [], 'innerBlocks' => [], 'innerHTML' => '', 'innerContent' => ['']]; } $parsed['innerBlocks'] = $children; } elseif (!in_array($name, ['core/heading', 'core/paragraph'], true) && !in_array($name, array_map(static fn($kind) => 'filter-query-block-pro/filter-' . $kind, CONTROL_NAMES), true)) { continue; } $result[] = $parsed; } return $result; } function render_header($attributes, $block, $configuration, $state, $request) { // The 6.x router retains server DOM positions and cannot reconcile fields // moved into dialogs/menus. Use the complete GET form and native history on // those versions, including Query pagination, instead of a broken partial diff. if (version_compare(get_bloginfo('version'), '7.0', '<')) { wp_interactivity_config('core/router', ['clientNavigationDisabled' => true]); } $id = absint($configuration['queryId'] ?? 0); $style = in_array($attributes['nativeStyle'] ?? '', ['theme', 'outlined', 'soft', 'filled', 'unstyled'], true) ? $attributes['nativeStyle'] : 'theme'; $label_position = $attributes['nativeLabelPosition'] ?? ''; if (!in_array($label_position, ['top', 'start', 'end'], true)) $label_position = in_array('fqbpro-compact-filter-rows', preg_split('/\s+/', (string) ($attributes['className'] ?? '')), true) ? 'start' : 'top'; $wrapper = get_block_wrapper_attributes(array_merge(field_style_attributes($attributes), [ 'data-native-pagination' => (!defined('FQBPRO_EDITION') || FQBPRO_EDITION !== 'free') && ($attributes['paginationMode'] ?? '') === 'load-more' ? 'load-more' : 'pages', 'data-native-loading' => in_array($attributes['nativeLoading'] ?? '', ['fade', 'blur', 'skeleton', 'none'], true) ? $attributes['nativeLoading'] : 'fade', 'class' => 'fqbpro-native-filters', 'data-native-style' => $style, 'data-native-shape' => in_array($attributes['nativeShape'] ?? '', ['square', 'rounded', 'pill'], true) ? $attributes['nativeShape'] : 'theme', 'data-native-control-size' => ($attributes['nativeControlSize'] ?? '') === 'compact' ? 'compact' : 'standard', 'data-native-label-position' => $label_position, 'data-native-button-arrangement' => ($attributes['nativeButtonArrangement'] ?? '') === 'combined' ? 'combined' : 'groups', 'data-native-overflow' => ($attributes['nativeOverflow'] ?? '') === 'more' ? 'more' : 'wrap', 'data-native-presentation' => ($attributes['nativePresentation'] ?? '') === 'popup' ? 'popup' : 'inline', 'data-native-layout' => ($attributes['nativeLayout'] ?? '') === 'sidebar' ? 'sidebar' : 'inline', 'data-native-ui' => (int) ($attributes['nativeUiVersion'] ?? 0) === 1 ? '1' : '0', 'data-native-mobile' => ($attributes['nativeMobilePresentation'] ?? '') === 'dialog' ? 'dialog' : 'inline', 'data-wp-interactive' => 'filter-query-block-pro/filter-header', 'data-wp-init' => 'callbacks.initialize', 'data-wp-watch' => 'callbacks.refreshNavigation', 'data-fqbpro-query-id' => (string) $id, ])); if (!$id) return '
'; $requires_pro = in_array('requires-pro', $configuration['errors'] ?? [], true); foreach ($configuration['nativeControls'] ?? [] as $control) $requires_pro = $requires_pro || in_array('requires-pro', $control['errors'] ?? [], true); if (defined('FQBPRO_EDITION') && FQBPRO_EDITION === 'free' && !empty($block->context['query']['fqbp'])) $requires_pro = true; $summary = (int) ($attributes['nativeUiVersion'] ?? 0) === 1 ? native_summary_items($configuration, $state, $request) : []; $context = array_merge($block->context, [CONFIG_CONTEXT => $configuration, STATE_CONTEXT => $state, RENDER_CONTEXT => (object) ['ids' => [], 'summary' => $summary]]); $tree = permitted_tree($block->parsed_block['innerBlocks'] ?? []); $needs_apply = !in_array('apply', array_column($configuration['nativeControls'] ?? [], 'kind'), true); $inline_apply = $needs_apply && count($tree) === 1 && ($tree[0]['blockName'] ?? '') === 'core/group' && ($tree[0]['attrs']['layout']['type'] ?? '') === 'flex' && ($tree[0]['attrs']['layout']['orientation'] ?? 'horizontal') === 'horizontal' && ($attributes['nativeLayout'] ?? '') !== 'sidebar'; ob_start(); ?>
>

data-native-inline-apply data-popup-labels=" __('Close', 'accomplice-query-loop-filters'), 'Clear' => __('Clear', 'accomplice-query-loop-filters'), 'Apply' => __('Apply', 'accomplice-query-loop-filters'), 'Apply filters' => __('Apply filters', 'accomplice-query-loop-filters'), 'Clear filters' => __('Clear filters', 'accomplice-query-loop-filters'), 'Cancel' => __('Cancel', 'accomplice-query-loop-filters')])); ?>" data-popup-close="" data-clear-label="" data-combined-label="" data-combined-all-label="" data-more-label="" data-range-error="" data-fqbpro-query-id="" data-native-parameters="" data-auto-apply="" data-search-delay=""> render(); } if ($needs_apply) { $automatic = ($configuration['behavior']['autoApply'] ?? true) !== false; if ($automatic) echo ''; } ?>

context[CONFIG_CONTEXT] ?? []; $control_id = $attributes['controlId'] ?? ''; $descriptor = null; foreach ($configuration['nativeControls'] ?? [] as $control) { if ($control['controlId'] === $control_id) { $descriptor = $control; break; } } if (!$descriptor) return ''; $rendered = $block->context[RENDER_CONTEXT] ?? null; if ($block->name !== 'filter-query-block-pro/filter-' . $descriptor['kind'] || ($rendered && isset($rendered->ids[$control_id]))) return ''; if ($rendered) $rendered->ids[$control_id] = true; $kind = $descriptor['kind']; $settings = $descriptor['settings']; $has_all_option = $kind === 'choice' && ($settings['presentation'] ?? '') === 'buttons' && !empty($settings['multiple']); $label = $descriptor['label']; $query_id = $configuration['queryId']; $state = $block->context[STATE_CONTEXT]['nativeControls'][$control_id] ?? []; $name = Request\native_parameter_name($configuration, $control_id); $id = 'fqb-' . $query_id . '-' . $control_id; $errors = array_merge($descriptor['errors'] ?? [], $state['errors'] ?? []); $error_messages = [ 'requires-pro' => __('This saved filter requires Filter Query Block Pro. Activate Pro or remove this filter in the editor.', 'accomplice-query-loop-filters'), 'unsupported-source' => __('This filter source is no longer available.', 'accomplice-query-loop-filters'), 'unsupported-date-source' => __('This date field is unavailable or has an unsupported format.', 'accomplice-query-loop-filters'), 'reversed-range' => __('The end must be greater than or equal to the start.', 'accomplice-query-loop-filters'), ]; $errors = array_values(array_unique(array_map(static fn($code) => $error_messages[$code] ?? __('Check this filter value and try again.', 'accomplice-query-loop-filters'), $errors))); $choice_style = in_array($settings['choiceStyle'] ?? '', ['text', 'outlined', 'pill', 'underline'], true) ? ['data-choice-style' => $settings['choiceStyle']] : []; if ($kind === 'choice') { $choice_style['data-button-indicators'] = ($attributes['showButtonIndicators'] ?? false) === true ? 'true' : 'false'; $choice_style['data-button-underline'] = ($attributes['showButtonUnderline'] ?? false) === true ? 'true' : 'false'; } if ($kind === 'choice' && in_array($attributes['termCase'] ?? '', ['capitalize', 'uppercase', 'lowercase'], true)) $choice_style['data-term-case'] = $attributes['termCase']; $wrapper = get_block_wrapper_attributes(array_merge(field_style_attributes($attributes), $choice_style, ['class' => 'fqbpro-native-control is-kind-' . $kind, 'data-native-combine' => ($attributes['combineInRow'] ?? true) === false ? 'false' : 'true', 'data-show-icon' => ($attributes['showIcon'] ?? true) === false ? 'false' : 'true', 'data-control-id' => $control_id, 'data-show-label' => ($attributes['showLabel'] ?? true) === false ? 'false' : 'true', 'data-presentation' => $settings['presentation'] ?? '', 'data-wp-key' => $id])); $aria = $errors ? ' aria-invalid="true" aria-describedby="' . esc_attr($id . '-error') . '"' : ''; ob_start(); ?>
> parsed_block['attrs'] ?? []; $all_label = trim((string) ($saved_attributes['allLabel'] ?? '')); if ($all_label === '' || (empty($saved_attributes['allLabelCustom']) && in_array($all_label, ['All', __('All', 'accomplice-query-loop-filters')], true))) { $taxonomy = str_starts_with($descriptor['sourceId'], 'taxonomy:') ? get_taxonomy(substr($descriptor['sourceId'], 9)) : null; if ($presentation === 'dropdown') { $all_label = $taxonomy ? $taxonomy->labels->name : $label; } } $all_label = $all_label ?: __('All', 'accomplice-query-loop-filters'); $search_placeholder = trim((string) ($saved_attributes['searchPlaceholder'] ?? '')) ?: __('Search choices', 'accomplice-query-loop-filters'); $selected_counts = []; for ($count = 2; $count <= count($choices); $count++) { /* translators: %d: number of selected filter options. */ $selected_counts[$count] = sprintf(_n('%d selected', '%d selected', $count, 'accomplice-query-loop-filters'), $count); } $choice_label = static function ($choice) use ($settings) { $label = (string) ($choice['label'] ?? ''); return !empty($settings['showCount']) && isset($choice['count']) ? $label . ' (' . absint($choice['count']) . ')' : $label; }; /* translators: %d: number of selected filter options. */ $selected_label = __('%d selected', 'accomplice-query-loop-filters'); $choice_labels = ['selectedCounts' => $selected_counts, 'Search choices' => $search_placeholder, 'No matching choices' => __('No matching choices', 'accomplice-query-loop-filters'), 'All' => $all_label, '%d selected' => $selected_label, 'Clear selection' => __('Clear selection', 'accomplice-query-loop-filters'), 'Done' => __('Done', 'accomplice-query-loop-filters')]; if ($presentation === 'dropdown') : ?>
context[STATE_CONTEXT] ?? [], is_array($_GET ?? null) ? wp_unslash($_GET) : [], $control_id); ?> > '', 'label' => $all_label]); foreach ($choices as $index => $choice) : $choice_id = $id . '-' . $index; ?>
__('From', 'accomplice-query-loop-filters'), 'to' => __('To', 'accomplice-query-loop-filters'), ]; ?>
>
$control, 'keys' => $keys, 'state' => $value]; } $base = Request\reset_url($request, $query_id, $configuration); $items = []; foreach ($groups as $group) { $control = $group['control']; $value = $group['state']; $without = array_diff_key($params, array_flip($group['keys'])); $clear = add_query_arg($without, $base); $labels = array_column($control['choices'] ?? [], 'label', 'value'); if ($control['kind'] === 'sort') $labels = array_column($control['settings']['options'] ?? [], 'label', 'id'); $values = $control['kind'] === 'choice' ? (array) ($value['values'] ?? []) : [null]; foreach ($values as $selected) { $url = $clear; if ($selected !== null) { $remaining = array_values(array_filter($values, static fn($item) => (string) $item !== (string) $selected)); $one_removed = $params; if ($remaining) $one_removed[$group['keys'][0]] = $remaining; else unset($one_removed[$group['keys'][0]]); $url = add_query_arg($one_removed, $base); $text = $labels[$selected] ?? $selected; } elseif (isset($value['value']) && $value['value'] !== '') { $text = $labels[$value['value']] ?? $value['value']; } else { $lower = $value['from'] ?? $value['min'] ?? ''; $upper = $value['to'] ?? $value['max'] ?? ''; $text = $lower !== '' && $upper !== '' ? "$lower – $upper" : ($lower !== '' ? "≥ $lower" : "≤ $upper"); } $items[] = ['controlId' => $control['controlId'], 'label' => $control['label'] . ': ' . $text, 'url' => $url, 'clearUrl' => $clear]; } } return $items; } function render_filter_summary($configuration, $items, $request) { if (!$items) return; echo '
' . esc_html__('Clear all', 'accomplice-query-loop-filters') . '
'; }