0, ); } function acewpcf_sanitize_display_settings( $settings ) { $settings = is_array( $settings ) ? $settings : array(); return array( 'enable_google_fonts' => ! empty( $settings['enable_google_fonts'] ) ? 1 : 0, ); } function acewpcf_get_display_settings() { $settings = get_option( ACEWPCF_OPTION_DISPLAY_SETTINGS, array() ); $settings = is_array( $settings ) ? $settings : array(); return wp_parse_args( $settings, acewpcf_get_default_display_settings() ); } function acewpcf_google_fonts_are_enabled() { $settings = acewpcf_get_display_settings(); $enabled = ! empty( $settings['enable_google_fonts'] ); return (bool) apply_filters( 'acewpcf_enable_google_fonts', $enabled, $settings ); } function acewpcf_get_request_query_params() { static $query_params = null; if ( null !== $query_params ) { return $query_params; } $query_params = array(); // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Public filter state is intentionally read from the query string and sanitized here before use. foreach ( $_GET as $key => $value ) { if ( ! is_scalar( $value ) ) { continue; } $key = sanitize_key( (string) $key ); if ( '' === $key ) { continue; } $query_params[ $key ] = wp_unslash( (string) $value ); } // phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized return $query_params; } function acewpcf_get_request_query_value( $key, $default = '' ) { $key = sanitize_key( (string) $key ); $query_params = acewpcf_get_request_query_params(); if ( '' === $key || ! array_key_exists( $key, $query_params ) ) { return $default; } return $query_params[ $key ]; } function acewpcf_get_request_server_value( $key, $default = '' ) { $key = (string) $key; if ( '' === $key ) { return $default; } // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Server values are read-only request context and sanitized by callers as needed. if ( ! isset( $_SERVER[ $key ] ) || ! is_scalar( $_SERVER[ $key ] ) ) { return $default; } return wp_unslash( (string) $_SERVER[ $key ] ); // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized } function acewpcf_prepare_style_inputs( $posted_styles, $stored_styles ) { $posted_styles = is_array( $posted_styles ) ? $posted_styles : array(); return $posted_styles; } function acewpcf_prepare_filter_inputs( $posted_filter, $stored_filter ) { $posted_filter = is_array( $posted_filter ) ? $posted_filter : array(); $posted_filter['styles'] = acewpcf_prepare_style_inputs( isset( $posted_filter['styles'] ) ? $posted_filter['styles'] : array(), array() ); return $posted_filter; } function acewpcf_prepare_panel_inputs( $posted_panel, $stored_panel ) { $posted_panel = is_array( $posted_panel ) ? $posted_panel : array(); $posted_panel['styles'] = acewpcf_prepare_style_inputs( isset( $posted_panel['styles'] ) ? $posted_panel['styles'] : array(), array() ); return $posted_panel; } function acewpcf_get_asset_version( $relative_path ) { $relative_path = ltrim( (string) $relative_path, '/\\' ); $asset_path = ACEWPCF_PLUGIN_PATH . $relative_path; if ( ! file_exists( $asset_path ) ) { return ACEWPCF_VERSION; } return ACEWPCF_VERSION . '.' . ACEWPCF_ASSET_REVISION . '.' . (string) filemtime( $asset_path ) . '.' . (string) filesize( $asset_path ); } function acewpcf_get_default_filter_styles() { return array( 'label_color' => '', 'label_font_family' => '', 'label_font_weight' => '', 'label_font_size' => '', 'label_letter_spacing' => '', 'label_text_transform' => '', 'panel_heading_color' => '', 'panel_heading_font_family' => '', 'panel_heading_font_weight' => '', 'panel_heading_font_size' => '', 'panel_heading_letter_spacing' => '', 'panel_heading_text_transform' => '', 'panel_toggle_icon_color' => '', 'panel_toggle_icon_size' => '', 'panel_toggle_hover_icon_color' => '', 'panel_toggle_hover_background_color' => '', 'panel_toggle_active_icon_color' => '', 'panel_toggle_active_background_color' => '', 'count_color' => '', 'count_font_family' => '', 'count_font_weight' => '', 'count_font_size' => '', 'count_letter_spacing' => '', 'count_text_transform' => '', 'button_text_color' => '', 'button_font_family' => '', 'button_font_weight' => '', 'button_background_color' => '', 'button_border_color' => '', 'button_border_width' => '', 'checkbox_size' => '', 'checkbox_border_width' => '', 'checkbox_border_radius' => '', 'button_font_size' => '', 'button_padding_y' => '', 'button_padding_x' => '', 'gap' => '', 'button_letter_spacing' => '', 'button_text_transform' => '', 'active_text_color' => '', 'active_background_color' => '', 'active_border_color' => '', 'button_hover_text_color' => '', 'button_hover_background_color' => '', 'button_hover_border_color' => '', 'border_radius' => '', 'empty_results_text_color' => '', 'empty_results_background_color' => '', 'empty_results_border_color' => '', 'empty_results_font_size' => '', 'empty_results_padding_y' => '', 'empty_results_padding_x' => '', 'empty_results_border_radius' => '', 'term_search_text_color' => '', 'term_search_placeholder_color' => '', 'term_search_background_color' => '', 'term_search_border_color' => '', 'term_search_border_width' => '', 'term_search_border_radius' => '', 'term_search_font_family' => '', 'term_search_font_weight' => '', 'term_search_font_size' => '', 'term_search_letter_spacing' => '', 'term_search_text_transform' => '', 'term_search_padding_y' => '', 'term_search_padding_x' => '', 'term_search_focus_border_color' => '', 'term_search_list_max_height' => '', 'swatch_size' => '', 'swatch_background_color' => '', 'responsive' => acewpcf_get_default_responsive_style_settings(), ); } function acewpcf_get_default_filter_panel_styles() { return array( 'clear_all_text_color' => '', 'clear_all_background_color' => '', 'clear_all_border_color' => '', 'clear_all_font_size' => '', 'clear_all_padding_y' => '', 'clear_all_padding_x' => '', 'clear_all_border_radius' => '', 'clear_all_hover_text_color' => '', 'clear_all_hover_background_color' => '', 'clear_all_hover_border_color' => '', 'empty_results_text_color' => '', 'empty_results_background_color' => '', 'empty_results_border_color' => '', 'empty_results_font_size' => '', 'empty_results_padding_y' => '', 'empty_results_padding_x' => '', 'empty_results_border_radius' => '', 'mobile_toggle_text_color' => '', 'mobile_toggle_background_color' => '', 'mobile_toggle_border_color' => '', 'mobile_toggle_border_width' => '', 'mobile_toggle_font_family' => '', 'mobile_toggle_font_weight' => '', 'mobile_toggle_font_size' => '', 'mobile_toggle_letter_spacing' => '', 'mobile_toggle_text_transform' => '', 'mobile_toggle_padding_y' => '', 'mobile_toggle_padding_x' => '', 'mobile_toggle_border_radius' => '', 'mobile_toggle_hover_text_color' => '', 'mobile_toggle_hover_background_color' => '', 'mobile_toggle_hover_border_color' => '', 'mobile_close_text_color' => '', 'mobile_close_background_color' => '', 'mobile_close_border_color' => '', 'mobile_close_border_width' => '', 'mobile_close_font_family' => '', 'mobile_close_font_weight' => '', 'mobile_close_font_size' => '', 'mobile_close_letter_spacing' => '', 'mobile_close_text_transform' => '', 'mobile_close_padding_y' => '', 'mobile_close_padding_x' => '', 'mobile_close_border_radius' => '', 'mobile_close_hover_text_color' => '', 'mobile_close_hover_background_color' => '', 'mobile_close_hover_border_color' => '', 'separator_color' => '', 'separator_width' => '', 'separator_spacing' => '', 'group_header_color' => '', 'group_header_font_family' => '', 'group_header_font_weight' => '', 'group_header_font_size' => '', 'group_header_letter_spacing' => '', 'group_header_text_transform' => '', ); } function acewpcf_get_responsive_style_modes() { return array( 'laptop' => array( 'label' => __( 'Laptop', 'ace-content-filters' ), 'max_width' => 1200, 'description' => __( 'Applies on screens up to 1200px wide. Useful for smaller laptops and landscape tablets.', 'ace-content-filters' ), ), 'tablet' => array( 'label' => __( 'Tablet', 'ace-content-filters' ), 'max_width' => 782, 'description' => __( 'Applies on screens up to 782px wide. Use this for tablet typography and button spacing.', 'ace-content-filters' ), ), 'mobile' => array( 'label' => __( 'Mobile', 'ace-content-filters' ), 'max_width' => 560, 'description' => __( 'Applies on screens up to 560px wide. Use this for the tightest phone layout.', 'ace-content-filters' ), ), ); } function acewpcf_get_default_responsive_style_overrides() { return array( 'label_font_size' => '', 'panel_heading_font_size' => '', 'count_font_size' => '', 'button_font_size' => '', 'button_padding_y' => '', 'button_padding_x' => '', 'gap' => '', ); } function acewpcf_get_default_responsive_style_settings() { $defaults = array(); foreach ( acewpcf_get_responsive_style_modes() as $mode_key => $mode ) { $defaults[ $mode_key ] = acewpcf_get_default_responsive_style_overrides(); } return $defaults; } function acewpcf_get_font_family_choices() { return array( '' => array( 'label' => __( 'Theme default', 'ace-content-filters' ), 'css' => '', 'google' => '', ), 'system-sans' => array( 'label' => __( 'System Sans', 'ace-content-filters' ), 'css' => 'system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif', 'google' => '', ), 'system-serif' => array( 'label' => __( 'System Serif', 'ace-content-filters' ), 'css' => 'Georgia,"Times New Roman",serif', 'google' => '', ), 'monospace' => array( 'label' => __( 'Monospace', 'ace-content-filters' ), 'css' => '"SFMono-Regular",Consolas,"Liberation Mono",monospace', 'google' => '', ), 'montserrat' => array( 'label' => __( 'Montserrat', 'ace-content-filters' ), 'css' => 'Montserrat,"Helvetica Neue",Arial,sans-serif', 'google' => 'Montserrat', ), 'poppins' => array( 'label' => __( 'Poppins', 'ace-content-filters' ), 'css' => 'Poppins,"Helvetica Neue",Arial,sans-serif', 'google' => 'Poppins', ), 'oswald' => array( 'label' => __( 'Oswald', 'ace-content-filters' ), 'css' => 'Oswald,"Arial Narrow",sans-serif', 'google' => 'Oswald', ), 'raleway' => array( 'label' => __( 'Raleway', 'ace-content-filters' ), 'css' => 'Raleway,"Helvetica Neue",Arial,sans-serif', 'google' => 'Raleway', ), 'playfair-display' => array( 'label' => __( 'Playfair Display', 'ace-content-filters' ), 'css' => '"Playfair Display",Georgia,serif', 'google' => 'Playfair Display', ), 'lora' => array( 'label' => __( 'Lora', 'ace-content-filters' ), 'css' => 'Lora,Georgia,serif', 'google' => 'Lora', ), 'open-sans' => array( 'label' => __( 'Open Sans', 'ace-content-filters' ), 'css' => '"Open Sans","Helvetica Neue",Arial,sans-serif', 'google' => 'Open Sans', ), 'bebas-neue' => array( 'label' => __( 'Bebas Neue', 'ace-content-filters' ), 'css' => '"Bebas Neue","Arial Narrow",sans-serif', 'google' => 'Bebas Neue', ), ); } function acewpcf_get_font_family_suggestions() { $suggestions = array( 'Abril Fatface', 'Anton', 'Bebas Neue', 'Cormorant Garamond', 'DM Sans', 'Figtree', 'IBM Plex Sans', 'Inter', 'Josefin Sans', 'Kanit', 'Lato', 'League Spartan', 'Lora', 'Manrope', 'Merriweather', 'Montserrat', 'Mulish', 'Nunito', 'Open Sans', 'Oswald', 'Playfair Display', 'Poppins', 'Public Sans', 'Quicksand', 'Raleway', 'Roboto', 'Roboto Condensed', 'Rubik', 'Sora', 'Source Sans 3', 'Space Grotesk', 'Work Sans', ); foreach ( acewpcf_get_font_family_choices() as $choice ) { if ( empty( $choice['google'] ) && empty( $choice['css'] ) ) { continue; } if ( ! empty( $choice['label'] ) ) { $suggestions[] = (string) $choice['label']; } } $suggestions = array_map( 'trim', $suggestions ); $suggestions = array_filter( $suggestions ); $suggestions = array_values( array_unique( $suggestions ) ); natcasesort( $suggestions ); return array_values( $suggestions ); } function acewpcf_get_font_weight_choices() { return array( '' => __( 'Theme default', 'ace-content-filters' ), '100' => __( '100 Thin', 'ace-content-filters' ), '200' => __( '200 Extra Light', 'ace-content-filters' ), '300' => __( '300 Light', 'ace-content-filters' ), '400' => __( '400 Regular', 'ace-content-filters' ), '500' => __( '500 Medium', 'ace-content-filters' ), '600' => __( '600 Semi Bold', 'ace-content-filters' ), '700' => __( '700 Bold', 'ace-content-filters' ), '800' => __( '800 Extra Bold', 'ace-content-filters' ), '900' => __( '900 Black', 'ace-content-filters' ), ); } function acewpcf_get_text_transform_choices() { return array( '' => __( 'Theme default', 'ace-content-filters' ), 'none' => __( 'None', 'ace-content-filters' ), 'uppercase' => __( 'Uppercase', 'ace-content-filters' ), 'capitalize' => __( 'Capitalize', 'ace-content-filters' ), 'lowercase' => __( 'Lowercase', 'ace-content-filters' ), ); } function acewpcf_sanitize_font_family_choice( $value ) { $value = trim( wp_strip_all_tags( (string) $value ) ); if ( '' === $value ) { return ''; } $choices = acewpcf_get_font_family_choices(); $key = sanitize_key( $value ); if ( array_key_exists( $key, $choices ) ) { return $key; } foreach ( $choices as $choice_key => $choice ) { if ( isset( $choice['label'] ) && 0 === strcasecmp( $value, (string) $choice['label'] ) ) { return $choice_key; } } $value = preg_replace( '/[^A-Za-z0-9,\-\s"\']+/', '', $value ); $value = preg_replace( '/\s+/', ' ', trim( (string) $value ) ); return '' === $value ? '' : substr( $value, 0, 120 ); } function acewpcf_get_font_family_input_value( $value ) { $value = trim( (string) $value ); if ( '' === $value ) { return ''; } $choices = acewpcf_get_font_family_choices(); if ( isset( $choices[ $value ]['label'] ) ) { return (string) $choices[ $value ]['label']; } return acewpcf_sanitize_font_family_choice( $value ); } function acewpcf_get_font_family_css_value( $value ) { $choices = acewpcf_get_font_family_choices(); $value = trim( (string) $value ); if ( isset( $choices[ $value ]['css'] ) ) { return $choices[ $value ]['css']; } $value = acewpcf_sanitize_font_family_choice( $value ); if ( isset( $choices[ $value ]['css'] ) ) { return $choices[ $value ]['css']; } return $value; } function acewpcf_get_google_font_family_name( $value ) { $choices = acewpcf_get_font_family_choices(); $value = trim( (string) $value ); if ( isset( $choices[ $value ]['google'] ) ) { return (string) $choices[ $value ]['google']; } $value = acewpcf_sanitize_font_family_choice( $value ); if ( isset( $choices[ $value ]['google'] ) ) { return (string) $choices[ $value ]['google']; } if ( '' === $value ) { return ''; } $parts = explode( ',', $value ); $primary_family = trim( (string) $parts[0], " \t\n\r\0\x0B\"'" ); $generic_values = array( 'serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui', 'ui-serif', 'ui-sans-serif', 'ui-monospace', 'emoji', 'math', 'fangsong', 'segoe ui', ); if ( '' === $primary_family || in_array( strtolower( $primary_family ), $generic_values, true ) ) { return ''; } return $primary_family; } function acewpcf_get_google_fonts_url( $families ) { $families = is_array( $families ) ? $families : array(); $families = array_map( 'trim', $families ); $families = array_filter( $families ); $families = array_values( array_unique( $families ) ); if ( empty( $families ) ) { return ''; } $family_args = array(); foreach ( $families as $family ) { $family_args[] = 'family=' . urlencode( $family . ':wght@100;200;300;400;500;600;700;800;900' ); } return 'https://fonts.googleapis.com/css2?' . implode( '&', $family_args ) . '&display=swap'; } function acewpcf_get_excluded_content_types() { // Internal WordPress types, builder libraries, and WooCommerce catalog/commerce types. // WooCommerce product catalogs use different queries and are handled by the separate // ACE Product Filters plugin; this plugin focuses on posts, pages, and other public // site content. return array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block', 'wp_template', 'wp_template_part', 'wp_global_styles', 'wp_navigation', 'wp_font_family', 'wp_font_face', 'product', 'product_variation', 'shop_order', 'shop_coupon', 'elementor_library', ); } function acewpcf_get_content_type_choices() { $choices = array(); $post_types = get_post_types( array( 'public' => true ), 'objects' ); if ( empty( $post_types ) || ! is_array( $post_types ) ) { return array( 'post' => __( 'Posts', 'ace-content-filters' ), 'page' => __( 'Pages', 'ace-content-filters' ), ); } $excluded = acewpcf_get_excluded_content_types(); foreach ( $post_types as $post_type => $object ) { $post_type = sanitize_key( (string) $post_type ); if ( '' === $post_type || in_array( $post_type, $excluded, true ) ) { continue; } $label = ( $object instanceof WP_Post_Type && ! empty( $object->labels->name ) ) ? (string) $object->labels->name : ucwords( str_replace( array( '-', '_' ), ' ', $post_type ) ); $choices[ $post_type ] = $label; } if ( ! isset( $choices['post'] ) ) { $choices = array( 'post' => __( 'Posts', 'ace-content-filters' ) ) + $choices; } return $choices; } function acewpcf_sanitize_content_type( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_content_type_choices(); if ( isset( $choices[ $value ] ) ) { return $value; } return 'post'; } function acewpcf_get_content_taxonomy_choices( $content_type = 'post' ) { $content_type = acewpcf_sanitize_content_type( $content_type ); $choices = array(); $taxonomies = get_object_taxonomies( $content_type, 'objects' ); if ( empty( $taxonomies ) || ! is_array( $taxonomies ) ) { return $choices; } foreach ( $taxonomies as $taxonomy => $taxonomy_object ) { $taxonomy = sanitize_key( (string) $taxonomy ); if ( '' === $taxonomy || ! ( $taxonomy_object instanceof WP_Taxonomy ) ) { continue; } if ( ! empty( $taxonomy_object->public ) || ! empty( $taxonomy_object->publicly_queryable ) || ! empty( $taxonomy_object->show_ui ) ) { $label = ! empty( $taxonomy_object->labels->singular_name ) ? (string) $taxonomy_object->labels->singular_name : ucwords( str_replace( array( '-', '_' ), ' ', $taxonomy ) ); $choices[ $taxonomy ] = $label; } } return $choices; } function acewpcf_get_virtual_filter_source_types() { return array( 'search', 'author', 'date' ); } function acewpcf_is_virtual_filter_source_type( $value ) { return in_array( sanitize_key( (string) $value ), acewpcf_get_virtual_filter_source_types(), true ); } function acewpcf_is_virtual_filter( $filter ) { $filter = is_array( $filter ) ? $filter : array(); return acewpcf_is_virtual_filter_source_type( isset( $filter['source_type'] ) ? $filter['source_type'] : '' ); } function acewpcf_get_taxonomy_filter_source_types() { return array( 'category', 'tag', 'custom_taxonomy' ); } function acewpcf_is_taxonomy_filter_source_type( $value ) { return in_array( sanitize_key( (string) $value ), acewpcf_get_taxonomy_filter_source_types(), true ); } function acewpcf_get_filter_source_choices() { return array( 'category' => __( 'Categories', 'ace-content-filters' ), 'tag' => __( 'Tags', 'ace-content-filters' ), 'custom_taxonomy' => __( 'Custom taxonomy', 'ace-content-filters' ), 'search' => __( 'Search', 'ace-content-filters' ), 'author' => __( 'Author', 'ace-content-filters' ), 'date' => __( 'Date', 'ace-content-filters' ), ); } function acewpcf_get_filter_orientation_choices() { return array( 'horizontal' => __( 'Horizontal / Top bar', 'ace-content-filters' ), 'vertical' => __( 'Vertical / Left bar', 'ace-content-filters' ), ); } function acewpcf_sanitize_filter_source_type( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_source_choices(); return array_key_exists( $value, $choices ) ? $value : 'category'; } function acewpcf_sanitize_filter_orientation( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_orientation_choices(); return array_key_exists( $value, $choices ) ? $value : 'horizontal'; } function acewpcf_is_tag_taxonomy_slug( $taxonomy ) { $taxonomy = sanitize_key( (string) $taxonomy ); if ( '' === $taxonomy || 'category' === $taxonomy ) { return false; } if ( 'post_tag' === $taxonomy ) { return true; } return false !== strpos( $taxonomy, 'tag' ); } function acewpcf_get_tag_taxonomy_choices( $content_type = 'post' ) { $content_type = acewpcf_sanitize_content_type( $content_type ); $choices = array(); foreach ( acewpcf_get_content_taxonomy_choices( $content_type ) as $taxonomy => $label ) { if ( acewpcf_is_tag_taxonomy_slug( $taxonomy ) ) { $choices[ $taxonomy ] = $label; } } return $choices; } function acewpcf_get_custom_taxonomy_choices( $content_type = 'post' ) { $content_type = acewpcf_sanitize_content_type( $content_type ); $choices = array(); foreach ( acewpcf_get_content_taxonomy_choices( $content_type ) as $taxonomy => $label ) { if ( 'category' !== $taxonomy && 'post_tag' !== $taxonomy ) { $choices[ $taxonomy ] = $label; } } return $choices; } function acewpcf_get_default_taxonomy_for_source( $source_type, $content_type = 'post' ) { $source_type = acewpcf_sanitize_filter_source_type( $source_type ); $content_type = acewpcf_sanitize_content_type( $content_type ); $available = acewpcf_get_content_taxonomy_choices( $content_type ); if ( 'tag' === $source_type ) { if ( isset( $available['post_tag'] ) ) { return 'post_tag'; } foreach ( $available as $taxonomy => $label ) { unset( $label ); if ( false !== strpos( $taxonomy, 'tag' ) ) { return $taxonomy; } } } if ( 'category' === $source_type ) { if ( isset( $available['category'] ) ) { return 'category'; } $first = array_key_first( $available ); return is_string( $first ) ? $first : ''; } if ( 'custom_taxonomy' === $source_type ) { foreach ( $available as $taxonomy => $label ) { unset( $label ); if ( 'category' !== $taxonomy && 'post_tag' !== $taxonomy ) { return $taxonomy; } } $first = array_key_first( $available ); return is_string( $first ) ? $first : ''; } return ''; } function acewpcf_sanitize_filter_source_taxonomy( $source_type, $value, $content_type = 'post' ) { $source_type = acewpcf_sanitize_filter_source_type( $source_type ); $content_type = acewpcf_sanitize_content_type( $content_type ); $value = sanitize_key( (string) $value ); if ( acewpcf_is_virtual_filter_source_type( $source_type ) ) { return ''; } $available = acewpcf_get_content_taxonomy_choices( $content_type ); if ( 'category' === $source_type ) { if ( isset( $available['category'] ) ) { return 'category'; } return acewpcf_get_default_taxonomy_for_source( 'category', $content_type ); } if ( 'tag' === $source_type ) { $tag_choices = acewpcf_get_tag_taxonomy_choices( $content_type ); if ( isset( $tag_choices[ $value ] ) ) { return $value; } return acewpcf_get_default_taxonomy_for_source( 'tag', $content_type ); } $custom_choices = acewpcf_get_custom_taxonomy_choices( $content_type ); if ( isset( $custom_choices[ $value ] ) ) { return $value; } return acewpcf_get_default_taxonomy_for_source( 'custom_taxonomy', $content_type ); } function acewpcf_get_filter_taxonomy( $filter ) { $filter = is_array( $filter ) ? $filter : array(); $source_type = isset( $filter['source_type'] ) ? acewpcf_sanitize_filter_source_type( $filter['source_type'] ) : 'category'; $content_type = isset( $filter['content_type'] ) ? acewpcf_sanitize_content_type( $filter['content_type'] ) : 'post'; if ( acewpcf_is_virtual_filter_source_type( $source_type ) ) { return ''; } return acewpcf_sanitize_filter_source_taxonomy( $source_type, isset( $filter['source_taxonomy'] ) ? $filter['source_taxonomy'] : '', $content_type ); } function acewpcf_filter_uses_terms( $filter ) { $filter = is_array( $filter ) ? $filter : array(); $source = isset( $filter['source_type'] ) ? acewpcf_sanitize_filter_source_type( $filter['source_type'] ) : 'category'; return acewpcf_is_taxonomy_filter_source_type( $source ); } function acewpcf_is_search_filter( $filter ) { $filter = is_array( $filter ) ? $filter : array(); return 'search' === acewpcf_sanitize_filter_source_type( isset( $filter['source_type'] ) ? $filter['source_type'] : '' ); } function acewpcf_is_author_filter( $filter ) { $filter = is_array( $filter ) ? $filter : array(); return 'author' === acewpcf_sanitize_filter_source_type( isset( $filter['source_type'] ) ? $filter['source_type'] : '' ); } function acewpcf_is_date_filter( $filter ) { $filter = is_array( $filter ) ? $filter : array(); return 'date' === acewpcf_sanitize_filter_source_type( isset( $filter['source_type'] ) ? $filter['source_type'] : '' ); } function acewpcf_get_option_list_filter_source_types() { return array( 'author', 'date' ); } function acewpcf_is_option_list_filter_source_type( $value ) { return in_array( sanitize_key( (string) $value ), acewpcf_get_option_list_filter_source_types(), true ); } function acewpcf_is_option_list_filter( $filter ) { $filter = is_array( $filter ) ? $filter : array(); return acewpcf_is_option_list_filter_source_type( isset( $filter['source_type'] ) ? $filter['source_type'] : '' ); } function acewpcf_get_default_filter_set() { return array( 'id' => '', 'name' => '', 'panel_heading' => '', 'show_panel_heading' => 1, 'panel_collapsible' => 0, 'panel_collapsed_by_default' => 0, 'source_type' => 'category', 'source_taxonomy' => 'category', 'content_type' => 'post', 'search_placeholder' => '', 'date_granularity' => 'month', 'orientation' => 'horizontal', 'selection_mode' => 'single', 'show_label' => 1, 'show_count' => 1, 'count_display_mode' => 'contextual', 'hide_zero_count_terms' => 0, 'term_search_mode' => 'terms', 'term_search_placeholder' => '', 'term_search_empty_message' => '', 'display_mode' => 'buttons', 'swatch_shape' => 'square', 'swatch_layout' => 'wrap', 'term_colors' => array(), 'ajax_enabled' => 0, 'results_selector' => '', 'empty_results_message' => '', 'responsive_layouts' => acewpcf_get_default_filter_responsive_layouts(), 'term_ids' => array(), 'term_order' => array(), 'option_keys' => array(), 'option_order' => array(), 'styles' => acewpcf_get_default_filter_styles(), 'match_logic' => 'or', 'include_child_terms' => 0, 'show_term_hierarchy' => 0, 'group_header' => '', // Legacy fallback; group headings now live on panels. ); } function acewpcf_is_supported_content_taxonomy( $taxonomy ) { $taxonomy = sanitize_key( (string) $taxonomy ); return '' !== $taxonomy && taxonomy_exists( $taxonomy ); } function acewpcf_get_filter_layout_choices() { return array( 'buttons' => __( 'Buttons list', 'ace-content-filters' ), 'dropdown' => __( 'Selected item with dropdown', 'ace-content-filters' ), ); } function acewpcf_get_default_filter_responsive_layouts() { return array( 'tablet' => 'dropdown', 'mobile' => 'dropdown', ); } function acewpcf_sanitize_filter_layout_value( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_layout_choices(); return array_key_exists( $value, $choices ) ? $value : 'buttons'; } function acewpcf_sanitize_filter_responsive_layouts( $layouts ) { $defaults = acewpcf_get_default_filter_responsive_layouts(); $layouts = is_array( $layouts ) ? $layouts : array(); $sanitized = array( 'tablet' => isset( $layouts['tablet'] ) ? acewpcf_sanitize_filter_layout_value( $layouts['tablet'] ) : $defaults['tablet'], 'mobile' => isset( $layouts['mobile'] ) ? acewpcf_sanitize_filter_layout_value( $layouts['mobile'] ) : $defaults['mobile'], ); return wp_parse_args( $sanitized, $defaults ); } function acewpcf_sanitize_results_selector( $value ) { $value = sanitize_text_field( (string) $value ); $value = preg_replace( '/\s+/', ' ', trim( $value ) ); return '' === $value ? '' : substr( $value, 0, 190 ); } function acewpcf_sanitize_empty_results_message( $value ) { $value = sanitize_text_field( (string) $value ); $value = preg_replace( '/\s+/', ' ', trim( $value ) ); return '' === $value ? '' : substr( $value, 0, 220 ); } function acewpcf_sanitize_panel_control_label( $value ) { $value = sanitize_text_field( (string) $value ); $value = preg_replace( '/\s+/', ' ', trim( $value ) ); return '' === $value ? '' : substr( $value, 0, 80 ); } function acewpcf_get_filter_count_display_mode_choices() { return array( 'contextual' => __( 'Contextual counts', 'ace-content-filters' ), 'static' => __( 'Static term counts', 'ace-content-filters' ), ); } function acewpcf_get_panel_count_display_mode_choices() { return array( 'inherit' => __( 'Use each filter setting', 'ace-content-filters' ), 'contextual' => __( 'Force contextual counts for this panel', 'ace-content-filters' ), 'static' => __( 'Force static counts for this panel', 'ace-content-filters' ), ); } function acewpcf_sanitize_filter_count_display_mode( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_count_display_mode_choices(); return isset( $choices[ $value ] ) ? $value : 'contextual'; } function acewpcf_sanitize_panel_count_display_mode( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_panel_count_display_mode_choices(); return isset( $choices[ $value ] ) ? $value : 'inherit'; } function acewpcf_get_panel_hide_zero_count_terms_choices() { return array( 'inherit' => __( 'Use each filter setting', 'ace-content-filters' ), 'hide' => __( 'Hide empty terms', 'ace-content-filters' ), 'show' => __( 'Keep empty terms visible', 'ace-content-filters' ), ); } function acewpcf_sanitize_panel_hide_zero_count_terms( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_panel_hide_zero_count_terms_choices(); return isset( $choices[ $value ] ) ? $value : 'inherit'; } function acewpcf_get_filter_term_search_mode_choices() { return array( 'terms' => __( 'Terms only', 'ace-content-filters' ), 'search_and_terms' => __( 'Search box and terms', 'ace-content-filters' ), ); } function acewpcf_get_panel_term_search_mode_choices() { return array( 'inherit' => __( 'Use each filter setting', 'ace-content-filters' ), 'terms' => __( 'Terms only', 'ace-content-filters' ), 'search_and_terms' => __( 'Search box and terms', 'ace-content-filters' ), ); } function acewpcf_sanitize_filter_term_search_mode( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_term_search_mode_choices(); if ( 'search' === $value ) { $value = 'search_and_terms'; } return isset( $choices[ $value ] ) ? $value : 'terms'; } function acewpcf_sanitize_panel_term_search_mode( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_panel_term_search_mode_choices(); if ( 'search' === $value ) { $value = 'search_and_terms'; } return isset( $choices[ $value ] ) ? $value : 'inherit'; } function acewpcf_get_filter_display_mode_choices() { return array( 'buttons' => __( 'Text buttons', 'ace-content-filters' ), 'swatches' => __( 'Colour swatches', 'ace-content-filters' ), ); } function acewpcf_get_filter_swatch_shape_choices() { return array( 'square' => __( 'Square', 'ace-content-filters' ), 'circle' => __( 'Circle', 'ace-content-filters' ), ); } function acewpcf_get_filter_swatch_layout_choices() { return array( 'wrap' => __( 'Spread', 'ace-content-filters' ), 'stack' => __( 'Column', 'ace-content-filters' ), ); } function acewpcf_sanitize_filter_display_mode( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_display_mode_choices(); return isset( $choices[ $value ] ) ? $value : 'buttons'; } function acewpcf_sanitize_filter_swatch_shape( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_swatch_shape_choices(); return isset( $choices[ $value ] ) ? $value : 'square'; } function acewpcf_sanitize_filter_swatch_layout( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_swatch_layout_choices(); return isset( $choices[ $value ] ) ? $value : 'wrap'; } function acewpcf_normalize_hex_color( $value ) { $value = trim( (string) $value ); if ( '' === $value ) { return ''; } if ( '#' !== substr( $value, 0, 1 ) ) { $value = '#' . $value; } if ( preg_match( '/^#([A-Fa-f0-9]{3})$/', $value, $matches ) ) { $digits = $matches[1]; $value = '#' . $digits[0] . $digits[0] . $digits[1] . $digits[1] . $digits[2] . $digits[2]; } $sanitized = sanitize_hex_color( $value ); return $sanitized ? strtolower( $sanitized ) : ''; } function acewpcf_sanitize_filter_term_colors( $colors, $existing_colors = array() ) { $sanitized = array(); $existing = is_array( $existing_colors ) ? $existing_colors : array(); $colors = is_array( $colors ) ? $colors : array(); foreach ( $existing as $term_id => $color ) { $term_id = absint( $term_id ); $color = acewpcf_normalize_hex_color( $color ); if ( $term_id && $color ) { $sanitized[ $term_id ] = $color; } } foreach ( $colors as $term_id => $color ) { $term_id = absint( $term_id ); $color = acewpcf_normalize_hex_color( $color ); if ( ! $term_id ) { continue; } if ( $color ) { $sanitized[ $term_id ] = $color; } else { unset( $sanitized[ $term_id ] ); } } return $sanitized; } function acewpcf_get_generated_id_base( $label, $fallback = 'filter' ) { $label = sanitize_text_field( (string) $label ); $fallback = sanitize_key( (string) $fallback ); $base = sanitize_title( preg_replace( '/\s+/', ' ', trim( $label ) ) ); $base = preg_replace( '/(?:-(?:copy|duplicate))(?:-\d+)?$/', '', $base ); $base = trim( (string) $base, '-' ); if ( '' === $base ) { $base = '' !== $fallback ? $fallback : 'filter'; } return substr( $base, 0, 40 ); } function acewpcf_generate_filter_id( $label = 'filter', $existing_ids = array(), $fallback = 'filter' ) { $base = acewpcf_get_generated_id_base( $label, $fallback ); $existing_ids = is_array( $existing_ids ) ? $existing_ids : array(); $existing_map = array(); foreach ( $existing_ids as $existing_id ) { $existing_id = sanitize_key( (string) $existing_id ); if ( '' !== $existing_id ) { $existing_map[ $existing_id ] = true; } } if ( ! isset( $existing_map[ $base ] ) ) { return $base; } $counter = 2; while ( true ) { $suffix = '-' . $counter; $candidate = substr( $base, 0, max( 1, 40 - strlen( $suffix ) ) ) . $suffix; if ( ! isset( $existing_map[ $candidate ] ) ) { return $candidate; } ++$counter; } } function acewpcf_resolve_editable_object_id( $current_id, $requested_id, $name_source, $existing_ids = array(), $fallback = 'filter' ) { $current_id = sanitize_key( (string) $current_id ); $requested_id = sanitize_key( (string) $requested_id ); $fallback = sanitize_key( (string) $fallback ); $existing_ids = is_array( $existing_ids ) ? $existing_ids : array(); $available_ids = array(); foreach ( $existing_ids as $existing_id ) { $existing_id = sanitize_key( (string) $existing_id ); if ( '' === $existing_id || $existing_id === $current_id ) { continue; } $available_ids[] = $existing_id; } if ( '' !== $requested_id ) { if ( ! in_array( $requested_id, $available_ids, true ) ) { return $requested_id; } return acewpcf_generate_filter_id( $requested_id, $available_ids, $fallback ); } if ( '' !== $current_id ) { return $current_id; } return acewpcf_generate_filter_id( $name_source, $available_ids, $fallback ); } function acewpcf_replace_associative_entry_preserving_order( $items, $current_id, $new_id, $new_value ) { $items = is_array( $items ) ? $items : array(); $current_id = sanitize_key( (string) $current_id ); $new_id = sanitize_key( (string) $new_id ); if ( '' === $new_id ) { return $items; } if ( '' === $current_id || $current_id === $new_id || ! array_key_exists( $current_id, $items ) ) { $items[ $new_id ] = $new_value; return $items; } $updated_items = array(); foreach ( $items as $item_id => $item_value ) { if ( $item_id === $current_id ) { $updated_items[ $new_id ] = $new_value; continue; } $updated_items[ $item_id ] = $item_value; } return $updated_items; } function acewpcf_sanitize_size_value( $value ) { if ( is_array( $value ) || is_object( $value ) ) { return ''; } $value = trim( wp_strip_all_tags( (string) $value ) ); if ( '' === $value || ! is_numeric( $value ) ) { return ''; } return (string) absint( $value ); } function acewpcf_sanitize_font_weight_value( $value ) { $value = trim( (string) $value ); $choices = acewpcf_get_font_weight_choices(); return array_key_exists( $value, $choices ) ? $value : ''; } function acewpcf_sanitize_letter_spacing_value( $value ) { if ( is_array( $value ) || is_object( $value ) ) { return ''; } $value = trim( wp_strip_all_tags( (string) $value ) ); if ( '' === $value || ! is_numeric( $value ) ) { return ''; } $value = round( (float) $value, 2 ); if ( $value > 20 ) { $value = 20; } elseif ( $value < -20 ) { $value = -20; } $value = number_format( $value, 2, '.', '' ); $value = rtrim( rtrim( $value, '0' ), '.' ); return '-0' === $value ? '0' : $value; } function acewpcf_sanitize_text_transform_value( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_text_transform_choices(); return array_key_exists( $value, $choices ) ? $value : ''; } function acewpcf_sanitize_responsive_style_overrides( $styles ) { $defaults = acewpcf_get_default_responsive_style_overrides(); $styles = is_array( $styles ) ? $styles : array(); $sanitized = array( 'label_font_size' => isset( $styles['label_font_size'] ) ? acewpcf_sanitize_size_value( $styles['label_font_size'] ) : '', 'panel_heading_font_size' => isset( $styles['panel_heading_font_size'] ) ? acewpcf_sanitize_size_value( $styles['panel_heading_font_size'] ) : '', 'count_font_size' => isset( $styles['count_font_size'] ) ? acewpcf_sanitize_size_value( $styles['count_font_size'] ) : '', 'button_font_size' => isset( $styles['button_font_size'] ) ? acewpcf_sanitize_size_value( $styles['button_font_size'] ) : '', 'button_padding_y' => isset( $styles['button_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['button_padding_y'] ) : '', 'button_padding_x' => isset( $styles['button_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['button_padding_x'] ) : '', 'gap' => isset( $styles['gap'] ) ? acewpcf_sanitize_size_value( $styles['gap'] ) : '', ); return wp_parse_args( $sanitized, $defaults ); } function acewpcf_validate_filter_term_ids( $taxonomy, $term_ids ) { $taxonomy = sanitize_key( (string) $taxonomy ); $term_ids = is_array( $term_ids ) ? $term_ids : array(); $term_ids = array_map( 'absint', $term_ids ); $term_ids = array_filter( $term_ids ); $term_ids = array_values( array_unique( $term_ids ) ); if ( empty( $term_ids ) || ! taxonomy_exists( $taxonomy ) ) { return array(); } $valid_terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'include' => $term_ids, 'fields' => 'ids', ) ); if ( is_wp_error( $valid_terms ) ) { return array(); } $valid_term_lookup = array_fill_keys( array_map( 'absint', $valid_terms ), true ); $ordered_term_ids = array(); foreach ( $term_ids as $term_id ) { if ( isset( $valid_term_lookup[ $term_id ] ) ) { $ordered_term_ids[] = $term_id; } } return $ordered_term_ids; } function acewpcf_sort_term_ids_by_order( $term_ids, $term_order ) { $term_ids = array_values( array_filter( array_unique( array_map( 'absint', is_array( $term_ids ) ? $term_ids : array() ) ) ) ); $term_order = is_array( $term_order ) ? $term_order : array(); if ( ! empty( $term_order ) && array_keys( $term_order ) === range( 0, count( $term_order ) - 1 ) ) { $normalized_term_order = array(); foreach ( $term_order as $index => $term_id ) { $term_id = absint( $term_id ); if ( $term_id > 0 ) { $normalized_term_order[ $term_id ] = $index + 1; } } $term_order = $normalized_term_order; } if ( empty( $term_ids ) || empty( $term_order ) ) { return $term_ids; } $order_map = array(); foreach ( $term_ids as $index => $term_id ) { $raw_order = isset( $term_order[ $term_id ] ) ? trim( (string) $term_order[ $term_id ] ) : ''; $order_map[ $term_id ] = array( 'order' => '' === $raw_order ? 1000 + $index : max( 1, absint( $raw_order ) ), 'index' => $index, ); } usort( $term_ids, static function ( $left, $right ) use ( $order_map ) { $left_position = isset( $order_map[ $left ] ) ? $order_map[ $left ] : array( 'order' => 1000, 'index' => 0, ); $right_position = isset( $order_map[ $right ] ) ? $order_map[ $right ] : array( 'order' => 1000, 'index' => 0, ); if ( $left_position['order'] === $right_position['order'] ) { return $left_position['index'] <=> $right_position['index']; } return $left_position['order'] <=> $right_position['order']; } ); return $term_ids; } function acewpcf_sanitize_filter_styles( $styles ) { $defaults = acewpcf_get_default_filter_styles(); $styles = is_array( $styles ) ? $styles : array(); $responsive_styles = array(); foreach ( acewpcf_get_responsive_style_modes() as $mode_key => $mode ) { $responsive_styles[ $mode_key ] = acewpcf_sanitize_responsive_style_overrides( isset( $styles['responsive'][ $mode_key ] ) ? $styles['responsive'][ $mode_key ] : array() ); } $sanitized = array( 'label_color' => isset( $styles['label_color'] ) ? sanitize_hex_color( $styles['label_color'] ) : '', 'label_font_family' => isset( $styles['label_font_family'] ) ? acewpcf_sanitize_font_family_choice( $styles['label_font_family'] ) : '', 'label_font_weight' => isset( $styles['label_font_weight'] ) ? acewpcf_sanitize_font_weight_value( $styles['label_font_weight'] ) : '', 'label_font_size' => isset( $styles['label_font_size'] ) ? acewpcf_sanitize_size_value( $styles['label_font_size'] ) : '', 'label_letter_spacing' => isset( $styles['label_letter_spacing'] ) ? acewpcf_sanitize_letter_spacing_value( $styles['label_letter_spacing'] ) : '', 'label_text_transform' => isset( $styles['label_text_transform'] ) ? acewpcf_sanitize_text_transform_value( $styles['label_text_transform'] ) : '', 'panel_heading_color' => isset( $styles['panel_heading_color'] ) ? sanitize_hex_color( $styles['panel_heading_color'] ) : '', 'panel_heading_font_family' => isset( $styles['panel_heading_font_family'] ) ? acewpcf_sanitize_font_family_choice( $styles['panel_heading_font_family'] ) : '', 'panel_heading_font_weight' => isset( $styles['panel_heading_font_weight'] ) ? acewpcf_sanitize_font_weight_value( $styles['panel_heading_font_weight'] ) : '', 'panel_heading_font_size' => isset( $styles['panel_heading_font_size'] ) ? acewpcf_sanitize_size_value( $styles['panel_heading_font_size'] ) : '', 'panel_heading_letter_spacing' => isset( $styles['panel_heading_letter_spacing'] ) ? acewpcf_sanitize_letter_spacing_value( $styles['panel_heading_letter_spacing'] ) : '', 'panel_heading_text_transform' => isset( $styles['panel_heading_text_transform'] ) ? acewpcf_sanitize_text_transform_value( $styles['panel_heading_text_transform'] ) : '', 'panel_toggle_icon_color' => isset( $styles['panel_toggle_icon_color'] ) ? sanitize_hex_color( $styles['panel_toggle_icon_color'] ) : '', 'panel_toggle_icon_size' => isset( $styles['panel_toggle_icon_size'] ) ? acewpcf_sanitize_size_value( $styles['panel_toggle_icon_size'] ) : '', 'panel_toggle_hover_icon_color' => isset( $styles['panel_toggle_hover_icon_color'] ) ? sanitize_hex_color( $styles['panel_toggle_hover_icon_color'] ) : '', 'panel_toggle_hover_background_color' => isset( $styles['panel_toggle_hover_background_color'] ) ? sanitize_hex_color( $styles['panel_toggle_hover_background_color'] ) : '', 'panel_toggle_active_icon_color' => isset( $styles['panel_toggle_active_icon_color'] ) ? sanitize_hex_color( $styles['panel_toggle_active_icon_color'] ) : '', 'panel_toggle_active_background_color' => isset( $styles['panel_toggle_active_background_color'] ) ? sanitize_hex_color( $styles['panel_toggle_active_background_color'] ) : '', 'count_color' => isset( $styles['count_color'] ) ? sanitize_hex_color( $styles['count_color'] ) : '', 'count_font_family' => isset( $styles['count_font_family'] ) ? acewpcf_sanitize_font_family_choice( $styles['count_font_family'] ) : '', 'count_font_weight' => isset( $styles['count_font_weight'] ) ? acewpcf_sanitize_font_weight_value( $styles['count_font_weight'] ) : '', 'count_font_size' => isset( $styles['count_font_size'] ) ? acewpcf_sanitize_size_value( $styles['count_font_size'] ) : '', 'count_letter_spacing' => isset( $styles['count_letter_spacing'] ) ? acewpcf_sanitize_letter_spacing_value( $styles['count_letter_spacing'] ) : '', 'count_text_transform' => isset( $styles['count_text_transform'] ) ? acewpcf_sanitize_text_transform_value( $styles['count_text_transform'] ) : '', 'button_text_color' => isset( $styles['button_text_color'] ) ? sanitize_hex_color( $styles['button_text_color'] ) : '', 'button_font_family' => isset( $styles['button_font_family'] ) ? acewpcf_sanitize_font_family_choice( $styles['button_font_family'] ) : '', 'button_font_weight' => isset( $styles['button_font_weight'] ) ? acewpcf_sanitize_font_weight_value( $styles['button_font_weight'] ) : '', 'button_background_color' => isset( $styles['button_background_color'] ) ? sanitize_hex_color( $styles['button_background_color'] ) : '', 'button_border_color' => isset( $styles['button_border_color'] ) ? sanitize_hex_color( $styles['button_border_color'] ) : '', 'button_border_width' => isset( $styles['button_border_width'] ) ? acewpcf_sanitize_size_value( $styles['button_border_width'] ) : '', 'checkbox_size' => isset( $styles['checkbox_size'] ) ? acewpcf_sanitize_size_value( $styles['checkbox_size'] ) : '', 'checkbox_border_width' => isset( $styles['checkbox_border_width'] ) ? acewpcf_sanitize_size_value( $styles['checkbox_border_width'] ) : '', 'checkbox_border_radius' => isset( $styles['checkbox_border_radius'] ) ? acewpcf_sanitize_size_value( $styles['checkbox_border_radius'] ) : '', 'button_font_size' => isset( $styles['button_font_size'] ) ? acewpcf_sanitize_size_value( $styles['button_font_size'] ) : '', 'button_padding_y' => isset( $styles['button_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['button_padding_y'] ) : '', 'button_padding_x' => isset( $styles['button_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['button_padding_x'] ) : '', 'gap' => isset( $styles['gap'] ) ? acewpcf_sanitize_size_value( $styles['gap'] ) : '', 'button_letter_spacing' => isset( $styles['button_letter_spacing'] ) ? acewpcf_sanitize_letter_spacing_value( $styles['button_letter_spacing'] ) : '', 'button_text_transform' => isset( $styles['button_text_transform'] ) ? acewpcf_sanitize_text_transform_value( $styles['button_text_transform'] ) : '', 'active_text_color' => isset( $styles['active_text_color'] ) ? sanitize_hex_color( $styles['active_text_color'] ) : '', 'active_background_color' => isset( $styles['active_background_color'] ) ? sanitize_hex_color( $styles['active_background_color'] ) : '', 'active_border_color' => isset( $styles['active_border_color'] ) ? sanitize_hex_color( $styles['active_border_color'] ) : '', 'button_hover_text_color' => isset( $styles['button_hover_text_color'] ) ? sanitize_hex_color( $styles['button_hover_text_color'] ) : '', 'button_hover_background_color' => isset( $styles['button_hover_background_color'] ) ? sanitize_hex_color( $styles['button_hover_background_color'] ) : '', 'button_hover_border_color' => isset( $styles['button_hover_border_color'] ) ? sanitize_hex_color( $styles['button_hover_border_color'] ) : '', 'border_radius' => isset( $styles['border_radius'] ) ? acewpcf_sanitize_size_value( $styles['border_radius'] ) : '', 'empty_results_text_color' => isset( $styles['empty_results_text_color'] ) ? sanitize_hex_color( $styles['empty_results_text_color'] ) : '', 'empty_results_background_color' => isset( $styles['empty_results_background_color'] ) ? sanitize_hex_color( $styles['empty_results_background_color'] ) : '', 'empty_results_border_color' => isset( $styles['empty_results_border_color'] ) ? sanitize_hex_color( $styles['empty_results_border_color'] ) : '', 'empty_results_font_size' => isset( $styles['empty_results_font_size'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_font_size'] ) : '', 'empty_results_padding_y' => isset( $styles['empty_results_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_padding_y'] ) : '', 'empty_results_padding_x' => isset( $styles['empty_results_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_padding_x'] ) : '', 'empty_results_border_radius' => isset( $styles['empty_results_border_radius'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_border_radius'] ) : '', 'term_search_text_color' => isset( $styles['term_search_text_color'] ) ? sanitize_hex_color( $styles['term_search_text_color'] ) : '', 'term_search_placeholder_color' => isset( $styles['term_search_placeholder_color'] ) ? sanitize_hex_color( $styles['term_search_placeholder_color'] ) : '', 'term_search_background_color' => isset( $styles['term_search_background_color'] ) ? sanitize_hex_color( $styles['term_search_background_color'] ) : '', 'term_search_border_color' => isset( $styles['term_search_border_color'] ) ? sanitize_hex_color( $styles['term_search_border_color'] ) : '', 'term_search_border_width' => isset( $styles['term_search_border_width'] ) ? acewpcf_sanitize_size_value( $styles['term_search_border_width'] ) : '', 'term_search_border_radius' => isset( $styles['term_search_border_radius'] ) ? acewpcf_sanitize_size_value( $styles['term_search_border_radius'] ) : '', 'term_search_font_family' => isset( $styles['term_search_font_family'] ) ? acewpcf_sanitize_font_family_choice( $styles['term_search_font_family'] ) : '', 'term_search_font_weight' => isset( $styles['term_search_font_weight'] ) ? acewpcf_sanitize_font_weight_value( $styles['term_search_font_weight'] ) : '', 'term_search_font_size' => isset( $styles['term_search_font_size'] ) ? acewpcf_sanitize_size_value( $styles['term_search_font_size'] ) : '', 'term_search_letter_spacing' => isset( $styles['term_search_letter_spacing'] ) ? acewpcf_sanitize_letter_spacing_value( $styles['term_search_letter_spacing'] ) : '', 'term_search_text_transform' => isset( $styles['term_search_text_transform'] ) ? acewpcf_sanitize_text_transform_value( $styles['term_search_text_transform'] ) : '', 'term_search_padding_y' => isset( $styles['term_search_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['term_search_padding_y'] ) : '', 'term_search_padding_x' => isset( $styles['term_search_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['term_search_padding_x'] ) : '', 'term_search_focus_border_color' => isset( $styles['term_search_focus_border_color'] ) ? sanitize_hex_color( $styles['term_search_focus_border_color'] ) : '', 'term_search_list_max_height' => isset( $styles['term_search_list_max_height'] ) ? acewpcf_sanitize_size_value( $styles['term_search_list_max_height'] ) : '', 'swatch_size' => isset( $styles['swatch_size'] ) ? acewpcf_sanitize_size_value( $styles['swatch_size'] ) : '', 'swatch_background_color' => isset( $styles['swatch_background_color'] ) ? sanitize_hex_color( $styles['swatch_background_color'] ) : '', 'responsive' => $responsive_styles, ); return wp_parse_args( $sanitized, $defaults ); } function acewpcf_sanitize_filter_panel_styles( $styles ) { $defaults = acewpcf_get_default_filter_panel_styles(); $styles = is_array( $styles ) ? $styles : array(); $sanitized = array( 'clear_all_text_color' => isset( $styles['clear_all_text_color'] ) ? sanitize_hex_color( $styles['clear_all_text_color'] ) : '', 'clear_all_background_color' => isset( $styles['clear_all_background_color'] ) ? sanitize_hex_color( $styles['clear_all_background_color'] ) : '', 'clear_all_border_color' => isset( $styles['clear_all_border_color'] ) ? sanitize_hex_color( $styles['clear_all_border_color'] ) : '', 'clear_all_font_size' => isset( $styles['clear_all_font_size'] ) ? acewpcf_sanitize_size_value( $styles['clear_all_font_size'] ) : '', 'clear_all_padding_y' => isset( $styles['clear_all_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['clear_all_padding_y'] ) : '', 'clear_all_padding_x' => isset( $styles['clear_all_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['clear_all_padding_x'] ) : '', 'clear_all_border_radius' => isset( $styles['clear_all_border_radius'] ) ? acewpcf_sanitize_size_value( $styles['clear_all_border_radius'] ) : '', 'clear_all_hover_text_color' => isset( $styles['clear_all_hover_text_color'] ) ? sanitize_hex_color( $styles['clear_all_hover_text_color'] ) : '', 'clear_all_hover_background_color' => isset( $styles['clear_all_hover_background_color'] ) ? sanitize_hex_color( $styles['clear_all_hover_background_color'] ) : '', 'clear_all_hover_border_color' => isset( $styles['clear_all_hover_border_color'] ) ? sanitize_hex_color( $styles['clear_all_hover_border_color'] ) : '', 'empty_results_text_color' => isset( $styles['empty_results_text_color'] ) ? sanitize_hex_color( $styles['empty_results_text_color'] ) : '', 'empty_results_background_color' => isset( $styles['empty_results_background_color'] ) ? sanitize_hex_color( $styles['empty_results_background_color'] ) : '', 'empty_results_border_color' => isset( $styles['empty_results_border_color'] ) ? sanitize_hex_color( $styles['empty_results_border_color'] ) : '', 'empty_results_font_size' => isset( $styles['empty_results_font_size'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_font_size'] ) : '', 'empty_results_padding_y' => isset( $styles['empty_results_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_padding_y'] ) : '', 'empty_results_padding_x' => isset( $styles['empty_results_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_padding_x'] ) : '', 'empty_results_border_radius' => isset( $styles['empty_results_border_radius'] ) ? acewpcf_sanitize_size_value( $styles['empty_results_border_radius'] ) : '', 'mobile_toggle_text_color' => isset( $styles['mobile_toggle_text_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_text_color'] ) : '', 'mobile_toggle_background_color' => isset( $styles['mobile_toggle_background_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_background_color'] ) : '', 'mobile_toggle_border_color' => isset( $styles['mobile_toggle_border_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_border_color'] ) : '', 'mobile_toggle_border_width' => isset( $styles['mobile_toggle_border_width'] ) ? acewpcf_sanitize_size_value( $styles['mobile_toggle_border_width'] ) : '', 'mobile_toggle_font_family' => isset( $styles['mobile_toggle_font_family'] ) ? acewpcf_sanitize_font_family_choice( $styles['mobile_toggle_font_family'] ) : '', 'mobile_toggle_font_weight' => isset( $styles['mobile_toggle_font_weight'] ) ? acewpcf_sanitize_font_weight_value( $styles['mobile_toggle_font_weight'] ) : '', 'mobile_toggle_font_size' => isset( $styles['mobile_toggle_font_size'] ) ? acewpcf_sanitize_size_value( $styles['mobile_toggle_font_size'] ) : '', 'mobile_toggle_letter_spacing' => isset( $styles['mobile_toggle_letter_spacing'] ) ? acewpcf_sanitize_letter_spacing_value( $styles['mobile_toggle_letter_spacing'] ) : '', 'mobile_toggle_text_transform' => isset( $styles['mobile_toggle_text_transform'] ) ? acewpcf_sanitize_text_transform_value( $styles['mobile_toggle_text_transform'] ) : '', 'mobile_toggle_padding_y' => isset( $styles['mobile_toggle_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['mobile_toggle_padding_y'] ) : '', 'mobile_toggle_padding_x' => isset( $styles['mobile_toggle_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['mobile_toggle_padding_x'] ) : '', 'mobile_toggle_border_radius' => isset( $styles['mobile_toggle_border_radius'] ) ? acewpcf_sanitize_size_value( $styles['mobile_toggle_border_radius'] ) : '', 'mobile_toggle_hover_text_color' => isset( $styles['mobile_toggle_hover_text_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_hover_text_color'] ) : '', 'mobile_toggle_hover_background_color' => isset( $styles['mobile_toggle_hover_background_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_hover_background_color'] ) : '', 'mobile_toggle_hover_border_color' => isset( $styles['mobile_toggle_hover_border_color'] ) ? sanitize_hex_color( $styles['mobile_toggle_hover_border_color'] ) : '', 'mobile_close_text_color' => isset( $styles['mobile_close_text_color'] ) ? sanitize_hex_color( $styles['mobile_close_text_color'] ) : '', 'mobile_close_background_color' => isset( $styles['mobile_close_background_color'] ) ? sanitize_hex_color( $styles['mobile_close_background_color'] ) : '', 'mobile_close_border_color' => isset( $styles['mobile_close_border_color'] ) ? sanitize_hex_color( $styles['mobile_close_border_color'] ) : '', 'mobile_close_border_width' => isset( $styles['mobile_close_border_width'] ) ? acewpcf_sanitize_size_value( $styles['mobile_close_border_width'] ) : '', 'mobile_close_font_family' => isset( $styles['mobile_close_font_family'] ) ? acewpcf_sanitize_font_family_choice( $styles['mobile_close_font_family'] ) : '', 'mobile_close_font_weight' => isset( $styles['mobile_close_font_weight'] ) ? acewpcf_sanitize_font_weight_value( $styles['mobile_close_font_weight'] ) : '', 'mobile_close_font_size' => isset( $styles['mobile_close_font_size'] ) ? acewpcf_sanitize_size_value( $styles['mobile_close_font_size'] ) : '', 'mobile_close_letter_spacing' => isset( $styles['mobile_close_letter_spacing'] ) ? acewpcf_sanitize_letter_spacing_value( $styles['mobile_close_letter_spacing'] ) : '', 'mobile_close_text_transform' => isset( $styles['mobile_close_text_transform'] ) ? acewpcf_sanitize_text_transform_value( $styles['mobile_close_text_transform'] ) : '', 'mobile_close_padding_y' => isset( $styles['mobile_close_padding_y'] ) ? acewpcf_sanitize_size_value( $styles['mobile_close_padding_y'] ) : '', 'mobile_close_padding_x' => isset( $styles['mobile_close_padding_x'] ) ? acewpcf_sanitize_size_value( $styles['mobile_close_padding_x'] ) : '', 'mobile_close_border_radius' => isset( $styles['mobile_close_border_radius'] ) ? acewpcf_sanitize_size_value( $styles['mobile_close_border_radius'] ) : '', 'mobile_close_hover_text_color' => isset( $styles['mobile_close_hover_text_color'] ) ? sanitize_hex_color( $styles['mobile_close_hover_text_color'] ) : '', 'mobile_close_hover_background_color' => isset( $styles['mobile_close_hover_background_color'] ) ? sanitize_hex_color( $styles['mobile_close_hover_background_color'] ) : '', 'mobile_close_hover_border_color' => isset( $styles['mobile_close_hover_border_color'] ) ? sanitize_hex_color( $styles['mobile_close_hover_border_color'] ) : '', 'separator_color' => isset( $styles['separator_color'] ) ? sanitize_hex_color( $styles['separator_color'] ) : '', 'separator_width' => isset( $styles['separator_width'] ) ? acewpcf_sanitize_size_value( $styles['separator_width'] ) : '', 'separator_spacing' => isset( $styles['separator_spacing'] ) ? acewpcf_sanitize_size_value( $styles['separator_spacing'] ) : '', 'group_header_color' => isset( $styles['group_header_color'] ) ? sanitize_hex_color( $styles['group_header_color'] ) : '', 'group_header_font_family' => isset( $styles['group_header_font_family'] ) ? acewpcf_sanitize_font_family_choice( $styles['group_header_font_family'] ) : '', 'group_header_font_weight' => isset( $styles['group_header_font_weight'] ) ? acewpcf_sanitize_font_weight_value( $styles['group_header_font_weight'] ) : '', 'group_header_font_size' => isset( $styles['group_header_font_size'] ) ? acewpcf_sanitize_size_value( $styles['group_header_font_size'] ) : '', 'group_header_letter_spacing' => isset( $styles['group_header_letter_spacing'] ) ? acewpcf_sanitize_letter_spacing_value( $styles['group_header_letter_spacing'] ) : '', 'group_header_text_transform' => isset( $styles['group_header_text_transform'] ) ? acewpcf_sanitize_text_transform_value( $styles['group_header_text_transform'] ) : '', ); return wp_parse_args( $sanitized, $defaults ); } function acewpcf_sanitize_filter_set( $filter_id, $filter_data, $existing_ids = null ) { $defaults = acewpcf_get_default_filter_set(); $filter_data = is_array( $filter_data ) ? $filter_data : array(); $filter_id = sanitize_key( $filter_id ); $requested_id = isset( $filter_data['id'] ) ? sanitize_key( (string) $filter_data['id'] ) : ''; $name_source = isset( $filter_data['name'] ) ? sanitize_text_field( (string) $filter_data['name'] ) : 'filter'; $stored_ids = is_array( $existing_ids ) ? $existing_ids : array_keys( (array) get_option( ACEWPCF_OPTION_FILTER_SETS, array() ) ); $filter_id = acewpcf_resolve_editable_object_id( $filter_id, $requested_id, $name_source, $stored_ids, 'filter' ); $content_type = acewpcf_sanitize_content_type( isset( $filter_data['content_type'] ) ? $filter_data['content_type'] : 'post' ); $source_type = acewpcf_sanitize_filter_source_type( isset( $filter_data['source_type'] ) ? $filter_data['source_type'] : 'category' ); $is_virtual = acewpcf_is_virtual_filter_source_type( $source_type ); $source_taxonomy = acewpcf_sanitize_filter_source_taxonomy( $source_type, isset( $filter_data['source_taxonomy'] ) ? $filter_data['source_taxonomy'] : '', $content_type ); $uses_terms = acewpcf_is_taxonomy_filter_source_type( $source_type ); $term_ids_input = isset( $filter_data['ordered_term_ids'] ) && is_array( $filter_data['ordered_term_ids'] ) && ! empty( $filter_data['ordered_term_ids'] ) ? $filter_data['ordered_term_ids'] : ( isset( $filter_data['term_ids'] ) ? $filter_data['term_ids'] : array() ); $term_ids_input = $uses_terms ? acewpcf_sort_term_ids_by_order( $term_ids_input, isset( $filter_data['term_order'] ) ? $filter_data['term_order'] : array() ) : array(); $term_ids = $uses_terms ? acewpcf_validate_filter_term_ids( $source_taxonomy, $term_ids_input ) : array(); $option_keys_input = isset( $filter_data['ordered_option_keys'] ) && is_array( $filter_data['ordered_option_keys'] ) && ! empty( $filter_data['ordered_option_keys'] ) ? $filter_data['ordered_option_keys'] : ( isset( $filter_data['option_keys'] ) ? $filter_data['option_keys'] : array() ); $option_keys = ( 'author' === $source_type || 'date' === $source_type ) ? acewpcf_sanitize_virtual_option_keys( $source_type, $option_keys_input, isset( $filter_data['option_order'] ) ? $filter_data['option_order'] : array(), array( 'source_type' => $source_type, 'content_type' => $content_type, 'date_granularity' => isset( $filter_data['date_granularity'] ) ? $filter_data['date_granularity'] : 'month', ) ) : array(); $selection_mode = ( isset( $filter_data['selection_mode'] ) && 'multiple' === $filter_data['selection_mode'] ) ? 'multiple' : 'single'; if ( 'search' === $source_type ) { $selection_mode = 'single'; } $stored_filters = get_option( ACEWPCF_OPTION_FILTER_SETS, array() ); $stored_filters = is_array( $stored_filters ) ? $stored_filters : array(); $sanitized = array( 'id' => $filter_id, 'name' => isset( $filter_data['name'] ) ? sanitize_text_field( (string) $filter_data['name'] ) : '', 'panel_heading' => isset( $filter_data['panel_heading'] ) ? sanitize_text_field( (string) $filter_data['panel_heading'] ) : '', 'show_panel_heading' => isset( $filter_data['show_panel_heading'] ) ? ( ! empty( $filter_data['show_panel_heading'] ) ? 1 : 0 ) : ( ! empty( $filter_data['panel_heading'] ) ? 1 : 0 ), 'panel_collapsible' => isset( $filter_data['panel_collapsible'] ) && ! empty( $filter_data['panel_collapsible'] ) ? 1 : 0, 'panel_collapsed_by_default' => empty( $filter_data['panel_collapsible'] ) ? 0 : ( isset( $filter_data['panel_collapsed_by_default'] ) && ! empty( $filter_data['panel_collapsed_by_default'] ) ? 1 : 0 ), 'content_type' => $content_type, 'source_type' => $source_type, 'source_taxonomy' => $source_taxonomy, 'orientation' => isset( $filter_data['orientation'] ) ? acewpcf_sanitize_filter_orientation( $filter_data['orientation'] ) : 'horizontal', 'selection_mode' => $selection_mode, 'show_label' => ( $is_virtual && 'search' === $source_type && ! isset( $filter_data['show_label'] ) ) ? 1 : ( ! empty( $filter_data['show_label'] ) ? 1 : 0 ), 'show_count' => ( $is_virtual && 'search' === $source_type ) ? 0 : ( ! empty( $filter_data['show_count'] ) ? 1 : 0 ), 'count_display_mode' => acewpcf_sanitize_filter_count_display_mode( isset( $filter_data['count_display_mode'] ) ? $filter_data['count_display_mode'] : 'contextual' ), 'hide_zero_count_terms' => $uses_terms && ! empty( $filter_data['hide_zero_count_terms'] ) ? 1 : 0, 'term_search_mode' => $uses_terms ? acewpcf_sanitize_filter_term_search_mode( isset( $filter_data['term_search_mode'] ) ? $filter_data['term_search_mode'] : 'terms' ) : 'terms', 'term_search_placeholder' => $uses_terms ? acewpcf_sanitize_panel_control_label( isset( $filter_data['term_search_placeholder'] ) ? $filter_data['term_search_placeholder'] : '' ) : '', 'term_search_empty_message' => $uses_terms ? acewpcf_sanitize_empty_results_message( isset( $filter_data['term_search_empty_message'] ) ? $filter_data['term_search_empty_message'] : '' ) : '', 'search_placeholder' => 'search' === $source_type ? acewpcf_sanitize_panel_control_label( isset( $filter_data['search_placeholder'] ) ? $filter_data['search_placeholder'] : '' ) : '', 'date_granularity' => 'date' === $source_type ? acewpcf_sanitize_date_granularity( isset( $filter_data['date_granularity'] ) ? $filter_data['date_granularity'] : 'month' ) : 'month', 'display_mode' => $uses_terms ? acewpcf_sanitize_filter_display_mode( isset( $filter_data['display_mode'] ) ? $filter_data['display_mode'] : 'buttons' ) : 'buttons', 'swatch_shape' => $uses_terms ? acewpcf_sanitize_filter_swatch_shape( isset( $filter_data['swatch_shape'] ) ? $filter_data['swatch_shape'] : 'square' ) : 'square', 'swatch_layout' => $uses_terms ? acewpcf_sanitize_filter_swatch_layout( isset( $filter_data['swatch_layout'] ) ? $filter_data['swatch_layout'] : 'wrap' ) : 'wrap', 'term_colors' => $uses_terms ? acewpcf_sanitize_filter_term_colors( isset( $filter_data['term_colors'] ) ? $filter_data['term_colors'] : array(), isset( $stored_filters[ $filter_id ]['term_colors'] ) ? $stored_filters[ $filter_id ]['term_colors'] : array() ) : array(), 'ajax_enabled' => ! empty( $filter_data['ajax_enabled'] ) ? 1 : 0, 'results_selector' => isset( $filter_data['results_selector'] ) ? acewpcf_sanitize_results_selector( $filter_data['results_selector'] ) : '', 'empty_results_message' => isset( $filter_data['empty_results_message'] ) ? acewpcf_sanitize_empty_results_message( $filter_data['empty_results_message'] ) : '', 'responsive_layouts' => acewpcf_sanitize_filter_responsive_layouts( isset( $filter_data['responsive_layouts'] ) ? $filter_data['responsive_layouts'] : array() ), 'term_ids' => $term_ids, 'term_order' => $term_ids, 'option_keys' => $option_keys, 'option_order' => $option_keys, 'styles' => acewpcf_sanitize_filter_styles( isset( $filter_data['styles'] ) ? $filter_data['styles'] : array() ), 'match_logic' => ( $uses_terms && 'multiple' === $selection_mode && isset( $filter_data['match_logic'] ) && 'and' === sanitize_key( (string) $filter_data['match_logic'] ) ) ? 'and' : 'or', 'include_child_terms' => ( $uses_terms && 'multiple' === $selection_mode && is_taxonomy_hierarchical( $source_taxonomy ) && ! empty( $filter_data['include_child_terms'] ) ) ? 1 : 0, 'show_term_hierarchy' => ( $uses_terms && is_taxonomy_hierarchical( $source_taxonomy ) && ! empty( $filter_data['show_term_hierarchy'] ) ) ? 1 : 0, 'group_header' => acewpcf_sanitize_group_header( isset( $filter_data['group_header'] ) ? $filter_data['group_header'] : ( isset( $stored_filters[ $filter_id ]['group_header'] ) ? $stored_filters[ $filter_id ]['group_header'] : '' ) ), ); if ( '' === $sanitized['results_selector'] ) { $sanitized['ajax_enabled'] = 0; } if ( $uses_terms && ! $sanitized['show_label'] && ! $sanitized['show_count'] && 'swatches' !== $sanitized['display_mode'] ) { $sanitized['show_label'] = 1; } if ( '' === $sanitized['name'] ) { $sanitized['name'] = __( 'Content Filter', 'ace-content-filters' ); } return wp_parse_args( $sanitized, $defaults ); } function acewpcf_get_filter_sets() { $stored_filters = get_option( ACEWPCF_OPTION_FILTER_SETS, array() ); $filters = array(); if ( is_array( $stored_filters ) ) { foreach ( $stored_filters as $filter_id => $filter_data ) { $filter = acewpcf_sanitize_filter_set( $filter_id, $filter_data ); if ( '' !== $filter['id'] ) { $filters[ $filter['id'] ] = $filter; } } } return $filters; } function acewpcf_get_filter_set( $filter_id = '' ) { $filters = acewpcf_get_filter_sets(); if ( '' !== $filter_id ) { $filter_id = sanitize_key( $filter_id ); if ( isset( $filters[ $filter_id ] ) ) { return $filters[ $filter_id ]; } } return ! empty( $filters ) ? reset( $filters ) : array(); } function acewpcf_get_filter_set_choices() { $choices = array(); foreach ( acewpcf_get_filter_sets() as $filter ) { $choices[ $filter['id'] ] = $filter['name']; } return $choices; } function acewpcf_parse_filter_id_list( $raw_value ) { $available_filters = acewpcf_get_filter_sets(); $filter_ids = array(); if ( is_array( $raw_value ) ) { $filter_ids = $raw_value; } elseif ( is_string( $raw_value ) && '' !== trim( $raw_value ) ) { $filter_ids = preg_split( '/[\s,]+/', $raw_value ); } if ( empty( $filter_ids ) ) { return array(); } $filter_ids = array_map( 'sanitize_key', $filter_ids ); $filter_ids = array_filter( $filter_ids ); $filter_ids = array_values( array_unique( $filter_ids ) ); return array_values( array_filter( $filter_ids, static function ( $filter_id ) use ( $available_filters ) { return isset( $available_filters[ $filter_id ] ); } ) ); } function acewpcf_sanitize_group_header( $value ) { return substr( sanitize_text_field( (string) $value ), 0, 80 ); } function acewpcf_sanitize_panel_heading_id( $value, $existing_ids = array() ) { $value = sanitize_key( (string) $value ); $existing_ids = is_array( $existing_ids ) ? $existing_ids : array(); if ( '' === $value || 0 !== strpos( $value, 'cpcf-heading-' ) ) { $value = 'cpcf-heading-' . strtolower( wp_generate_password( 8, false, false ) ); } $base_value = $value; $suffix = 2; while ( in_array( $value, $existing_ids, true ) ) { $value = $base_value . '-' . $suffix; $suffix++; } return $value; } function acewpcf_sanitize_panel_items( $items, $filter_ids ) { $items = is_array( $items ) ? $items : array(); $filter_ids = array_values( array_filter( array_unique( array_map( 'sanitize_key', is_array( $filter_ids ) ? $filter_ids : array() ) ) ) ); $filter_map = array_fill_keys( $filter_ids, true ); $seen = array(); $heading_ids = array(); $sanitized = array(); foreach ( $items as $item ) { if ( ! is_array( $item ) ) { continue; } $type = isset( $item['type'] ) ? sanitize_key( (string) $item['type'] ) : ''; if ( 'heading' === $type ) { $heading_id = acewpcf_sanitize_panel_heading_id( isset( $item['id'] ) ? $item['id'] : '', $heading_ids ); $heading_ids[] = $heading_id; $sanitized[] = array( 'type' => 'heading', 'id' => $heading_id, 'text' => acewpcf_sanitize_group_header( isset( $item['text'] ) ? $item['text'] : '' ), ); continue; } if ( 'filter' !== $type ) { continue; } $filter_id = isset( $item['id'] ) ? sanitize_key( (string) $item['id'] ) : ''; if ( '' === $filter_id || ! isset( $filter_map[ $filter_id ] ) || isset( $seen[ $filter_id ] ) ) { continue; } $seen[ $filter_id ] = true; $sanitized[] = array( 'type' => 'filter', 'id' => $filter_id, ); } foreach ( $filter_ids as $filter_id ) { if ( isset( $seen[ $filter_id ] ) ) { continue; } $sanitized[] = array( 'type' => 'filter', 'id' => $filter_id, ); } return $sanitized; } function acewpcf_filter_group_headers_from_panel_items( $items ) { $headers = array(); $current = ''; foreach ( is_array( $items ) ? $items : array() as $item ) { if ( ! is_array( $item ) ) { continue; } $type = isset( $item['type'] ) ? sanitize_key( (string) $item['type'] ) : ''; if ( 'heading' === $type ) { $current = acewpcf_sanitize_group_header( isset( $item['text'] ) ? $item['text'] : '' ); continue; } if ( 'filter' !== $type ) { continue; } $filter_id = isset( $item['id'] ) ? sanitize_key( (string) $item['id'] ) : ''; if ( '' !== $filter_id ) { $headers[ $filter_id ] = $current; } } return $headers; } function acewpcf_build_panel_items_from_headers( $panel_data, $filter_ids ) { $filter_ids = array_values( array_filter( array_unique( array_map( 'sanitize_key', is_array( $filter_ids ) ? $filter_ids : array() ) ) ) ); $headers = isset( $panel_data['filter_group_headers'] ) && is_array( $panel_data['filter_group_headers'] ) ? $panel_data['filter_group_headers'] : array(); $filters = acewpcf_get_filter_sets(); $items = array(); $previous = ''; $heading_n = 1; foreach ( $filter_ids as $filter_id ) { $filter = isset( $filters[ $filter_id ] ) ? $filters[ $filter_id ] : array(); $heading = ''; if ( array_key_exists( $filter_id, $headers ) ) { $heading = acewpcf_sanitize_group_header( $headers[ $filter_id ] ); } elseif ( is_array( $filter ) && isset( $filter['group_header'] ) ) { $heading = acewpcf_sanitize_group_header( $filter['group_header'] ); } if ( '' !== $heading && 0 !== strcasecmp( $heading, $previous ) ) { $items[] = array( 'type' => 'heading', 'id' => 'cpcf-heading-' . $heading_n, 'text' => $heading, ); $heading_n++; $previous = $heading; } elseif ( '' === $heading ) { $previous = ''; } $items[] = array( 'type' => 'filter', 'id' => $filter_id, ); } return $items; } function acewpcf_get_panel_layout_items( $panel ) { $panel = is_array( $panel ) ? $panel : array(); $filter_ids = isset( $panel['filter_ids'] ) ? acewpcf_parse_filter_id_list( $panel['filter_ids'] ) : array(); if ( isset( $panel['panel_items'] ) && is_array( $panel['panel_items'] ) && ! empty( $panel['panel_items'] ) ) { return acewpcf_sanitize_panel_items( $panel['panel_items'], $filter_ids ); } return acewpcf_build_panel_items_from_headers( $panel, $filter_ids ); } function acewpcf_sanitize_filter_group_headers( $headers, $filter_ids ) { $headers = is_array( $headers ) ? $headers : array(); $filter_ids = array_values( array_filter( array_unique( array_map( 'sanitize_key', is_array( $filter_ids ) ? $filter_ids : array() ) ) ) ); $sanitized = array(); foreach ( $filter_ids as $filter_id ) { if ( ! array_key_exists( $filter_id, $headers ) ) { continue; } $sanitized[ $filter_id ] = acewpcf_sanitize_group_header( $headers[ $filter_id ] ); } return $sanitized; } function acewpcf_get_panel_filter_group_header( $panel, $filter ) { $filter = is_array( $filter ) ? $filter : array(); $filter_id = isset( $filter['id'] ) ? sanitize_key( (string) $filter['id'] ) : ''; $headers = isset( $panel['filter_group_headers'] ) && is_array( $panel['filter_group_headers'] ) ? $panel['filter_group_headers'] : array(); if ( '' !== $filter_id && array_key_exists( $filter_id, $headers ) ) { return acewpcf_sanitize_group_header( $headers[ $filter_id ] ); } return isset( $filter['group_header'] ) ? acewpcf_sanitize_group_header( $filter['group_header'] ) : ''; } function acewpcf_get_selected_term_ancestor_id( $term, $selected_ids ) { if ( ! ( $term instanceof WP_Term ) ) { return 0; } $selected_ids = is_array( $selected_ids ) ? $selected_ids : array(); $parent_id = (int) $term->parent; $guard = 0; while ( $parent_id > 0 && $guard < 20 ) { if ( isset( $selected_ids[ $parent_id ] ) ) { return $parent_id; } $parent_term = get_term( $parent_id, $term->taxonomy ); if ( ! ( $parent_term instanceof WP_Term ) || is_wp_error( $parent_term ) ) { return 0; } $parent_id = (int) $parent_term->parent; $guard++; } return 0; } function acewpcf_sort_filter_terms_hierarchically( $terms ) { $terms = is_array( $terms ) ? $terms : array(); $selected_ids = array(); $children = array(); $roots = array(); foreach ( $terms as $term ) { if ( ! ( $term instanceof WP_Term ) ) { continue; } $selected_ids[ (int) $term->term_id ] = true; } foreach ( $terms as $term ) { if ( ! ( $term instanceof WP_Term ) ) { continue; } $ancestor_id = acewpcf_get_selected_term_ancestor_id( $term, $selected_ids ); if ( $ancestor_id > 0 ) { if ( ! isset( $children[ $ancestor_id ] ) ) { $children[ $ancestor_id ] = array(); } $children[ $ancestor_id ][] = $term; continue; } $roots[] = $term; } $ordered = array(); $walk = function ( $term, $depth ) use ( &$walk, &$ordered, $children ) { $term->acewpcf_depth = max( 0, (int) $depth ); $ordered[] = $term; $term_id = (int) $term->term_id; if ( empty( $children[ $term_id ] ) ) { return; } foreach ( $children[ $term_id ] as $child ) { $walk( $child, $depth + 1 ); } }; foreach ( $roots as $root ) { $walk( $root, 0 ); } return $ordered; } function acewpcf_get_filter_descendant_slugs_map( $terms ) { $terms = is_array( $terms ) ? $terms : array(); $children_by_parent_id = array(); $term_by_id = array(); foreach ( $terms as $term ) { if ( ! ( $term instanceof WP_Term ) ) { continue; } $term_id = (int) $term->term_id; $term_by_id[ $term_id ] = $term; $parent_id = (int) $term->parent; if ( $parent_id > 0 ) { if ( ! isset( $children_by_parent_id[ $parent_id ] ) ) { $children_by_parent_id[ $parent_id ] = array(); } $children_by_parent_id[ $parent_id ][] = $term_id; } } $map = array(); foreach ( $term_by_id as $term_id => $term ) { $slugs = acewpcf_collect_filter_descendant_slugs( $term_id, $children_by_parent_id, $term_by_id, array() ); if ( ! empty( $slugs ) ) { $map[ $term->slug ] = $slugs; } } return $map; } function acewpcf_collect_filter_descendant_slugs( $term_id, $children_by_parent_id, $term_by_id, $seen ) { $term_id = (int) $term_id; if ( isset( $seen[ $term_id ] ) || empty( $children_by_parent_id[ $term_id ] ) ) { return array(); } $seen[ $term_id ] = true; $slugs = array(); foreach ( $children_by_parent_id[ $term_id ] as $child_id ) { $child_id = (int) $child_id; if ( ! isset( $term_by_id[ $child_id ] ) ) { continue; } $slugs[] = $term_by_id[ $child_id ]->slug; $slugs = array_merge( $slugs, acewpcf_collect_filter_descendant_slugs( $child_id, $children_by_parent_id, $term_by_id, $seen ) ); } return array_values( array_unique( $slugs ) ); } function acewpcf_sort_filter_ids_by_order( $filter_ids, $filter_order ) { $filter_ids = acewpcf_parse_filter_id_list( $filter_ids ); $filter_order = is_array( $filter_order ) ? $filter_order : array(); if ( empty( $filter_ids ) || empty( $filter_order ) ) { return $filter_ids; } $order_map = array(); foreach ( $filter_ids as $index => $filter_id ) { $raw_order = isset( $filter_order[ $filter_id ] ) ? trim( (string) $filter_order[ $filter_id ] ) : ''; $order_map[ $filter_id ] = array( 'order' => '' === $raw_order ? 1000 + $index : max( 1, absint( $raw_order ) ), 'index' => $index, ); } usort( $filter_ids, static function ( $left, $right ) use ( $order_map ) { $left_position = isset( $order_map[ $left ] ) ? $order_map[ $left ] : array( 'order' => 1000, 'index' => 0, ); $right_position = isset( $order_map[ $right ] ) ? $order_map[ $right ] : array( 'order' => 1000, 'index' => 0, ); if ( $left_position['order'] === $right_position['order'] ) { return $left_position['index'] <=> $right_position['index']; } return $left_position['order'] <=> $right_position['order']; } ); return $filter_ids; } function acewpcf_get_default_filter_panel() { return array( 'id' => '', 'name' => '', 'filter_ids' => array(), 'count_display_mode' => 'inherit', 'hide_zero_count_terms' => 'inherit', 'term_search_mode' => 'inherit', 'clear_all_mode' => 'auto', 'mobile_toggle_label' => '', 'clear_all_label' => '', 'filter_group_headers' => array(), 'panel_items' => array(), 'styles' => acewpcf_get_default_filter_panel_styles(), 'ajax_enabled' => 0, 'results_selector' => '', 'empty_results_message' => '', ); } function acewpcf_sanitize_filter_panel( $panel_id, $panel_data, $existing_ids = null ) { $defaults = acewpcf_get_default_filter_panel(); $panel_data = is_array( $panel_data ) ? $panel_data : array(); $panel_id = sanitize_key( $panel_id ); $requested_id = isset( $panel_data['id'] ) ? sanitize_key( (string) $panel_data['id'] ) : ''; $name_source = isset( $panel_data['name'] ) ? sanitize_text_field( (string) $panel_data['name'] ) : 'panel'; $stored_ids = is_array( $existing_ids ) ? $existing_ids : array_keys( (array) get_option( ACEWPCF_OPTION_FILTER_PANELS, array() ) ); $filter_ids_input = isset( $panel_data['ordered_filter_ids'] ) && is_array( $panel_data['ordered_filter_ids'] ) && ! empty( $panel_data['ordered_filter_ids'] ) ? $panel_data['ordered_filter_ids'] : ( isset( $panel_data['filter_ids'] ) ? $panel_data['filter_ids'] : array() ); $panel_id = acewpcf_resolve_editable_object_id( $panel_id, $requested_id, 'panel-' . $name_source, $stored_ids, 'panel' ); $filter_ids = acewpcf_sort_filter_ids_by_order( $filter_ids_input, isset( $panel_data['filter_order'] ) ? $panel_data['filter_order'] : array() ); if ( isset( $panel_data['panel_items'] ) && is_array( $panel_data['panel_items'] ) ) { $panel_items = acewpcf_sanitize_panel_items( $panel_data['panel_items'], $filter_ids ); } else { $panel_items = acewpcf_build_panel_items_from_headers( $panel_data, $filter_ids ); } $layout_filter_ids = array(); foreach ( $panel_items as $panel_item ) { if ( isset( $panel_item['type'], $panel_item['id'] ) && 'filter' === $panel_item['type'] ) { $layout_filter_ids[] = $panel_item['id']; } } if ( ! empty( $layout_filter_ids ) ) { $filter_ids = $layout_filter_ids; } $sanitized = array( 'id' => $panel_id, 'name' => isset( $panel_data['name'] ) ? sanitize_text_field( (string) $panel_data['name'] ) : '', 'filter_ids' => $filter_ids, 'count_display_mode' => acewpcf_sanitize_panel_count_display_mode( isset( $panel_data['count_display_mode'] ) ? $panel_data['count_display_mode'] : 'inherit' ), 'hide_zero_count_terms' => acewpcf_sanitize_panel_hide_zero_count_terms( isset( $panel_data['hide_zero_count_terms'] ) ? $panel_data['hide_zero_count_terms'] : 'inherit' ), 'term_search_mode' => acewpcf_sanitize_panel_term_search_mode( isset( $panel_data['term_search_mode'] ) ? $panel_data['term_search_mode'] : 'inherit' ), 'clear_all_mode' => acewpcf_sanitize_filter_panel_clear_all_mode( isset( $panel_data['clear_all_mode'] ) ? $panel_data['clear_all_mode'] : 'auto' ), 'mobile_toggle_label' => isset( $panel_data['mobile_toggle_label'] ) ? acewpcf_sanitize_panel_control_label( $panel_data['mobile_toggle_label'] ) : '', 'clear_all_label' => isset( $panel_data['clear_all_label'] ) ? acewpcf_sanitize_panel_control_label( $panel_data['clear_all_label'] ) : '', 'panel_items' => $panel_items, 'filter_group_headers' => acewpcf_filter_group_headers_from_panel_items( $panel_items ), 'styles' => acewpcf_sanitize_filter_panel_styles( isset( $panel_data['styles'] ) ? $panel_data['styles'] : array() ), 'ajax_enabled' => ! empty( $panel_data['ajax_enabled'] ) ? 1 : 0, 'results_selector' => isset( $panel_data['results_selector'] ) ? acewpcf_sanitize_results_selector( $panel_data['results_selector'] ) : '', 'empty_results_message' => isset( $panel_data['empty_results_message'] ) ? acewpcf_sanitize_empty_results_message( $panel_data['empty_results_message'] ) : '', ); if ( '' === $sanitized['results_selector'] ) { $sanitized['ajax_enabled'] = 0; } if ( '' === $sanitized['name'] ) { $sanitized['name'] = __( 'Filter Panel', 'ace-content-filters' ); } return wp_parse_args( $sanitized, $defaults ); } function acewpcf_get_filter_panels() { $stored_panels = get_option( ACEWPCF_OPTION_FILTER_PANELS, array() ); $panels = array(); if ( ! is_array( $stored_panels ) ) { return $panels; } foreach ( $stored_panels as $panel_id => $panel_data ) { $panel = acewpcf_sanitize_filter_panel( $panel_id, $panel_data ); if ( '' !== $panel['id'] && ! empty( $panel['filter_ids'] ) ) { $panels[ $panel['id'] ] = $panel; } } return $panels; } function acewpcf_get_filter_panel( $panel_id = '' ) { $panels = acewpcf_get_filter_panels(); if ( '' !== $panel_id ) { $panel_id = sanitize_key( $panel_id ); if ( isset( $panels[ $panel_id ] ) ) { return $panels[ $panel_id ]; } } return ! empty( $panels ) ? reset( $panels ) : array(); } function acewpcf_get_filter_panel_choices() { $choices = array(); foreach ( acewpcf_get_filter_panels() as $panel ) { $choices[ $panel['id'] ] = $panel['name']; } return $choices; } function acewpcf_get_filter_panel_clear_all_choices() { return array( 'off' => __( 'Off', 'ace-content-filters' ), 'auto' => __( 'Auto', 'ace-content-filters' ), 'always' => __( 'Always', 'ace-content-filters' ), ); } function acewpcf_sanitize_filter_panel_clear_all_mode( $value ) { $value = sanitize_key( (string) $value ); $choices = acewpcf_get_filter_panel_clear_all_choices(); return isset( $choices[ $value ] ) ? $value : 'auto'; } function acewpcf_get_filter_query_var( $filter_id ) { $filter_id = sanitize_key( $filter_id ); if ( '' === $filter_id ) { $filter_id = 'default'; } return 'cpcf_filter_' . substr( $filter_id, 0, 32 ); } function acewpcf_get_current_request_url() { $request_uri = acewpcf_get_request_server_value( 'REQUEST_URI', '' ); if ( '' === $request_uri ) { return ''; } $request_path = strtok( $request_uri, '?' ); if ( false === $request_path || '' === $request_path ) { return ''; } return home_url( $request_path ); } function acewpcf_get_filter_content_type( $filter ) { $filter = is_array( $filter ) ? $filter : array(); return acewpcf_sanitize_content_type( isset( $filter['content_type'] ) ? $filter['content_type'] : 'post' ); } function acewpcf_get_filter_base_url( $selected_slugs = array(), $taxonomy = '', $content_type = 'post' ) { $selected_slugs = is_array( $selected_slugs ) ? array_values( array_filter( array_map( 'sanitize_title', $selected_slugs ) ) ) : array(); $taxonomy = sanitize_key( (string) $taxonomy ); $content_type = acewpcf_sanitize_content_type( $content_type ); if ( 1 === count( $selected_slugs ) && '' !== $taxonomy && taxonomy_exists( $taxonomy ) ) { $selected_term = get_term_by( 'slug', $selected_slugs[0], $taxonomy ); if ( $selected_term instanceof WP_Term ) { $selected_term_url = get_term_link( $selected_term ); if ( ! is_wp_error( $selected_term_url ) && ! empty( $selected_term_url ) ) { return $selected_term_url; } } } $current_url = acewpcf_get_current_request_url(); if ( '' !== $current_url ) { if ( is_home() || is_front_page() || is_post_type_archive( $content_type ) || is_tax() || is_category() || is_tag() || is_author() || is_date() || is_search() ) { return $current_url; } } $url = ''; if ( 'post' === $content_type ) { $page_for_posts = (int) get_option( 'page_for_posts' ); if ( $page_for_posts > 0 ) { $url = get_permalink( $page_for_posts ); } if ( empty( $url ) ) { $url = get_post_type_archive_link( 'post' ); } } else { $url = get_post_type_archive_link( $content_type ); } if ( empty( $url ) && '' !== $current_url ) { $url = $current_url; } if ( empty( $url ) ) { $url = home_url( '/' ); } return $url; } function acewpcf_get_filter_render_base_url() { if ( is_singular() ) { $page_url = get_permalink(); if ( is_string( $page_url ) && '' !== $page_url ) { return $page_url; } } $current_url = acewpcf_get_current_request_url(); if ( '' !== $current_url ) { return $current_url; } return acewpcf_get_filter_base_url(); } function acewpcf_get_filter_terms( $filter_id = '' ) { static $term_cache = array(); $filter = acewpcf_get_filter_set( $filter_id ); if ( empty( $filter ) ) { return array(); } if ( acewpcf_is_search_filter( $filter ) ) { return array(); } if ( ( acewpcf_is_author_filter( $filter ) || acewpcf_is_date_filter( $filter ) ) && function_exists( 'acewpcf_get_virtual_filter_terms' ) ) { return acewpcf_get_virtual_filter_terms( $filter ); } if ( ! acewpcf_filter_uses_terms( $filter ) ) { return array(); } $taxonomy = acewpcf_get_filter_taxonomy( $filter ); $term_ids = isset( $filter['term_ids'] ) && is_array( $filter['term_ids'] ) ? $filter['term_ids'] : array(); $term_order = isset( $filter['term_order'] ) && is_array( $filter['term_order'] ) ? $filter['term_order'] : array(); // Ensure term_ids is properly sorted $term_ids = array_values( array_filter( array_map( 'absint', (array) $term_ids ) ) ); if ( empty( $term_ids ) || ! taxonomy_exists( $taxonomy ) ) { return array(); } $term_ids = acewpcf_sort_term_ids_by_order( $term_ids, ! empty( $term_order ) ? $term_order : $term_ids ); $cache_key = sanitize_key( isset( $filter['id'] ) ? $filter['id'] : '' ) . ':' . $taxonomy . ':' . md5( wp_json_encode( array_values( array_map( 'absint', $term_ids ) ) ) ); if ( isset( $term_cache[ $cache_key ] ) ) { return $term_cache[ $cache_key ]; } $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'include' => $term_ids, 'orderby' => 'include', ) ); if ( is_wp_error( $terms ) ) { $term_cache[ $cache_key ] = array(); return $term_cache[ $cache_key ]; } $term_map = array(); $ordered_terms = array(); foreach ( $terms as $term ) { if ( $term instanceof WP_Term ) { $term_map[ (int) $term->term_id ] = $term; } } foreach ( $term_ids as $term_id ) { $term_id = absint( $term_id ); if ( isset( $term_map[ $term_id ] ) ) { $ordered_terms[] = $term_map[ $term_id ]; } } $term_cache[ $cache_key ] = $ordered_terms; return $term_cache[ $cache_key ]; } function acewpcf_get_filter_allowed_slugs( $filter_id = '' ) { $filter = acewpcf_get_filter_set( $filter_id ); if ( empty( $filter ) ) { return array(); } $terms = acewpcf_get_filter_terms( $filter_id ); if ( empty( $terms ) ) { return array(); } $slugs = wp_list_pluck( $terms, 'slug' ); $slugs = array_map( 'sanitize_title', $slugs ); $slugs = array_filter( $slugs ); return array_values( array_unique( $slugs ) ); } function acewpcf_parse_filter_request_slugs( $filter_id = '', $raw_value = null ) { $filter = acewpcf_get_filter_set( $filter_id ); if ( empty( $filter ) || acewpcf_is_search_filter( $filter ) ) { return array(); } if ( null === $raw_value ) { $query_var = acewpcf_get_filter_query_var( $filter['id'] ); $raw_value = acewpcf_get_request_query_value( $query_var, null ); if ( null === $raw_value ) { $raw_value = ''; } else { $raw_value = (string) $raw_value; } } $raw_value = sanitize_text_field( (string) $raw_value ); if ( '' === $raw_value ) { return array(); } $slugs = explode( ',', $raw_value ); $slugs = array_map( 'sanitize_title', $slugs ); $slugs = array_filter( $slugs ); $slugs = array_values( array_unique( $slugs ) ); if ( empty( $slugs ) ) { return array(); } $allowed_slugs = acewpcf_get_filter_allowed_slugs( $filter['id'] ); if ( empty( $allowed_slugs ) ) { return array(); } $slugs = array_values( array_intersect( $slugs, $allowed_slugs ) ); if ( 'single' === $filter['selection_mode'] && ! empty( $slugs ) ) { return array( $slugs[0] ); } return $slugs; } function acewpcf_get_all_active_filter_slugs_by_taxonomy() { $filter_slugs_by_taxonomy = array(); foreach ( acewpcf_get_filter_sets() as $filter ) { $taxonomy = acewpcf_get_filter_taxonomy( $filter ); $slugs = acewpcf_parse_filter_request_slugs( $filter['id'] ); if ( '' === $taxonomy || empty( $slugs ) ) { continue; } if ( ! isset( $filter_slugs_by_taxonomy[ $taxonomy ] ) ) { $filter_slugs_by_taxonomy[ $taxonomy ] = array(); } $filter_slugs_by_taxonomy[ $taxonomy ] = array_merge( $filter_slugs_by_taxonomy[ $taxonomy ], $slugs ); } foreach ( $filter_slugs_by_taxonomy as $taxonomy => $slugs ) { $slugs = array_map( 'sanitize_title', $slugs ); $slugs = array_filter( $slugs ); $filter_slugs_by_taxonomy[ $taxonomy ] = array_values( array_unique( $slugs ) ); } return $filter_slugs_by_taxonomy; } function acewpcf_normalize_active_filter_tax_clauses( $clauses ) { $clauses = is_array( $clauses ) ? $clauses : array(); $normalized = array(); foreach ( $clauses as $clause_key => $clause_value ) { $filter_id = ''; $taxonomy = ''; $slugs = array(); if ( is_string( $clause_key ) && is_array( $clause_value ) && ! isset( $clause_value['taxonomy'] ) ) { $taxonomy = $clause_key; $slugs = $clause_value; } elseif ( is_array( $clause_value ) ) { $filter_id = isset( $clause_value['filter_id'] ) ? sanitize_key( (string) $clause_value['filter_id'] ) : ''; $taxonomy = isset( $clause_value['taxonomy'] ) ? sanitize_key( (string) $clause_value['taxonomy'] ) : ''; $slugs = isset( $clause_value['slugs'] ) ? $clause_value['slugs'] : array(); } $taxonomy = sanitize_key( (string) $taxonomy ); $slugs = array_map( 'sanitize_title', is_array( $slugs ) ? $slugs : array() ); $slugs = array_values( array_filter( array_unique( $slugs ) ) ); if ( '' === $taxonomy || empty( $slugs ) ) { continue; } $operator = is_array( $clause_value ) && isset( $clause_value['operator'] ) && 'and' === $clause_value['operator'] ? 'and' : 'or'; $normalized[] = array( 'filter_id' => $filter_id, 'taxonomy' => $taxonomy, 'slugs' => $slugs, 'operator' => $operator, ); } return $normalized; } function acewpcf_get_all_active_filter_tax_clauses( $exclude_filter_id = '' ) { $exclude_filter_id = sanitize_key( (string) $exclude_filter_id ); $clauses = array(); foreach ( acewpcf_get_filter_sets() as $filter ) { $filter_id = isset( $filter['id'] ) ? sanitize_key( (string) $filter['id'] ) : ''; if ( '' === $filter_id || $filter_id === $exclude_filter_id ) { continue; } $taxonomy = acewpcf_get_filter_taxonomy( $filter ); $slugs = acewpcf_parse_filter_request_slugs( $filter_id ); if ( '' === $taxonomy || empty( $slugs ) ) { continue; } $match_logic = ( 'multiple' === ( isset( $filter['selection_mode'] ) ? $filter['selection_mode'] : 'single' ) && isset( $filter['match_logic'] ) && 'and' === $filter['match_logic'] ) ? 'and' : 'or'; $clauses[] = array( 'filter_id' => $filter_id, 'taxonomy' => $taxonomy, 'slugs' => $slugs, 'operator' => $match_logic, ); } return acewpcf_normalize_active_filter_tax_clauses( $clauses ); } function acewpcf_get_all_active_filter_slugs( $taxonomy = '' ) { $taxonomy = sanitize_key( (string) $taxonomy ); $filter_slugs_by_taxonomy = acewpcf_get_all_active_filter_slugs_by_taxonomy(); if ( '' !== $taxonomy ) { return isset( $filter_slugs_by_taxonomy[ $taxonomy ] ) ? $filter_slugs_by_taxonomy[ $taxonomy ] : array(); } $filter_slugs = array(); foreach ( $filter_slugs_by_taxonomy as $slugs ) { $filter_slugs = array_merge( $filter_slugs, $slugs ); } $filter_slugs = array_map( 'sanitize_title', $filter_slugs ); $filter_slugs = array_filter( $filter_slugs ); return array_values( array_unique( $filter_slugs ) ); } require_once ACEWPCF_PLUGIN_PATH . 'includes/virtual-filters.php'; require_once ACEWPCF_PLUGIN_PATH . 'includes/content-search.php'; require_once ACEWPCF_PLUGIN_PATH . 'includes/admin-settings.php'; require_once ACEWPCF_PLUGIN_PATH . 'includes/frontend.php'; require_once ACEWPCF_PLUGIN_PATH . 'includes/query-handler.php'; require_once ACEWPCF_PLUGIN_PATH . 'includes/elementor-widget.php';