preview ) && method_exists( $elementor->preview, 'is_preview_mode' ) && $elementor->preview->is_preview_mode() ) { return true; } if ( isset( $elementor->editor ) && method_exists( $elementor->editor, 'is_edit_mode' ) && $elementor->editor->is_edit_mode() ) { return true; } return false; } function acewpcf_late_inline_style_blocks( $style_block = null, $flush = false ) { static $blocks = array(); if ( $flush ) { $pending = $blocks; $blocks = array(); return $pending; } $style_block = trim( (string) $style_block ); if ( '' !== $style_block ) { $blocks[ md5( $style_block ) ] = $style_block; } return $blocks; } function acewpcf_print_late_styles() { if ( ! wp_style_is( 'acewpcf-filter-style', 'done' ) ) { if ( ! wp_style_is( 'acewpcf-filter-style', 'registered' ) ) { acewpcf_register_assets(); } if ( ! wp_style_is( 'acewpcf-filter-style', 'enqueued' ) ) { wp_enqueue_style( 'acewpcf-filter-style' ); } wp_print_styles( array( 'acewpcf-filter-style' ) ); } foreach ( acewpcf_late_inline_style_blocks( null, true ) as $hash => $css ) { $handle = 'acewpcf-filter-inline-' . substr( (string) $hash, 0, 12 ); if ( ! wp_style_is( $handle, 'registered' ) ) { wp_register_style( $handle, false, array( 'acewpcf-filter-style' ), ACEWPCF_VERSION ); wp_add_inline_style( $handle, wp_strip_all_tags( $css ) ); } if ( ! wp_style_is( $handle, 'done' ) ) { wp_enqueue_style( $handle ); wp_print_styles( array( $handle ) ); } } } function acewpcf_should_print_filter_styles_immediately() { if ( wp_doing_ajax() ) { return true; } if ( did_action( 'wp_head' ) ) { return true; } return acewpcf_is_elementor_edit_or_preview() && did_action( 'admin_head' ); } function acewpcf_prefix_late_filter_styles( $html ) { $html = (string) $html; if ( '' === $html || ! acewpcf_should_print_filter_styles_immediately() ) { return $html; } ob_start(); acewpcf_print_late_styles(); return ob_get_clean() . $html; } function acewpcf_enqueue_assets() { static $assets_enqueued = false; if ( ! wp_style_is( 'acewpcf-filter-style', 'registered' ) || ! wp_script_is( 'acewpcf-filter-script', 'registered' ) ) { acewpcf_register_assets(); } if ( $assets_enqueued ) { return; } $assets_enqueued = true; wp_enqueue_style( 'acewpcf-filter-style' ); wp_enqueue_script( 'acewpcf-filter-script' ); wp_localize_script( 'acewpcf-filter-script', 'acewpcfFilterI18n', array( 'noResultsMessage' => __( 'No results were found matching your selection.', 'ace-content-filters' ), ) ); } function acewpcf_enqueue_google_font_stylesheet( $styles, $style_keys ) { static $loaded_urls = array(); if ( ! acewpcf_google_fonts_are_enabled() ) { return; } $styles = is_array( $styles ) ? $styles : array(); $style_keys = is_array( $style_keys ) ? $style_keys : array(); $families = array(); foreach ( $style_keys as $style_key ) { if ( empty( $styles[ $style_key ] ) ) { continue; } $family = acewpcf_get_google_font_family_name( $styles[ $style_key ] ); if ( '' !== $family ) { $families[] = $family; } } $url = acewpcf_get_google_fonts_url( $families ); if ( '' === $url || isset( $loaded_urls[ $url ] ) ) { return; } $loaded_urls[ $url ] = true; $handle = 'cpcf-fonts-' . substr( md5( $url ), 0, 12 ); wp_enqueue_style( $handle, $url, array(), substr( md5( $url ), 0, 12 ) ); if ( did_action( 'wp_head' ) ) { add_action( 'wp_footer', static function () use ( $handle ) { if ( ! wp_style_is( $handle, 'done' ) ) { wp_print_styles( array( $handle ) ); } }, 1 ); } } function acewpcf_enqueue_filter_font_stylesheet( $filter ) { $styles = isset( $filter['styles'] ) && is_array( $filter['styles'] ) ? $filter['styles'] : array(); acewpcf_enqueue_google_font_stylesheet( $styles, array( 'label_font_family', 'panel_heading_font_family', 'count_font_family', 'button_font_family', 'term_search_font_family' ) ); } function acewpcf_enqueue_panel_font_stylesheet( $panel ) { $styles = isset( $panel['styles'] ) && is_array( $panel['styles'] ) ? $panel['styles'] : array(); acewpcf_enqueue_google_font_stylesheet( $styles, array( 'mobile_toggle_font_family', 'group_header_font_family' ) ); } function acewpcf_enqueue_inline_style_block( $style_block ) { static $enqueued_blocks = array(); $style_block = trim( (string) $style_block ); if ( '' === $style_block ) { return; } acewpcf_enqueue_assets(); $style_hash = md5( $style_block ); if ( isset( $enqueued_blocks[ $style_hash ] ) ) { return; } $enqueued_blocks[ $style_hash ] = true; if ( wp_style_is( 'acewpcf-filter-style', 'done' ) ) { acewpcf_late_inline_style_blocks( $style_block ); return; } wp_add_inline_style( 'acewpcf-filter-style', $style_block ); } function acewpcf_build_css_rule( $selector, $declarations ) { if ( empty( $declarations ) ) { return ''; } return $selector . '{' . implode( ';', $declarations ) . ';}'; } function acewpcf_style_value_is_set( $value ) { return '' !== trim( (string) $value ); } function acewpcf_append_panel_button_style_rules( &$rules, $scope, $selector, $hover_selector, $styles, $prefix ) { $styles = is_array( $styles ) ? $styles : array(); $base_declarations = array(); $hover_declarations = array(); $base_declarations[] = 'font-style:normal'; if ( ! empty( $styles[ $prefix . '_text_color' ] ) ) { $base_declarations[] = 'color:' . $styles[ $prefix . '_text_color' ]; } if ( ! empty( $styles[ $prefix . '_background_color' ] ) ) { $base_declarations[] = 'background:' . $styles[ $prefix . '_background_color' ]; } if ( ! empty( $styles[ $prefix . '_border_color' ] ) ) { $base_declarations[] = 'border-color:' . $styles[ $prefix . '_border_color' ]; } if ( isset( $styles[ $prefix . '_border_width' ] ) && acewpcf_style_value_is_set( $styles[ $prefix . '_border_width' ] ) ) { $base_declarations[] = 'border-width:' . absint( $styles[ $prefix . '_border_width' ] ) . 'px'; } if ( isset( $styles[ $prefix . '_padding_y' ] ) && acewpcf_style_value_is_set( $styles[ $prefix . '_padding_y' ] ) ) { $base_declarations[] = 'padding-top:' . absint( $styles[ $prefix . '_padding_y' ] ) . 'px'; $base_declarations[] = 'padding-bottom:' . absint( $styles[ $prefix . '_padding_y' ] ) . 'px'; } if ( isset( $styles[ $prefix . '_padding_x' ] ) && acewpcf_style_value_is_set( $styles[ $prefix . '_padding_x' ] ) ) { $base_declarations[] = 'padding-left:' . absint( $styles[ $prefix . '_padding_x' ] ) . 'px'; $base_declarations[] = 'padding-right:' . absint( $styles[ $prefix . '_padding_x' ] ) . 'px'; } if ( isset( $styles[ $prefix . '_border_radius' ] ) && acewpcf_style_value_is_set( $styles[ $prefix . '_border_radius' ] ) ) { $base_declarations[] = 'border-radius:' . absint( $styles[ $prefix . '_border_radius' ] ) . 'px'; } acewpcf_append_typography_declarations( $base_declarations, $styles, $prefix ); $base_rule = acewpcf_build_css_rule( $scope . ' ' . $selector, $base_declarations ); if ( '' !== $base_rule ) { $rules[] = $base_rule; } if ( ! empty( $styles[ $prefix . '_hover_text_color' ] ) ) { $hover_declarations[] = 'color:' . $styles[ $prefix . '_hover_text_color' ]; } if ( ! empty( $styles[ $prefix . '_hover_background_color' ] ) ) { $hover_declarations[] = 'background:' . $styles[ $prefix . '_hover_background_color' ]; } if ( ! empty( $styles[ $prefix . '_hover_border_color' ] ) ) { $hover_declarations[] = 'border-color:' . $styles[ $prefix . '_hover_border_color' ]; } $hover_rule = acewpcf_build_css_rule( $scope . ' ' . $hover_selector, $hover_declarations ); if ( '' !== $hover_rule ) { $rules[] = $hover_rule; } } function acewpcf_append_typography_declarations( &$declarations, $styles, $prefix ) { $font_family = isset( $styles[ $prefix . '_font_family' ] ) ? acewpcf_get_font_family_css_value( $styles[ $prefix . '_font_family' ] ) : ''; $font_weight = isset( $styles[ $prefix . '_font_weight' ] ) ? trim( (string) $styles[ $prefix . '_font_weight' ] ) : ''; $font_size = isset( $styles[ $prefix . '_font_size' ] ) ? trim( (string) $styles[ $prefix . '_font_size' ] ) : ''; $letter_spacing = isset( $styles[ $prefix . '_letter_spacing' ] ) ? trim( (string) $styles[ $prefix . '_letter_spacing' ] ) : ''; $text_transform = isset( $styles[ $prefix . '_text_transform' ] ) ? trim( (string) $styles[ $prefix . '_text_transform' ] ) : ''; if ( '' !== $font_family ) { $declarations[] = 'font-family:' . $font_family; } if ( '' !== $font_weight ) { $declarations[] = 'font-weight:' . $font_weight; } if ( '' !== $font_size ) { $declarations[] = 'font-size:' . $font_size . 'px'; } if ( '' !== $letter_spacing ) { $declarations[] = 'letter-spacing:' . $letter_spacing . 'px'; } if ( '' !== $text_transform ) { $declarations[] = 'text-transform:' . $text_transform; } } function acewpcf_get_filter_responsive_style_block( $filter ) { $styles = isset( $filter['styles'] ) && is_array( $filter['styles'] ) ? $filter['styles'] : array(); $responsive = isset( $styles['responsive'] ) && is_array( $styles['responsive'] ) ? $styles['responsive'] : array(); $scope = '.cpcf-filter--' . sanitize_html_class( $filter['id'] ); $responsive_rules = array(); foreach ( acewpcf_get_responsive_style_modes() as $mode_key => $mode ) { $mode_styles = isset( $responsive[ $mode_key ] ) && is_array( $responsive[ $mode_key ] ) ? $responsive[ $mode_key ] : array(); $mode_rules = array(); $container_declarations = array(); if ( isset( $mode_styles['gap'] ) && acewpcf_style_value_is_set( $mode_styles['gap'] ) ) { $container_declarations[] = 'gap:' . absint( $mode_styles['gap'] ) . 'px'; } $container_rule = acewpcf_build_css_rule( $scope, $container_declarations ); if ( '' !== $container_rule ) { $mode_rules[] = $container_rule; } $button_declarations = array(); if ( isset( $mode_styles['button_padding_y'] ) && acewpcf_style_value_is_set( $mode_styles['button_padding_y'] ) ) { $button_declarations[] = 'padding-top:' . absint( $mode_styles['button_padding_y'] ) . 'px'; $button_declarations[] = 'padding-bottom:' . absint( $mode_styles['button_padding_y'] ) . 'px'; } if ( isset( $mode_styles['button_padding_x'] ) && acewpcf_style_value_is_set( $mode_styles['button_padding_x'] ) ) { $button_declarations[] = 'padding-left:' . absint( $mode_styles['button_padding_x'] ) . 'px'; $button_declarations[] = 'padding-right:' . absint( $mode_styles['button_padding_x'] ) . 'px'; } $button_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__button, ' . $scope . ' .cpcf-filter__mobile-toggle', $button_declarations ); if ( '' !== $button_rule ) { $mode_rules[] = $button_rule; } $label_declarations = array(); if ( isset( $mode_styles['label_font_size'] ) && acewpcf_style_value_is_set( $mode_styles['label_font_size'] ) ) { $label_declarations[] = 'font-size:' . absint( $mode_styles['label_font_size'] ) . 'px'; } $label_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__label', $label_declarations ); if ( '' !== $label_rule ) { $mode_rules[] = $label_rule; } $panel_heading_declarations = array(); if ( isset( $mode_styles['panel_heading_font_size'] ) && acewpcf_style_value_is_set( $mode_styles['panel_heading_font_size'] ) ) { $panel_heading_declarations[] = 'font-size:' . absint( $mode_styles['panel_heading_font_size'] ) . 'px'; } elseif ( isset( $mode_styles['label_font_size'] ) && acewpcf_style_value_is_set( $mode_styles['label_font_size'] ) ) { $panel_heading_declarations[] = 'font-size:' . absint( $mode_styles['label_font_size'] ) . 'px'; } $panel_heading_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__panel-heading', $panel_heading_declarations ); if ( '' !== $panel_heading_rule ) { $mode_rules[] = $panel_heading_rule; } $count_declarations = array(); if ( isset( $mode_styles['count_font_size'] ) && acewpcf_style_value_is_set( $mode_styles['count_font_size'] ) ) { $count_declarations[] = 'font-size:' . absint( $mode_styles['count_font_size'] ) . 'px'; } $count_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__count', $count_declarations ); if ( '' !== $count_rule ) { $mode_rules[] = $count_rule; } if ( empty( $mode_rules ) ) { continue; } $responsive_rules[] = '@media (max-width: ' . absint( $mode['max_width'] ) . 'px){' . implode( '', $mode_rules ) . '}'; } return implode( "\n", $responsive_rules ); } function acewpcf_get_filter_style_block( $filter ) { $styles = isset( $filter['styles'] ) && is_array( $filter['styles'] ) ? $filter['styles'] : array(); $scope = '.cpcf-filter--' . sanitize_html_class( $filter['id'] ); $rules = array(); $container_declarations = array(); if ( isset( $styles['gap'] ) && acewpcf_style_value_is_set( $styles['gap'] ) ) { $container_declarations[] = 'gap:' . absint( $styles['gap'] ) . 'px'; } $button_declarations = array(); if ( ! empty( $styles['label_color'] ) ) { $button_declarations[] = 'color:' . $styles['label_color']; } elseif ( ! empty( $styles['count_color'] ) ) { $button_declarations[] = 'color:' . $styles['count_color']; } if ( ! empty( $styles['button_background_color'] ) ) { $button_declarations[] = 'background:' . $styles['button_background_color']; } if ( ! empty( $styles['button_border_color'] ) ) { $button_declarations[] = 'border-color:' . $styles['button_border_color']; } if ( isset( $styles['button_border_width'] ) && acewpcf_style_value_is_set( $styles['button_border_width'] ) ) { $button_declarations[] = 'border-width:' . absint( $styles['button_border_width'] ) . 'px'; } if ( isset( $styles['checkbox_size'] ) && acewpcf_style_value_is_set( $styles['checkbox_size'] ) ) { $container_declarations[] = '--cpcf-checkbox-size:' . absint( $styles['checkbox_size'] ) . 'px'; } if ( isset( $styles['checkbox_border_width'] ) && acewpcf_style_value_is_set( $styles['checkbox_border_width'] ) ) { $container_declarations[] = '--cpcf-checkbox-border-width:' . absint( $styles['checkbox_border_width'] ) . 'px'; } if ( isset( $styles['checkbox_border_radius'] ) && acewpcf_style_value_is_set( $styles['checkbox_border_radius'] ) ) { $container_declarations[] = '--cpcf-checkbox-radius:' . absint( $styles['checkbox_border_radius'] ) . 'px'; } $container_rule = acewpcf_build_css_rule( $scope, $container_declarations ); if ( '' !== $container_rule ) { $rules[] = $container_rule; } if ( isset( $styles['border_radius'] ) && acewpcf_style_value_is_set( $styles['border_radius'] ) ) { $button_declarations[] = 'border-radius:' . absint( $styles['border_radius'] ) . 'px'; } if ( isset( $styles['button_padding_y'] ) && acewpcf_style_value_is_set( $styles['button_padding_y'] ) ) { $button_declarations[] = 'padding-top:' . absint( $styles['button_padding_y'] ) . 'px'; $button_declarations[] = 'padding-bottom:' . absint( $styles['button_padding_y'] ) . 'px'; } if ( isset( $styles['button_padding_x'] ) && acewpcf_style_value_is_set( $styles['button_padding_x'] ) ) { $button_declarations[] = 'padding-left:' . absint( $styles['button_padding_x'] ) . 'px'; $button_declarations[] = 'padding-right:' . absint( $styles['button_padding_x'] ) . 'px'; } $button_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__button, ' . $scope . ' .cpcf-filter__mobile-toggle', $button_declarations ); if ( '' !== $button_rule ) { $rules[] = $button_rule; } $active_declarations = array(); if ( ! empty( $styles['active_text_color'] ) ) { $active_declarations[] = 'color:' . $styles['active_text_color']; } if ( ! empty( $styles['active_background_color'] ) ) { $active_declarations[] = 'background:' . $styles['active_background_color']; } if ( ! empty( $styles['active_border_color'] ) ) { $active_declarations[] = 'border-color:' . $styles['active_border_color']; } $active_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__button.is-active, ' . $scope . ' .cpcf-filter__choice.is-active .cpcf-filter__button, ' . $scope . ' .cpcf-filter__mobile-toggle.is-selected', $active_declarations ); if ( '' !== $active_rule ) { $rules[] = $active_rule; } if ( ! empty( $styles['active_text_color'] ) ) { $active_text_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__button.is-active .cpcf-filter__label, ' . $scope . ' .cpcf-filter__button.is-active .cpcf-filter__count, ' . $scope . ' .cpcf-filter__choice.is-active .cpcf-filter__label, ' . $scope . ' .cpcf-filter__choice.is-active .cpcf-filter__count, ' . $scope . ' .cpcf-filter__mobile-toggle.is-selected .cpcf-filter__label, ' . $scope . ' .cpcf-filter__mobile-toggle.is-selected .cpcf-filter__count', array( 'color:' . $styles['active_text_color'] ) ); if ( '' !== $active_text_rule ) { $rules[] = $active_text_rule; } } $hover_declarations = array(); if ( ! empty( $styles['button_hover_text_color'] ) ) { $hover_declarations[] = 'color:' . $styles['button_hover_text_color']; } if ( ! empty( $styles['button_hover_background_color'] ) ) { $hover_declarations[] = 'background:' . $styles['button_hover_background_color']; } if ( ! empty( $styles['button_hover_border_color'] ) ) { $hover_declarations[] = 'border-color:' . $styles['button_hover_border_color']; } $hover_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__button:not(.is-active):hover, ' . $scope . ' .cpcf-filter__choice:not(.is-active):hover .cpcf-filter__button, ' . $scope . ' .cpcf-filter__mobile-toggle:not(.is-selected):hover', $hover_declarations ); if ( '' !== $hover_rule ) { $rules[] = $hover_rule; } if ( ! empty( $styles['button_hover_text_color'] ) ) { $hover_text_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__button:not(.is-active):hover .cpcf-filter__label, ' . $scope . ' .cpcf-filter__button:not(.is-active):hover .cpcf-filter__count, ' . $scope . ' .cpcf-filter__choice:not(.is-active):hover .cpcf-filter__label, ' . $scope . ' .cpcf-filter__choice:not(.is-active):hover .cpcf-filter__count, ' . $scope . ' .cpcf-filter__mobile-toggle:not(.is-selected):hover .cpcf-filter__label, ' . $scope . ' .cpcf-filter__mobile-toggle:not(.is-selected):hover .cpcf-filter__count', array( 'color:' . $styles['button_hover_text_color'] ) ); if ( '' !== $hover_text_rule ) { $rules[] = $hover_text_rule; } } $label_declarations = array(); if ( ! empty( $styles['label_color'] ) ) { $label_declarations[] = 'color:' . $styles['label_color']; } acewpcf_append_typography_declarations( $label_declarations, $styles, 'label' ); $label_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__label', $label_declarations ); if ( '' !== $label_rule ) { $rules[] = $label_rule; } $panel_heading_declarations = array(); $panel_heading_styles = array( 'panel_heading_font_family' => ! empty( $styles['panel_heading_font_family'] ) ? $styles['panel_heading_font_family'] : ( isset( $styles['label_font_family'] ) ? $styles['label_font_family'] : '' ), 'panel_heading_font_weight' => ! empty( $styles['panel_heading_font_weight'] ) ? $styles['panel_heading_font_weight'] : ( isset( $styles['label_font_weight'] ) ? $styles['label_font_weight'] : '' ), 'panel_heading_font_size' => ( isset( $styles['panel_heading_font_size'] ) && acewpcf_style_value_is_set( $styles['panel_heading_font_size'] ) ) ? $styles['panel_heading_font_size'] : ( isset( $styles['label_font_size'] ) ? $styles['label_font_size'] : '' ), 'panel_heading_letter_spacing' => ! empty( $styles['panel_heading_letter_spacing'] ) ? $styles['panel_heading_letter_spacing'] : ( isset( $styles['label_letter_spacing'] ) ? $styles['label_letter_spacing'] : '' ), 'panel_heading_text_transform' => ! empty( $styles['panel_heading_text_transform'] ) ? $styles['panel_heading_text_transform'] : ( isset( $styles['label_text_transform'] ) ? $styles['label_text_transform'] : '' ), ); if ( ! empty( $styles['panel_heading_color'] ) ) { $panel_heading_declarations[] = 'color:' . $styles['panel_heading_color']; } elseif ( ! empty( $styles['label_color'] ) ) { $panel_heading_declarations[] = 'color:' . $styles['label_color']; } acewpcf_append_typography_declarations( $panel_heading_declarations, $panel_heading_styles, 'panel_heading' ); $panel_heading_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__panel-heading', $panel_heading_declarations ); if ( '' !== $panel_heading_rule ) { $rules[] = $panel_heading_rule; } $panel_toggle_declarations = array(); if ( ! empty( $styles['panel_toggle_icon_color'] ) ) { $panel_toggle_declarations[] = 'color:' . $styles['panel_toggle_icon_color']; } elseif ( ! empty( $styles['panel_heading_color'] ) ) { $panel_toggle_declarations[] = 'color:' . $styles['panel_heading_color']; } if ( isset( $styles['panel_toggle_icon_size'] ) && acewpcf_style_value_is_set( $styles['panel_toggle_icon_size'] ) ) { $panel_toggle_declarations[] = '--cpcf-panel-toggle-size:' . absint( $styles['panel_toggle_icon_size'] ) . 'px'; } if ( ! empty( $styles['panel_toggle_hover_icon_color'] ) ) { $panel_toggle_declarations[] = '--cpcf-panel-toggle-hover-color:' . $styles['panel_toggle_hover_icon_color']; } if ( ! empty( $styles['panel_toggle_hover_background_color'] ) ) { $panel_toggle_declarations[] = '--cpcf-panel-toggle-hover-background:' . $styles['panel_toggle_hover_background_color']; } if ( ! empty( $styles['panel_toggle_active_icon_color'] ) ) { $panel_toggle_declarations[] = '--cpcf-panel-toggle-active-color:' . $styles['panel_toggle_active_icon_color']; } if ( ! empty( $styles['panel_toggle_active_background_color'] ) ) { $panel_toggle_declarations[] = '--cpcf-panel-toggle-active-background:' . $styles['panel_toggle_active_background_color']; } $panel_toggle_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__panel-toggle', $panel_toggle_declarations ); if ( '' !== $panel_toggle_rule ) { $rules[] = $panel_toggle_rule; } $count_declarations = array(); if ( ! empty( $styles['count_color'] ) ) { $count_declarations[] = 'color:' . $styles['count_color']; } acewpcf_append_typography_declarations( $count_declarations, $styles, 'count' ); $count_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__count', $count_declarations ); if ( '' !== $count_rule ) { $rules[] = $count_rule; } if ( acewpcf_filter_uses_terms( $filter ) ) { $term_search_declarations = array(); $term_search_placeholder_declarations = array(); $term_search_focus_declarations = array(); if ( ! empty( $styles['term_search_text_color'] ) ) { $term_search_declarations[] = 'color:' . $styles['term_search_text_color']; } if ( ! empty( $styles['term_search_background_color'] ) ) { $term_search_declarations[] = 'background:' . $styles['term_search_background_color']; } if ( ! empty( $styles['term_search_border_color'] ) ) { $term_search_declarations[] = 'border-color:' . $styles['term_search_border_color']; } if ( isset( $styles['term_search_border_width'] ) && acewpcf_style_value_is_set( $styles['term_search_border_width'] ) ) { $term_search_declarations[] = 'border-width:' . absint( $styles['term_search_border_width'] ) . 'px'; } if ( isset( $styles['term_search_border_radius'] ) && acewpcf_style_value_is_set( $styles['term_search_border_radius'] ) ) { $term_search_declarations[] = 'border-radius:' . absint( $styles['term_search_border_radius'] ) . 'px'; } if ( isset( $styles['term_search_padding_y'] ) && acewpcf_style_value_is_set( $styles['term_search_padding_y'] ) ) { $term_search_declarations[] = 'padding-top:' . absint( $styles['term_search_padding_y'] ) . 'px'; $term_search_declarations[] = 'padding-bottom:' . absint( $styles['term_search_padding_y'] ) . 'px'; } if ( isset( $styles['term_search_padding_x'] ) && acewpcf_style_value_is_set( $styles['term_search_padding_x'] ) ) { $term_search_declarations[] = 'padding-left:' . absint( $styles['term_search_padding_x'] ) . 'px'; $term_search_declarations[] = 'padding-right:' . absint( $styles['term_search_padding_x'] ) . 'px'; } acewpcf_append_typography_declarations( $term_search_declarations, $styles, 'term_search' ); $term_search_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__term-search-input', $term_search_declarations ); if ( '' !== $term_search_rule ) { $rules[] = $term_search_rule; } if ( ! empty( $styles['term_search_text_color'] ) ) { $term_search_clear_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__term-search-clear', array( 'color:' . $styles['term_search_text_color'] . ' !important', 'opacity:0.7', ) ); if ( '' !== $term_search_clear_rule ) { $rules[] = $term_search_clear_rule; } $term_search_clear_hover_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__term-search-clear:hover, ' . $scope . ' .cpcf-filter__term-search-clear:focus', array( 'color:' . $styles['term_search_text_color'] . ' !important', 'opacity:1', ) ); if ( '' !== $term_search_clear_hover_rule ) { $rules[] = $term_search_clear_hover_rule; } } if ( ! empty( $styles['term_search_placeholder_color'] ) ) { $term_search_placeholder_declarations[] = 'color:' . $styles['term_search_placeholder_color']; $term_search_placeholder_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__term-search-input::placeholder, ' . $scope . ' .cpcf-filter__term-search-input::-webkit-input-placeholder', $term_search_placeholder_declarations ); if ( '' !== $term_search_placeholder_rule ) { $rules[] = $term_search_placeholder_rule; } } if ( ! empty( $styles['term_search_focus_border_color'] ) ) { $term_search_focus_declarations[] = 'border-color:' . $styles['term_search_focus_border_color']; $term_search_focus_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter__term-search-input:focus', $term_search_focus_declarations ); if ( '' !== $term_search_focus_rule ) { $rules[] = $term_search_focus_rule; } } if ( isset( $styles['term_search_list_max_height'] ) && acewpcf_style_value_is_set( $styles['term_search_list_max_height'] ) ) { $list_max_height = absint( $styles['term_search_list_max_height'] ); $term_search_list_rule = acewpcf_build_css_rule( $scope, array( '--cpcf-term-search-list-max-height:' . ( $list_max_height > 0 ? $list_max_height . 'px' : 'none' ) ) ); if ( '' !== $term_search_list_rule ) { $rules[] = $term_search_list_rule; } } } if ( acewpcf_filter_uses_swatches( $filter ) ) { $swatch_declarations = array( 'min-height:0', 'width:auto', 'padding:4px', 'background:transparent', 'border-color:transparent', 'box-shadow:none', ); if ( isset( $styles['swatch_size'] ) && acewpcf_style_value_is_set( $styles['swatch_size'] ) ) { $swatch_declarations[] = '--cpcf-swatch-size:' . absint( $styles['swatch_size'] ) . 'px'; } $swatch_area_declarations = array(); if ( ! empty( $styles['swatch_background_color'] ) ) { $swatch_area_declarations[] = '--cpcf-swatch-area-background:' . $styles['swatch_background_color']; $swatch_area_declarations[] = 'background:' . $styles['swatch_background_color']; $swatch_area_declarations[] = 'padding:10px'; if ( isset( $styles['border_radius'] ) && acewpcf_style_value_is_set( $styles['border_radius'] ) ) { $swatch_area_declarations[] = 'border-radius:' . absint( $styles['border_radius'] ) . 'px'; } } $swatch_area_rule = acewpcf_build_css_rule( $scope . '.cpcf-filter--swatches .cpcf-filter__panel-body', $swatch_area_declarations ); if ( '' !== $swatch_area_rule ) { $rules[] = $swatch_area_rule; } $swatch_button_rule = acewpcf_build_css_rule( $scope . '.cpcf-filter--swatches .cpcf-filter__button, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__choice .cpcf-filter__button', $swatch_declarations ); if ( '' !== $swatch_button_rule ) { $rules[] = $swatch_button_rule; } $swatch_active_color = ''; if ( ! empty( $styles['active_border_color'] ) ) { $swatch_active_color = $styles['active_border_color']; } elseif ( ! empty( $styles['active_background_color'] ) ) { $swatch_active_color = $styles['active_background_color']; } elseif ( ! empty( $styles['button_border_color'] ) ) { $swatch_active_color = $styles['button_border_color']; } $swatch_text_color = ''; if ( ! empty( $styles['label_color'] ) ) { $swatch_text_color = $styles['label_color']; } elseif ( ! empty( $styles['button_text_color'] ) ) { $swatch_text_color = $styles['button_text_color']; } $swatch_reset_declarations = array( 'background:transparent', 'border-color:transparent', 'box-shadow:none', ); if ( '' !== $swatch_text_color ) { $swatch_reset_declarations[] = 'color:' . $swatch_text_color; } $swatch_reset_rule = acewpcf_build_css_rule( $scope . '.cpcf-filter--swatches .cpcf-filter__button.is-active, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__choice.is-active .cpcf-filter__button, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__checkbox:checked + .cpcf-filter__button, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__button:not(.is-active):hover, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__choice:not(.is-active):hover .cpcf-filter__button', $swatch_reset_declarations ); if ( '' !== $swatch_reset_rule ) { $rules[] = $swatch_reset_rule; } if ( '' !== $swatch_text_color ) { $swatch_label_rule = acewpcf_build_css_rule( $scope . '.cpcf-filter--swatches .cpcf-filter__button.is-active .cpcf-filter__label, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__button.is-active .cpcf-filter__count, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__choice.is-active .cpcf-filter__label, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__choice.is-active .cpcf-filter__count', array( 'color:' . $swatch_text_color ) ); if ( '' !== $swatch_label_rule ) { $rules[] = $swatch_label_rule; } } if ( '' !== $swatch_active_color ) { $swatch_ring_gap = ! empty( $styles['swatch_background_color'] ) ? $styles['swatch_background_color'] : '#ffffff'; $swatch_ring_rule = acewpcf_build_css_rule( $scope . '.cpcf-filter--swatches .cpcf-filter__button.is-active .cpcf-filter__swatch, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__choice.is-active .cpcf-filter__swatch, ' . $scope . '.cpcf-filter--swatches .cpcf-filter__checkbox:checked + .cpcf-filter__button .cpcf-filter__swatch', array( 'box-shadow:0 0 0 2px ' . $swatch_ring_gap . ', 0 0 0 4px ' . $swatch_active_color . ', inset 0 0 0 1px rgba(16, 24, 40, 0.16)' ) ); if ( '' !== $swatch_ring_rule ) { $rules[] = $swatch_ring_rule; } } } $responsive_rule_block = acewpcf_get_filter_responsive_style_block( $filter ); if ( '' !== $responsive_rule_block ) { $rules[] = $responsive_rule_block; } return implode( "\n", $rules ); } function acewpcf_get_filter_panel_style_block( $panel ) { $styles = isset( $panel['styles'] ) && is_array( $panel['styles'] ) ? $panel['styles'] : array(); $scope = '.cpcf-filter-panel--' . sanitize_html_class( $panel['id'] ); $rules = array(); if ( empty( $styles ) ) { return ''; } $button_declarations = array(); if ( ! empty( $styles['clear_all_text_color'] ) ) { $button_declarations[] = 'color:' . $styles['clear_all_text_color']; } if ( ! empty( $styles['clear_all_background_color'] ) ) { $button_declarations[] = 'background:' . $styles['clear_all_background_color']; } if ( ! empty( $styles['clear_all_border_color'] ) ) { $button_declarations[] = 'border-color:' . $styles['clear_all_border_color']; } $panel_declarations = array(); if ( ! empty( $styles['separator_color'] ) ) { $panel_declarations[] = '--cpcf-panel-separator-color:' . $styles['separator_color']; } if ( isset( $styles['separator_width'] ) && acewpcf_style_value_is_set( $styles['separator_width'] ) ) { $panel_declarations[] = '--cpcf-panel-separator-width:' . absint( $styles['separator_width'] ) . 'px'; } if ( isset( $styles['separator_spacing'] ) && acewpcf_style_value_is_set( $styles['separator_spacing'] ) ) { $panel_declarations[] = '--cpcf-panel-separator-spacing:' . absint( $styles['separator_spacing'] ) . 'px'; } if ( ! empty( $styles['group_header_color'] ) ) { $panel_declarations[] = '--cpcf-group-header-color:' . $styles['group_header_color']; } if ( isset( $styles['group_header_font_size'] ) && acewpcf_style_value_is_set( $styles['group_header_font_size'] ) ) { $panel_declarations[] = '--cpcf-group-header-font-size:' . absint( $styles['group_header_font_size'] ) . 'px'; } if ( isset( $styles['group_header_letter_spacing'] ) && acewpcf_style_value_is_set( $styles['group_header_letter_spacing'] ) ) { $panel_declarations[] = '--cpcf-group-header-letter-spacing:' . $styles['group_header_letter_spacing'] . 'px'; } // Safe fallback colors for mobile toggle to prevent transient theme colors on first render. $panel_declarations[] = '--cpcf-mobile-toggle-fallback-text-color:' . ( ! empty( $styles['mobile_toggle_text_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_text_color'] ) : '#ffffff' ); $panel_declarations[] = '--cpcf-mobile-toggle-fallback-background-color:' . ( ! empty( $styles['mobile_toggle_background_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_background_color'] ) : '#1d2327' ); $panel_declarations[] = '--cpcf-mobile-toggle-fallback-border-color:' . ( ! empty( $styles['mobile_toggle_border_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_border_color'] ) : '#1d2327' ); $panel_rule = acewpcf_build_css_rule( $scope, $panel_declarations ); if ( '' !== $panel_rule ) { $rules[] = $panel_rule; } if ( isset( $styles['clear_all_font_size'] ) && acewpcf_style_value_is_set( $styles['clear_all_font_size'] ) ) { $button_declarations[] = 'font-size:' . absint( $styles['clear_all_font_size'] ) . 'px'; } if ( isset( $styles['clear_all_padding_y'] ) && acewpcf_style_value_is_set( $styles['clear_all_padding_y'] ) ) { $button_declarations[] = 'padding-top:' . absint( $styles['clear_all_padding_y'] ) . 'px'; $button_declarations[] = 'padding-bottom:' . absint( $styles['clear_all_padding_y'] ) . 'px'; } if ( isset( $styles['clear_all_padding_x'] ) && acewpcf_style_value_is_set( $styles['clear_all_padding_x'] ) ) { $button_declarations[] = 'padding-left:' . absint( $styles['clear_all_padding_x'] ) . 'px'; $button_declarations[] = 'padding-right:' . absint( $styles['clear_all_padding_x'] ) . 'px'; } if ( isset( $styles['clear_all_border_radius'] ) && acewpcf_style_value_is_set( $styles['clear_all_border_radius'] ) ) { $button_declarations[] = 'border-radius:' . absint( $styles['clear_all_border_radius'] ) . 'px'; } $button_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter-panel__clear', $button_declarations ); if ( '' !== $button_rule ) { $rules[] = $button_rule; } $hover_declarations = array(); if ( ! empty( $styles['clear_all_hover_text_color'] ) ) { $hover_declarations[] = 'color:' . $styles['clear_all_hover_text_color']; } if ( ! empty( $styles['clear_all_hover_background_color'] ) ) { $hover_declarations[] = 'background:' . $styles['clear_all_hover_background_color']; } if ( ! empty( $styles['clear_all_hover_border_color'] ) ) { $hover_declarations[] = 'border-color:' . $styles['clear_all_hover_border_color']; } $hover_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter-panel__clear:hover, ' . $scope . ' .cpcf-filter-panel__clear:focus-visible', $hover_declarations ); if ( '' !== $hover_rule ) { $rules[] = $hover_rule; } acewpcf_append_panel_button_style_rules( $rules, $scope, '.cpcf-filter-panel__mobile-toggle', '.cpcf-filter-panel__mobile-toggle:hover, .cpcf-filter-panel__mobile-toggle:focus, .cpcf-filter-panel__mobile-toggle:focus-visible, .cpcf-filter-panel__mobile-toggle:active', $styles, 'mobile_toggle' ); $group_header_declarations = array(); if ( ! empty( $styles['group_header_color'] ) ) { $group_header_declarations[] = 'color:' . $styles['group_header_color']; } acewpcf_append_typography_declarations( $group_header_declarations, $styles, 'group_header' ); $group_header_rule = acewpcf_build_css_rule( $scope . ' .cpcf-filter-panel__group-header > span', $group_header_declarations ); if ( '' !== $group_header_rule ) { $rules[] = $group_header_rule; } return implode( "\n", $rules ); } function acewpcf_get_ajax_empty_results_config( $source ) { $source = is_array( $source ) ? $source : array(); $styles = isset( $source['styles'] ) && is_array( $source['styles'] ) ? $source['styles'] : array(); $config = array( 'message' => isset( $source['empty_results_message'] ) ? acewpcf_sanitize_empty_results_message( $source['empty_results_message'] ) : '', 'textColor' => isset( $styles['empty_results_text_color'] ) ? sanitize_hex_color( $styles['empty_results_text_color'] ) : '', 'backgroundColor' => isset( $styles['empty_results_background_color'] ) ? sanitize_hex_color( $styles['empty_results_background_color'] ) : '', 'borderColor' => isset( $styles['empty_results_border_color'] ) ? sanitize_hex_color( $styles['empty_results_border_color'] ) : '', 'fontSize' => isset( $styles['empty_results_font_size'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_font_size'] ) : '', 'paddingY' => isset( $styles['empty_results_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_padding_y'] ) : '', 'paddingX' => isset( $styles['empty_results_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_padding_x'] ) : '', 'borderRadius' => isset( $styles['empty_results_border_radius'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_border_radius'] ) : '', ); return array_filter( $config, static function ( $value ) { return '' !== (string) $value; } ); } function acewpcf_get_current_archive_count_context() { static $context = null; if ( null !== $context ) { return $context; } $context = array(); $queried_object = get_queried_object(); if ( ! ( $queried_object instanceof WP_Term ) ) { return $context; } $taxonomy = sanitize_key( $queried_object->taxonomy ); if ( ! acewpcf_is_supported_content_taxonomy( $taxonomy ) ) { return $context; } $slug = sanitize_title( $queried_object->slug ); if ( '' !== $slug ) { $context[ $taxonomy ] = array( $slug ); } return $context; } function acewpcf_get_filter_count_context_tax_clauses( $filter ) { static $contexts = array(); $filter = is_array( $filter ) ? $filter : array(); $filter_id = isset( $filter['id'] ) ? sanitize_key( $filter['id'] ) : ''; $filter_taxonomy = acewpcf_get_filter_taxonomy( $filter ); $cache_key = $filter_id . ':' . $filter_taxonomy; if ( isset( $contexts[ $cache_key ] ) ) { return $contexts[ $cache_key ]; } $contexts[ $cache_key ] = acewpcf_get_all_active_filter_tax_clauses( $filter_id ); foreach ( acewpcf_get_current_archive_count_context() as $taxonomy => $archive_slugs ) { if ( $taxonomy === $filter_taxonomy ) { continue; } $contexts[ $cache_key ][] = array( 'filter_id' => 'archive-' . $taxonomy, 'taxonomy' => $taxonomy, 'slugs' => $archive_slugs, ); } $contexts[ $cache_key ] = acewpcf_normalize_active_filter_tax_clauses( $contexts[ $cache_key ] ); return $contexts[ $cache_key ]; } function acewpcf_get_filter_count_context_slugs_by_filter( $filter ) { return acewpcf_get_filter_count_context_tax_clauses( $filter ); } function acewpcf_get_contextual_content_query_args( $active_tax_clauses, $content_type = 'post', $exclude_filter_id = '' ) { $content_type = acewpcf_sanitize_content_type( $content_type ); $query_args = acewpcf_get_content_count_query_base_args( $content_type ); $tax_query = isset( $query_args['tax_query'] ) && is_array( $query_args['tax_query'] ) ? $query_args['tax_query'] : array(); $active_tax_clauses = acewpcf_normalize_active_filter_tax_clauses( $active_tax_clauses ); foreach ( $active_tax_clauses as $filter_clause ) { if ( empty( $filter_clause['taxonomy'] ) || empty( $filter_clause['slugs'] ) ) { continue; } $tax_query[] = array( 'taxonomy' => $filter_clause['taxonomy'], 'field' => 'slug', 'terms' => $filter_clause['slugs'], 'operator' => ( isset( $filter_clause['operator'] ) && 'and' === $filter_clause['operator'] && count( $filter_clause['slugs'] ) > 1 ) ? 'AND' : 'IN', ); } if ( ! empty( $tax_query ) ) { $query_args['tax_query'] = $tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Contextual filter state requires taxonomy constraints. } acewpcf_apply_virtual_filters_to_query_args( $query_args, $content_type, $exclude_filter_id ); return $query_args; } function acewpcf_get_contextual_filter_term_count_map_for_terms( $filter_taxonomy, $terms, $active_tax_clauses, $selected_slugs = array(), $content_type = 'post', $exclude_filter_id = '' ) { static $maps = array(); $filter_taxonomy = sanitize_key( (string) $filter_taxonomy ); $terms = is_array( $terms ) ? $terms : array(); $active_tax_clauses = acewpcf_normalize_active_filter_tax_clauses( $active_tax_clauses ); $selected_slugs = array_map( 'sanitize_title', is_array( $selected_slugs ) ? $selected_slugs : array() ); $selected_slugs = array_values( array_filter( array_unique( $selected_slugs ) ) ); $count_map = array(); $term_slugs = array(); foreach ( $terms as $term ) { if ( ! ( $term instanceof WP_Term ) ) { continue; } if ( $filter_taxonomy !== sanitize_key( $term->taxonomy ) ) { continue; } $term_id = (int) $term->term_id; if ( $term_id <= 0 ) { continue; } $count_map[ $term_id ] = 0; $term_slugs[ $term_id ] = sanitize_title( $term->slug ); } if ( '' === $filter_taxonomy || empty( $count_map ) ) { return $count_map; } $cache_key = md5( wp_json_encode( array( 'filter_taxonomy' => $filter_taxonomy, 'terms' => array_keys( $count_map ), 'active' => $active_tax_clauses, 'selected' => $selected_slugs, ) ) ); if ( isset( $maps[ $cache_key ] ) ) { return $maps[ $cache_key ]; } $post_ids_by_term = array(); $query_args = acewpcf_get_contextual_content_query_args( $active_tax_clauses, $content_type, $exclude_filter_id ); $query_args['posts_per_page'] = -1; $query_args['no_found_rows'] = true; $query_args['paged'] = 1; $query_args['orderby'] = 'none'; $query_args['cache_results'] = false; $query = new WP_Query( $query_args ); $post_ids = ! empty( $query->posts ) ? array_map( 'absint', $query->posts ) : array(); wp_reset_postdata(); if ( empty( $post_ids ) ) { $maps[ $cache_key ] = $count_map; return $maps[ $cache_key ]; } $term_relationships = wp_get_object_terms( $post_ids, $filter_taxonomy, array( 'fields' => 'all_with_object_id', 'orderby' => 'none', ) ); if ( is_wp_error( $term_relationships ) || empty( $term_relationships ) ) { $maps[ $cache_key ] = $count_map; return $maps[ $cache_key ]; } foreach ( $term_relationships as $term_relationship ) { if ( ! is_object( $term_relationship ) || ! isset( $term_relationship->object_id, $term_relationship->term_id, $term_relationship->slug ) ) { continue; } $object_id = absint( $term_relationship->object_id ); $term_id = (int) $term_relationship->term_id; if ( $object_id <= 0 || $term_id <= 0 ) { continue; } if ( isset( $count_map[ $term_id ] ) ) { if ( ! isset( $post_ids_by_term[ $term_id ] ) ) { $post_ids_by_term[ $term_id ] = array(); } $post_ids_by_term[ $term_id ][ $object_id ] = true; } } foreach ( $count_map as $term_id => $count ) { $term_post_ids = isset( $post_ids_by_term[ $term_id ] ) ? $post_ids_by_term[ $term_id ] : array(); $count_map[ $term_id ] = count( $term_post_ids ); } $maps[ $cache_key ] = $count_map; return $maps[ $cache_key ]; } function acewpcf_get_filter_term_count_map( $filter, $force_contextual = false ) { static $maps = array(); $filter = is_array( $filter ) ? $filter : array(); $filter_id = isset( $filter['id'] ) ? sanitize_key( $filter['id'] ) : ''; $taxonomy = acewpcf_get_filter_taxonomy( $filter ); $active_tax_clauses = acewpcf_get_filter_count_context_tax_clauses( $filter ); $selected_slugs = acewpcf_parse_filter_request_slugs( $filter_id ); $force_contextual = (bool) $force_contextual; if ( '' === $filter_id || ( empty( $active_tax_clauses ) && empty( $selected_slugs ) && ! $force_contextual && ! acewpcf_request_contains_filter_query_vars() ) ) { return array(); } $cache_key = $filter_id . ':' . md5( wp_json_encode( array( 'tax' => $active_tax_clauses, 'selected' => $selected_slugs, 'force_contextual' => $force_contextual ) ) ); if ( isset( $maps[ $cache_key ] ) ) { return $maps[ $cache_key ]; } $terms = acewpcf_get_filter_terms( $filter_id ); if ( empty( $terms ) ) { $maps[ $cache_key ] = array(); return $maps[ $cache_key ]; } if ( ( acewpcf_is_author_filter( $filter ) || acewpcf_is_date_filter( $filter ) ) && function_exists( 'acewpcf_get_virtual_filter_count_map' ) ) { $maps[ $cache_key ] = acewpcf_get_virtual_filter_count_map( $filter, $active_tax_clauses ); return $maps[ $cache_key ]; } $maps[ $cache_key ] = acewpcf_get_contextual_filter_term_count_map_for_terms( $taxonomy, $terms, $active_tax_clauses, $selected_slugs, acewpcf_get_filter_content_type( $filter ), $filter_id ); return $maps[ $cache_key ]; } function acewpcf_panel_has_active_filters( $panel ) { $panel_filter_ids = acewpcf_parse_filter_id_list( isset( $panel['filter_ids'] ) ? $panel['filter_ids'] : array() ); if ( empty( $panel_filter_ids ) ) { return false; } foreach ( $panel_filter_ids as $filter_id ) { $filter = acewpcf_get_filter_set( $filter_id ); if ( empty( $filter ) ) { continue; } if ( acewpcf_is_search_filter( $filter ) ) { if ( '' !== acewpcf_parse_filter_request_search( $filter['id'] ) ) { return true; } continue; } if ( ! empty( acewpcf_parse_filter_request_slugs( $filter['id'] ) ) ) { return true; } } return false; } function acewpcf_get_filter_panel_clear_all_url( $panel ) { $panel_filter_ids = acewpcf_parse_filter_id_list( isset( $panel['filter_ids'] ) ? $panel['filter_ids'] : array() ); $query_args_to_remove = array( 'paged' ); $base_url = acewpcf_get_filter_render_base_url(); if ( '' === $base_url ) { $base_url = acewpcf_get_filter_base_url(); } foreach ( $panel_filter_ids as $filter_id ) { $filter = acewpcf_get_filter_set( $filter_id ); if ( empty( $filter ) ) { continue; } $query_args_to_remove[] = acewpcf_get_filter_query_var( $filter['id'] ); } return remove_query_arg( array_values( array_unique( $query_args_to_remove ) ), $base_url ); } function acewpcf_should_render_panel_clear_all( $panel ) { $panel_filter_ids = acewpcf_parse_filter_id_list( isset( $panel['filter_ids'] ) ? $panel['filter_ids'] : array() ); $clear_all_mode = isset( $panel['clear_all_mode'] ) ? acewpcf_sanitize_filter_panel_clear_all_mode( $panel['clear_all_mode'] ) : 'auto'; if ( 'off' === $clear_all_mode || empty( $panel_filter_ids ) ) { return false; } if ( 'always' === $clear_all_mode ) { return true; } return count( $panel_filter_ids ) > 1; } function acewpcf_render_filter_choice_content( $category, $filter, $count = null ) { $selection_mode = isset( $filter['selection_mode'] ) ? $filter['selection_mode'] : 'single'; $display_count = null === $count ? absint( $category->count ) : absint( $count ); $uses_swatches = acewpcf_filter_uses_swatches( $filter ); $swatch_color = $uses_swatches ? acewpcf_get_filter_term_color( $filter, isset( $category->term_id ) ? $category->term_id : 0 ) : ''; ob_start(); ?> aria-hidden="true"> name ); ?> count ) ) { return (int) $term->count; } return 0; } function acewpcf_resolve_hide_zero_count_terms( $filter, $override = '' ) { if ( ! acewpcf_filter_uses_terms( $filter ) ) { return false; } $override = sanitize_key( (string) $override ); if ( 'hide' === $override ) { return true; } if ( 'show' === $override ) { return false; } return ! empty( $filter['hide_zero_count_terms'] ); } function acewpcf_resolve_term_search_mode( $filter, $override = '' ) { if ( ! acewpcf_filter_uses_terms( $filter ) ) { return 'terms'; } $override = sanitize_key( (string) $override ); $choices = acewpcf_get_filter_term_search_mode_choices(); if ( isset( $choices[ $override ] ) ) { return $override; } return acewpcf_sanitize_filter_term_search_mode( isset( $filter['term_search_mode'] ) ? $filter['term_search_mode'] : 'terms' ); } function acewpcf_filter_uses_swatches( $filter ) { if ( ! acewpcf_filter_uses_terms( $filter ) ) { return false; } return 'swatches' === acewpcf_sanitize_filter_display_mode( isset( $filter['display_mode'] ) ? $filter['display_mode'] : 'buttons' ); } function acewpcf_get_filter_term_color( $filter, $term_id ) { $colors = isset( $filter['term_colors'] ) && is_array( $filter['term_colors'] ) ? $filter['term_colors'] : array(); $term_id = absint( $term_id ); if ( ! $term_id ) { return ''; } if ( ! empty( $colors[ $term_id ] ) ) { return acewpcf_normalize_hex_color( $colors[ $term_id ] ); } $key = (string) $term_id; if ( ! empty( $colors[ $key ] ) ) { return acewpcf_normalize_hex_color( $colors[ $key ] ); } return ''; } function acewpcf_get_filter_term_search_placeholder( $filter ) { $placeholder = isset( $filter['term_search_placeholder'] ) ? trim( (string) $filter['term_search_placeholder'] ) : ''; return '' !== $placeholder ? $placeholder : __( 'Search…', 'ace-content-filters' ); } function acewpcf_get_filter_term_search_empty_message( $filter ) { $message = isset( $filter['term_search_empty_message'] ) ? trim( (string) $filter['term_search_empty_message'] ) : ''; return '' !== $message ? $message : __( 'No matching terms', 'ace-content-filters' ); } function acewpcf_get_filter_term_search_text( $term ) { $parts = array(); if ( is_object( $term ) && isset( $term->name ) && '' !== (string) $term->name ) { $parts[] = (string) $term->name; } if ( is_object( $term ) && isset( $term->slug ) && '' !== (string) $term->slug ) { $parts[] = (string) $term->slug; } return strtolower( implode( ' ', $parts ) ); } function acewpcf_get_visible_filter_terms( $terms, $count_map, $active_slugs, $preserve_ancestors = false ) { $terms = is_array( $terms ) ? $terms : array(); $count_map = is_array( $count_map ) ? $count_map : array(); $active_slugs = is_array( $active_slugs ) ? $active_slugs : array(); if ( empty( $terms ) ) { return array(); } $selected_ids = array(); $keep = array(); foreach ( $terms as $term ) { if ( ! ( $term instanceof WP_Term ) ) { continue; } $term_id = (int) $term->term_id; $slug = isset( $term->slug ) ? (string) $term->slug : ''; $selected_ids[ $term_id ] = true; $keep[ $term_id ] = ( '' !== $slug && in_array( $slug, $active_slugs, true ) ) || acewpcf_get_filter_term_display_count( $term, $count_map ) > 0; } if ( $preserve_ancestors ) { $changed = true; $guard = 0; while ( $changed && $guard < 20 ) { $changed = false; $guard++; foreach ( $terms as $term ) { if ( ! ( $term instanceof WP_Term ) ) { continue; } $term_id = (int) $term->term_id; if ( empty( $keep[ $term_id ] ) ) { continue; } $ancestor_id = acewpcf_get_selected_term_ancestor_id( $term, $selected_ids ); if ( $ancestor_id > 0 && empty( $keep[ $ancestor_id ] ) ) { $keep[ $ancestor_id ] = true; $changed = true; } } } } $visible = array(); foreach ( $terms as $term ) { if ( $term instanceof WP_Term && ! empty( $keep[ (int) $term->term_id ] ) ) { $visible[] = $term; } } return $visible; } function acewpcf_get_filter_choice_count_key( $choice ) { if ( is_object( $choice ) && isset( $choice->term_id ) ) { return (int) $choice->term_id; } if ( is_array( $choice ) && isset( $choice['term_id'] ) ) { return (int) $choice['term_id']; } if ( is_object( $choice ) && isset( $choice->slug ) ) { return sanitize_title( (string) $choice->slug ); } if ( is_array( $choice ) && isset( $choice['slug'] ) ) { return sanitize_title( (string) $choice['slug'] ); } return ''; } function acewpcf_get_current_filter_choice( $choices, $active_slugs ) { if ( empty( $choices ) || ! is_array( $choices ) ) { return null; } foreach ( $choices as $choice ) { if ( in_array( $choice->slug, $active_slugs, true ) ) { return $choice; } } return reset( $choices ); } function acewpcf_render_filter_mobile_toggle( $category, $filter, $is_selected, $count = null ) { if ( empty( $category ) ) { return ''; } ob_start(); ?> '', 'ajax' => '', 'results_selector' => '', 'show_panel_heading' => '', 'count_display_mode' => '', 'hide_zero_count_terms' => '', 'term_search_mode' => '', ), $atts, 'acewpcf_filter' ); $filter = acewpcf_get_filter_set( $atts['id'] ); if ( empty( $filter ) ) { return ''; } $ajax_override = isset( $atts['ajax'] ) ? trim( (string) $atts['ajax'] ) : ''; $selector_override = isset( $atts['results_selector'] ) ? trim( (string) $atts['results_selector'] ) : ''; $force_contextual_counts = ! empty( $atts['force_contextual_counts'] ); $count_display_override = isset( $atts['count_display_mode'] ) ? sanitize_key( (string) $atts['count_display_mode'] ) : ''; $hide_zero_count_override = isset( $atts['hide_zero_count_terms'] ) ? sanitize_key( (string) $atts['hide_zero_count_terms'] ) : ''; $term_search_override = isset( $atts['term_search_mode'] ) ? sanitize_key( (string) $atts['term_search_mode'] ) : ''; $show_panel_heading_attr = isset( $atts['show_panel_heading'] ) ? strtolower( trim( (string) $atts['show_panel_heading'] ) ) : ''; $panel_heading_forced_off = in_array( $show_panel_heading_attr, array( '0', 'false', 'no', 'off' ), true ); $panel_heading_enabled = ! $panel_heading_forced_off && ! empty( $filter['show_panel_heading'] ); $filter_ajax_enabled = ! empty( $filter['ajax_enabled'] ); $filter_results_selector = isset( $filter['results_selector'] ) ? acewpcf_sanitize_results_selector( $filter['results_selector'] ) : ''; $ajax_enabled = '' === $ajax_override ? $filter_ajax_enabled : acewpcf_shortcode_truthy( $ajax_override ); $results_selector = '' !== $selector_override ? acewpcf_sanitize_results_selector( $selector_override ) : $filter_results_selector; $ajax_enabled = $ajax_enabled && '' !== $results_selector; $panel_heading = ''; if ( $panel_heading_enabled ) { $panel_heading = isset( $filter['panel_heading'] ) ? trim( sanitize_text_field( (string) $filter['panel_heading'] ) ) : ''; } acewpcf_enqueue_assets(); acewpcf_enqueue_filter_font_stylesheet( $filter ); $style_block = acewpcf_get_filter_style_block( $filter ); acewpcf_enqueue_inline_style_block( $style_block ); $empty_results_config = acewpcf_get_ajax_empty_results_config( $filter ); $empty_results_config_json = ! empty( $empty_results_config ) ? wp_json_encode( $empty_results_config ) : ''; $orientation = isset( $filter['orientation'] ) ? acewpcf_sanitize_filter_orientation( $filter['orientation'] ) : 'horizontal'; $base_url = acewpcf_get_filter_render_base_url(); if ( acewpcf_is_search_filter( $filter ) ) { $search_value = acewpcf_parse_filter_request_search( $filter['id'] ); $search_placeholder = isset( $filter['search_placeholder'] ) && '' !== (string) $filter['search_placeholder'] ? (string) $filter['search_placeholder'] : __( 'Search…', 'ace-content-filters' ); $container_class = 'cpcf-filter cpcf-filter--' . sanitize_html_class( $filter['id'] ) . ' cpcf-filter--' . sanitize_html_class( $orientation ) . ' cpcf-filter--search'; $param_key = acewpcf_get_filter_query_var( $filter['id'] ); ob_start(); ?>
data-empty-results-config="" role="search" aria-label="" >
data-term-search-mode="" data-empty-results-config="" role="group" aria-label="" >
> term_id ] ) ? $count_map[ $current_category->term_id ] : $current_category->count ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> slug, $active_slugs, true ); ?> slug === $category->slug; ?> count; ?> acewpcf_depth ) ? max( 0, (int) $category->acewpcf_depth ) : 0; ?> >
'', 'ajax' => '', 'results_selector' => '', ), $atts, 'acewpcf_filter_panel' ); $panel = acewpcf_get_filter_panel( $atts['id'] ); if ( empty( $panel ) ) { return ''; } $panel_filter_ids = acewpcf_parse_filter_id_list( isset( $panel['filter_ids'] ) ? $panel['filter_ids'] : array() ); $ajax_override = isset( $atts['ajax'] ) ? trim( (string) $atts['ajax'] ) : ''; $selector_override = isset( $atts['results_selector'] ) ? trim( (string) $atts['results_selector'] ) : ''; $panel_ajax_enabled = ! empty( $panel['ajax_enabled'] ); $panel_results_selector = isset( $panel['results_selector'] ) ? acewpcf_sanitize_results_selector( $panel['results_selector'] ) : ''; $effective_ajax = '' === $ajax_override ? ( $panel_ajax_enabled ? '1' : '0' ) : $ajax_override; $effective_selector = '' !== $selector_override ? acewpcf_sanitize_results_selector( $selector_override ) : $panel_results_selector; $clear_all_mode = isset( $panel['clear_all_mode'] ) ? acewpcf_sanitize_filter_panel_clear_all_mode( $panel['clear_all_mode'] ) : 'auto'; $panel_count_display_mode = isset( $panel['count_display_mode'] ) ? acewpcf_sanitize_panel_count_display_mode( $panel['count_display_mode'] ) : 'inherit'; $panel_hide_zero_count_terms = isset( $panel['hide_zero_count_terms'] ) ? acewpcf_sanitize_panel_hide_zero_count_terms( $panel['hide_zero_count_terms'] ) : 'inherit'; $panel_term_search_mode = isset( $panel['term_search_mode'] ) ? acewpcf_sanitize_panel_term_search_mode( $panel['term_search_mode'] ) : 'inherit'; $should_render_clear_all = acewpcf_should_render_panel_clear_all( $panel ); $is_clear_all_enabled = acewpcf_panel_has_active_filters( $panel ); $clear_all_url = acewpcf_get_filter_panel_clear_all_url( $panel ); $mobile_toggle_label = isset( $panel['mobile_toggle_label'] ) ? acewpcf_sanitize_panel_control_label( $panel['mobile_toggle_label'] ) : ''; $clear_all_label = isset( $panel['clear_all_label'] ) ? acewpcf_sanitize_panel_control_label( $panel['clear_all_label'] ) : ''; $mobile_toggle_label = '' !== $mobile_toggle_label ? $mobile_toggle_label : __( 'Filters', 'ace-content-filters' ); $clear_all_label = '' !== $clear_all_label ? $clear_all_label : __( 'Clear all', 'ace-content-filters' ); acewpcf_enqueue_panel_font_stylesheet( $panel ); $style_block = acewpcf_get_filter_panel_style_block( $panel ); $empty_results_config = acewpcf_get_ajax_empty_results_config( $panel ); $empty_results_config_json = ! empty( $empty_results_config ) ? wp_json_encode( $empty_results_config ) : ''; if ( empty( $panel_filter_ids ) ) { return ''; } $rendered_filters = array(); foreach ( acewpcf_get_panel_layout_items( $panel ) as $panel_item ) { if ( isset( $panel_item['type'] ) && 'heading' === $panel_item['type'] ) { $group_header = isset( $panel_item['text'] ) ? acewpcf_sanitize_group_header( $panel_item['text'] ) : ''; if ( '' !== $group_header ) { $rendered_filters[] = '
' . esc_html( $group_header ) . '
'; } continue; } $filter_id = isset( $panel_item['id'] ) ? sanitize_key( (string) $panel_item['id'] ) : ''; $filter = '' !== $filter_id ? acewpcf_get_filter_set( $filter_id ) : array(); if ( empty( $filter ) ) { continue; } $filter_output = acewpcf_render_single_filter_shortcode( array( 'id' => $filter_id, 'ajax' => $effective_ajax, 'results_selector' => $effective_selector, 'show_panel_heading' => '1', 'count_display_mode' => 'inherit' !== $panel_count_display_mode ? $panel_count_display_mode : '', 'hide_zero_count_terms' => 'inherit' !== $panel_hide_zero_count_terms ? $panel_hide_zero_count_terms : '', 'term_search_mode' => 'inherit' !== $panel_term_search_mode ? $panel_term_search_mode : '', ) ); if ( '' !== $filter_output ) { $rendered_filters[] = '
' . $filter_output . '
'; } } if ( empty( $rendered_filters ) ) { return ''; } acewpcf_enqueue_inline_style_block( $style_block ); ob_start(); ?>
data-empty-results-config="" >
'', 'ids' => '', 'panel_id' => '', 'ajax' => '', 'results_selector' => '', ), $atts, 'acewpcf_filter' ); $panel_id = isset( $atts['panel_id'] ) ? sanitize_key( (string) $atts['panel_id'] ) : ''; if ( '' !== $panel_id ) { return acewpcf_render_filter_panel_shortcode( array( 'id' => $panel_id, 'ajax' => $atts['ajax'], 'results_selector' => $atts['results_selector'], ) ); } $filter_ids = acewpcf_parse_filter_id_list( $atts['ids'] ); if ( empty( $filter_ids ) ) { return acewpcf_render_single_filter_shortcode( $atts ); } if ( 1 === count( $filter_ids ) ) { $atts['id'] = $filter_ids[0]; return acewpcf_render_single_filter_shortcode( $atts ); } $rendered_filters = array(); foreach ( $filter_ids as $filter_id ) { $filter_output = acewpcf_render_single_filter_shortcode( array( 'id' => $filter_id, 'ajax' => $atts['ajax'], 'results_selector' => $atts['results_selector'], ) ); if ( '' !== $filter_output ) { $rendered_filters[] = $filter_output; } } if ( empty( $rendered_filters ) ) { return ''; } return implode( "\n", $rendered_filters ); } add_shortcode( 'acewpcf_filter', 'acewpcf_render_filter_shortcode' ); add_shortcode( 'acewpcf_filter_panel', 'acewpcf_render_filter_panel_shortcode' );