acewpf_google_fonts_are_enabled(),
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'previewNonce' => wp_create_nonce( 'acewpf_preview_filter' ),
'defaultRatingStarUrl' => function_exists( 'acewpf_get_default_rating_star_url' ) ? acewpf_get_default_rating_star_url() : '',
'i18n' => array(
'previewUpdating' => __( 'Updating preview...', 'ace-products-filters' ),
'previewUpdated' => __( 'Preview updated.', 'ace-products-filters' ),
'previewFailed' => __( 'Preview could not be refreshed. Try again, or save the filter if the problem persists.', 'ace-products-filters' ),
'chooseStarIcon' => __( 'Choose star icon', 'ace-products-filters' ),
'useThisIcon' => __( 'Use this icon', 'ace-products-filters' ),
),
)
) . ';',
'before'
);
}
add_action( 'admin_enqueue_scripts', 'acewpf_enqueue_admin_assets' );
function acewpf_get_admin_page_url( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'page' => 'acewpf-settings',
)
);
return add_query_arg( $args, admin_url( 'admin.php' ) );
}
function acewpf_get_admin_logo_url() {
return ACEWPF_PLUGIN_URL . 'assets/images/awp-logo.svg';
}
function acewpf_get_admin_product_categories() {
if ( ! taxonomy_exists( 'product_cat' ) ) {
return array();
}
$categories = get_terms(
array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC',
)
);
if ( is_wp_error( $categories ) ) {
return array();
}
return $categories;
}
function acewpf_get_admin_category_map( $categories ) {
$category_map = array();
foreach ( $categories as $category ) {
$category_map[ (int) $category->term_id ] = $category;
}
return $category_map;
}
function acewpf_get_admin_category_path( $term, $category_map ) {
$ancestor_ids = array_reverse( get_ancestors( $term->term_id, 'product_cat', 'taxonomy' ) );
$ancestor_names = array();
foreach ( $ancestor_ids as $ancestor_id ) {
if ( isset( $category_map[ $ancestor_id ] ) ) {
$ancestor_names[] = $category_map[ $ancestor_id ]->name;
}
}
return implode( ' / ', $ancestor_names );
}
function acewpf_get_admin_category_options( $categories ) {
if ( empty( $categories ) ) {
return array();
}
$category_map = acewpf_get_admin_category_map( $categories );
$children = array();
$seen_ids = array();
$options = array();
foreach ( $categories as $category ) {
$parent_id = isset( $category_map[ (int) $category->parent ] ) ? (int) $category->parent : 0;
if ( ! isset( $children[ $parent_id ] ) ) {
$children[ $parent_id ] = array();
}
$children[ $parent_id ][] = $category;
}
foreach ( $children as $parent_id => $child_terms ) {
usort(
$child_terms,
static function ( $left, $right ) {
return strcasecmp( $left->name, $right->name );
}
);
$children[ $parent_id ] = $child_terms;
}
$walk_terms = static function ( $parent_id, $depth ) use ( &$walk_terms, &$options, &$children, &$seen_ids, $category_map ) {
if ( empty( $children[ $parent_id ] ) ) {
return;
}
foreach ( $children[ $parent_id ] as $term ) {
$seen_ids[ (int) $term->term_id ] = true;
$path = acewpf_get_admin_category_path( $term, $category_map );
$options[] = array(
'term' => $term,
'depth' => $depth,
'path' => $path,
'search_text' => strtolower( trim( $term->name . ' ' . $term->slug . ' ' . $path ) ),
);
$walk_terms( (int) $term->term_id, $depth + 1 );
}
};
$walk_terms( 0, 0 );
foreach ( $categories as $category ) {
if ( isset( $seen_ids[ (int) $category->term_id ] ) ) {
continue;
}
$path = acewpf_get_admin_category_path( $category, $category_map );
$options[] = array(
'term' => $category,
'depth' => 0,
'path' => $path,
'search_text' => strtolower( trim( $category->name . ' ' . $category->slug . ' ' . $path ) ),
);
}
return $options;
}
function acewpf_get_admin_taxonomy_label( $taxonomy ) {
$taxonomy = sanitize_key( (string) $taxonomy );
if ( 'product_cat' === $taxonomy ) {
return __( 'Product categories', 'ace-products-filters' );
}
$attribute_taxonomies = acewpf_get_product_attribute_taxonomy_choices();
if ( isset( $attribute_taxonomies[ $taxonomy ] ) ) {
return $attribute_taxonomies[ $taxonomy ];
}
$taxonomy_object = get_taxonomy( $taxonomy );
if ( $taxonomy_object instanceof WP_Taxonomy && ! empty( $taxonomy_object->labels->singular_name ) ) {
return (string) $taxonomy_object->labels->singular_name;
}
return ucwords( str_replace( array( 'pa_', '-', '_' ), array( '', ' ', ' ' ), $taxonomy ) );
}
function acewpf_get_admin_terms_for_taxonomy( $taxonomy ) {
static $terms_cache = array();
$taxonomy = sanitize_key( (string) $taxonomy );
if ( '' === $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
return array();
}
if ( isset( $terms_cache[ $taxonomy ] ) ) {
return $terms_cache[ $taxonomy ];
}
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC',
)
);
if ( is_wp_error( $terms ) ) {
$terms_cache[ $taxonomy ] = array();
return array();
}
$terms_cache[ $taxonomy ] = $terms;
return $terms;
}
function acewpf_get_admin_term_map( $terms ) {
$term_map = array();
foreach ( $terms as $term ) {
$term_map[ (int) $term->term_id ] = $term;
}
return $term_map;
}
function acewpf_get_admin_term_path( $term, $term_map, $taxonomy ) {
$taxonomy = sanitize_key( (string) $taxonomy );
if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
return '';
}
$ancestor_ids = array_reverse( get_ancestors( $term->term_id, $taxonomy, 'taxonomy' ) );
$ancestor_names = array();
foreach ( $ancestor_ids as $ancestor_id ) {
if ( isset( $term_map[ $ancestor_id ] ) ) {
$ancestor_names[] = $term_map[ $ancestor_id ]->name;
}
}
return implode( ' / ', $ancestor_names );
}
function acewpf_get_admin_term_options( $taxonomy, $terms ) {
$taxonomy = sanitize_key( (string) $taxonomy );
$terms = is_array( $terms ) ? $terms : array();
if ( empty( $terms ) || ! taxonomy_exists( $taxonomy ) ) {
return array();
}
$term_map = acewpf_get_admin_term_map( $terms );
$taxonomy_label = acewpf_get_admin_taxonomy_label( $taxonomy );
$options = array();
if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
usort(
$terms,
static function ( $left, $right ) {
return strcasecmp( $left->name, $right->name );
}
);
foreach ( $terms as $term ) {
$options[] = array(
'taxonomy' => $taxonomy,
'taxonomy_label' => $taxonomy_label,
'term' => $term,
'depth' => 0,
'path' => '',
'search_text' => strtolower( trim( $term->name . ' ' . $term->slug . ' ' . $taxonomy_label ) ),
);
}
return $options;
}
$children = array();
$seen_ids = array();
foreach ( $terms as $term ) {
$parent_id = isset( $term_map[ (int) $term->parent ] ) ? (int) $term->parent : 0;
if ( ! isset( $children[ $parent_id ] ) ) {
$children[ $parent_id ] = array();
}
$children[ $parent_id ][] = $term;
}
foreach ( $children as $parent_id => $child_terms ) {
usort(
$child_terms,
static function ( $left, $right ) {
return strcasecmp( $left->name, $right->name );
}
);
$children[ $parent_id ] = $child_terms;
}
$walk_terms = static function ( $parent_id, $depth ) use ( &$walk_terms, &$options, &$children, &$seen_ids, $taxonomy, $taxonomy_label, $term_map ) {
if ( empty( $children[ $parent_id ] ) ) {
return;
}
foreach ( $children[ $parent_id ] as $term ) {
$seen_ids[ (int) $term->term_id ] = true;
$path = acewpf_get_admin_term_path( $term, $term_map, $taxonomy );
$options[] = array(
'taxonomy' => $taxonomy,
'taxonomy_label' => $taxonomy_label,
'term' => $term,
'depth' => $depth,
'path' => $path,
'search_text' => strtolower( trim( $term->name . ' ' . $term->slug . ' ' . $path . ' ' . $taxonomy_label ) ),
);
$walk_terms( (int) $term->term_id, $depth + 1 );
}
};
$walk_terms( 0, 0 );
foreach ( $terms as $term ) {
if ( isset( $seen_ids[ (int) $term->term_id ] ) ) {
continue;
}
$path = acewpf_get_admin_term_path( $term, $term_map, $taxonomy );
$options[] = array(
'taxonomy' => $taxonomy,
'taxonomy_label' => $taxonomy_label,
'term' => $term,
'depth' => 0,
'path' => $path,
'search_text' => strtolower( trim( $term->name . ' ' . $term->slug . ' ' . $path . ' ' . $taxonomy_label ) ),
);
}
return $options;
}
function acewpf_get_admin_filter_taxonomies( $filter = array() ) {
$filter = is_array( $filter ) ? $filter : array();
$taxonomies = array(
'product_cat' => acewpf_get_admin_taxonomy_label( 'product_cat' ),
);
$product_taxonomies = acewpf_get_product_taxonomy_choices();
if ( 'attribute' === ( isset( $filter['source_type'] ) ? $filter['source_type'] : '' ) || ! empty( acewpf_get_product_attribute_taxonomy_choices() ) ) {
$taxonomies = array_merge( $taxonomies, acewpf_get_product_attribute_taxonomy_choices() );
}
if ( 'custom_taxonomy' === ( isset( $filter['source_type'] ) ? $filter['source_type'] : '' ) || ! empty( $product_taxonomies ) ) {
$taxonomies = array_merge( $taxonomies, $product_taxonomies );
}
return $taxonomies;
}
function acewpf_get_admin_term_option_groups( $taxonomies ) {
$taxonomies = is_array( $taxonomies ) ? $taxonomies : array();
$groups = array();
foreach ( $taxonomies as $taxonomy => $label ) {
$groups[ $taxonomy ] = acewpf_get_admin_term_options( $taxonomy, acewpf_get_admin_terms_for_taxonomy( $taxonomy ) );
}
return $groups;
}
function acewpf_get_filter_mode_label( $selection_mode, $filter = array() ) {
if ( acewpf_is_price_filter( $filter ) ) {
return __( 'Range slider', 'ace-products-filters' );
}
return 'multiple' === $selection_mode
? __( 'Multiple / Checkboxes', 'ace-products-filters' )
: __( 'Single / Buttons', 'ace-products-filters' );
}
function acewpf_get_filter_source_label( $filter ) {
$filter = is_array( $filter ) ? $filter : array();
if ( acewpf_is_price_filter( $filter ) ) {
return __( 'Price range', 'ace-products-filters' );
}
$source_type = isset( $filter['source_type'] ) ? acewpf_sanitize_filter_source_type( $filter['source_type'] ) : 'category';
if ( acewpf_is_product_property_filter_source_type( $source_type ) ) {
$choices = acewpf_get_filter_source_choices();
return isset( $choices[ $source_type ] ) ? $choices[ $source_type ] : $source_type;
}
return acewpf_get_admin_taxonomy_label( acewpf_get_filter_taxonomy( $filter ) );
}
function acewpf_get_filter_display_summary_label( $filter ) {
$filter = is_array( $filter ) ? $filter : array();
if ( acewpf_is_price_filter( $filter ) ) {
return ! isset( $filter['price_show_inputs'] ) || ! empty( $filter['price_show_inputs'] )
? __( 'Slider + inputs', 'ace-products-filters' )
: __( 'Slider only', 'ace-products-filters' );
}
$show_label = ! empty( $filter['show_label'] );
$show_count = ! empty( $filter['show_count'] );
if ( function_exists( 'acewpf_filter_uses_swatches' ) && acewpf_filter_uses_swatches( $filter ) ) {
if ( $show_label && $show_count ) {
return __( 'Swatches + label + count', 'ace-products-filters' );
}
if ( $show_label ) {
return __( 'Swatches + label', 'ace-products-filters' );
}
if ( $show_count ) {
return __( 'Swatches + count', 'ace-products-filters' );
}
return __( 'Colour swatches', 'ace-products-filters' );
}
if ( function_exists( 'acewpf_filter_uses_rating_stars' ) && acewpf_filter_uses_rating_stars( $filter ) ) {
if ( $show_count ) {
return __( 'Stars + count', 'ace-products-filters' );
}
return __( 'Star icons', 'ace-products-filters' );
}
if ( $show_label && $show_count ) {
return __( 'Title + count', 'ace-products-filters' );
}
if ( $show_count ) {
return __( 'Count only', 'ace-products-filters' );
}
return __( 'Title only', 'ace-products-filters' );
}
function acewpf_get_filter_orientation_label( $orientation ) {
$orientation = acewpf_sanitize_filter_orientation( $orientation );
return 'vertical' === $orientation
? __( 'Vertical / Left bar', 'ace-products-filters' )
: __( 'Horizontal / Top bar', 'ace-products-filters' );
}
function acewpf_get_filter_item_summary_label( $filter, $term_ids = array() ) {
$term_ids = is_array( $term_ids ) ? $term_ids : array();
if ( acewpf_is_price_filter( $filter ) ) {
return __( 'Auto price bounds', 'ace-products-filters' );
}
if ( acewpf_is_product_property_filter( $filter ) ) {
$option_count = count( $term_ids );
return sprintf(
/* translators: %d: number of options included in the filter. */
_n( '%d option', '%d options', $option_count, 'ace-products-filters' ),
$option_count
);
}
return sprintf(
/* translators: %d: number of terms included in the filter. */
_n( '%d term', '%d terms', count( $term_ids ), 'ace-products-filters' ),
count( $term_ids )
);
}
function acewpf_get_filter_term_preview_labels( $filter ) {
$labels = array();
$filter = is_array( $filter ) ? $filter : array();
$terms = acewpf_get_filter_terms( isset( $filter['id'] ) ? $filter['id'] : '' );
$taxonomy = acewpf_get_filter_taxonomy( $filter );
if ( empty( $terms ) ) {
return $labels;
}
$term_map = acewpf_get_admin_term_map( $terms );
$taxonomy_label = acewpf_get_admin_taxonomy_label( $taxonomy );
foreach ( $terms as $term ) {
$path = acewpf_get_admin_term_path( $term, $term_map, $taxonomy );
$label = $term->name;
if ( '' !== $path ) {
$label = $path . ' / ' . $label;
} elseif ( 'product_cat' !== $taxonomy ) {
$label = $taxonomy_label . ' / ' . $label;
}
$labels[] = $label;
if ( count( $labels ) >= 3 ) {
break;
}
}
return $labels;
}
function acewpf_get_filter_term_preview_label_map( $filter_sets ) {
$filter_sets = is_array( $filter_sets ) ? $filter_sets : array();
$preview_map = array();
$terms_by_filter = array();
$term_ids_by_tax = array();
$term_maps = array();
$taxonomy_labels = array();
foreach ( $filter_sets as $filter ) {
$filter_id = sanitize_key( isset( $filter['id'] ) ? $filter['id'] : '' );
$preview_map[ $filter_id ] = array();
if ( '' === $filter_id || acewpf_is_price_filter( $filter ) ) {
continue;
}
$taxonomy = acewpf_get_filter_taxonomy( $filter );
if ( ! taxonomy_exists( $taxonomy ) ) {
continue;
}
$term_ids = isset( $filter['term_ids'] ) && is_array( $filter['term_ids'] ) ? $filter['term_ids'] : array();
if ( empty( $term_ids ) && isset( $filter['category_ids'] ) && is_array( $filter['category_ids'] ) ) {
$term_ids = $filter['category_ids'];
}
if ( empty( $term_ids ) ) {
continue;
}
$term_order = isset( $filter['term_order'] ) && is_array( $filter['term_order'] ) ? $filter['term_order'] : $term_ids;
$term_ids = acewpf_sort_term_ids_by_order( $term_ids, $term_order );
$term_ids = array_values( array_filter( array_map( 'absint', $term_ids ) ) );
if ( empty( $term_ids ) ) {
continue;
}
$terms_by_filter[ $filter_id ] = array(
'taxonomy' => $taxonomy,
'term_ids' => $term_ids,
);
if ( ! isset( $term_ids_by_tax[ $taxonomy ] ) ) {
$term_ids_by_tax[ $taxonomy ] = array();
}
$term_ids_by_tax[ $taxonomy ] = array_merge( $term_ids_by_tax[ $taxonomy ], $term_ids );
}
foreach ( $term_ids_by_tax as $taxonomy => $term_ids ) {
$term_ids = array_values( array_unique( array_filter( array_map( 'absint', $term_ids ) ) ) );
if ( empty( $term_ids ) ) {
$term_maps[ $taxonomy ] = array();
$taxonomy_labels[ $taxonomy ] = acewpf_get_admin_taxonomy_label( $taxonomy );
continue;
}
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'include' => $term_ids,
'orderby' => 'include',
)
);
$term_maps[ $taxonomy ] = array();
$taxonomy_labels[ $taxonomy ] = acewpf_get_admin_taxonomy_label( $taxonomy );
if ( is_wp_error( $terms ) ) {
continue;
}
foreach ( $terms as $term ) {
if ( $term instanceof WP_Term ) {
$term_maps[ $taxonomy ][ (int) $term->term_id ] = $term;
}
}
}
foreach ( $terms_by_filter as $filter_id => $filter_config ) {
$taxonomy = $filter_config['taxonomy'];
$taxonomy_label = isset( $taxonomy_labels[ $taxonomy ] ) ? $taxonomy_labels[ $taxonomy ] : acewpf_get_admin_taxonomy_label( $taxonomy );
$term_map = isset( $term_maps[ $taxonomy ] ) ? $term_maps[ $taxonomy ] : array();
$labels = array();
foreach ( $filter_config['term_ids'] as $term_id ) {
if ( ! isset( $term_map[ $term_id ] ) ) {
continue;
}
$term = $term_map[ $term_id ];
$path = acewpf_get_admin_term_path( $term, $term_map, $taxonomy );
$label = $term->name;
if ( '' !== $path ) {
$label = $path . ' / ' . $label;
} elseif ( 'product_cat' !== $taxonomy ) {
$label = $taxonomy_label . ' / ' . $label;
}
$labels[] = $label;
if ( count( $labels ) >= 3 ) {
break;
}
}
$preview_map[ $filter_id ] = $labels;
}
return $preview_map;
}
function acewpf_get_filter_panel_preview_labels( $panel, $filter_sets ) {
$panel = is_array( $panel ) ? $panel : array();
$filter_sets = is_array( $filter_sets ) ? $filter_sets : array();
$labels = array();
$filter_ids = isset( $panel['filter_ids'] ) ? acewpf_parse_filter_id_list( $panel['filter_ids'] ) : array();
foreach ( $filter_ids as $filter_id ) {
if ( ! isset( $filter_sets[ $filter_id ]['name'] ) ) {
continue;
}
$labels[] = $filter_sets[ $filter_id ]['name'];
if ( count( $labels ) >= 4 ) {
break;
}
}
return $labels;
}
function acewpf_render_color_style_field( $field_id, $field_name, $label, $value, $placeholder, $description = '' ) {
?>
'0',
'max' => '',
'step' => '1',
'description' => '',
)
);
?>
array(),
'tablet' => array( 'laptop' ),
'mobile' => array( 'laptop', 'tablet' ),
);
if ( ! isset( $inheritance_map[ $mode_key ] ) ) {
return $inherited_value;
}
foreach ( $inheritance_map[ $mode_key ] as $inherit_mode ) {
if ( ! empty( $responsive[ $inherit_mode ][ $field_key ] ) ) {
$inherited_value = (string) $responsive[ $inherit_mode ][ $field_key ];
}
}
return $inherited_value;
}
function acewpf_render_inline_responsive_fields( $filter_id, $field_prefix, $styles, $mode_key, $mode_config, $field_configs ) {
$styles = is_array( $styles ) ? $styles : array();
$responsive = isset( $styles['responsive'] ) && is_array( $styles['responsive'] ) ? $styles['responsive'] : array();
$current_values = isset( $responsive[ $mode_key ] ) && is_array( $responsive[ $mode_key ] ) ? $responsive[ $mode_key ] : acewpf_get_default_responsive_style_overrides();
$base_name = $field_prefix . '[styles][responsive][' . $mode_key . ']';
?>
__( 'Desktop', 'ace-products-filters' ),
'laptop' => __( 'Laptop', 'ace-products-filters' ),
'tablet' => __( 'Tablet', 'ace-products-filters' ),
'mobile' => __( 'Mobile', 'ace-products-filters' ),
);
?>
>
'deleted',
)
)
);
exit;
}
$is_new_filter = '' === $current_filter_id || ! isset( $stored_filters[ $current_filter_id ] );
if ( $is_new_filter ) {
$current_filter_id = '';
$posted_filter['current_id'] = '';
} else {
$posted_filter['current_id'] = $current_filter_id;
}
$posted_filter['id'] = $requested_filter_id;
$prepared_filter = acewpf_prepare_filter_inputs( $posted_filter, $stored_filter );
$sanitized_filter = acewpf_sanitize_filter_set( $current_filter_id, $prepared_filter, array_keys( $stored_filters ) );
if ( '' === trim( $sanitized_filter['name'] ) ) {
/* translators: %d: next available filter set number. */
$sanitized_filter['name'] = sprintf( __( 'Filter Set %d', 'ace-products-filters' ), count( $stored_filters ) + 1 );
}
if ( '' !== $current_filter_id && $current_filter_id !== $sanitized_filter['id'] ) {
$stored_panels = acewpf_get_option_with_legacy( ACEWPF_OPTION_FILTER_PANELS, array() );
$stored_panels = is_array( $stored_panels ) ? $stored_panels : array();
foreach ( $stored_panels as $stored_panel_id => $stored_panel ) {
$panel_filter_ids = acewpf_parse_filter_id_list( isset( $stored_panel['filter_ids'] ) ? $stored_panel['filter_ids'] : array() );
if ( empty( $panel_filter_ids ) ) {
continue;
}
$updated_filter_ids = array();
foreach ( $panel_filter_ids as $panel_filter_id ) {
$updated_filter_ids[] = $panel_filter_id === $current_filter_id ? $sanitized_filter['id'] : $panel_filter_id;
}
$stored_panel['filter_ids'] = $updated_filter_ids;
$stored_panels[ $stored_panel_id ] = acewpf_sanitize_filter_panel( $stored_panel_id, $stored_panel, array_keys( $stored_panels ) );
}
update_option( ACEWPF_OPTION_FILTER_PANELS, $stored_panels );
}
$stored_filters = acewpf_replace_associative_entry_preserving_order( $stored_filters, $current_filter_id, $sanitized_filter['id'], $sanitized_filter );
update_option( ACEWPF_OPTION_FILTER_SETS, $stored_filters );
wp_safe_redirect(
acewpf_get_admin_page_url(
array(
'acewpf_action' => 'edit',
'filter_id' => $sanitized_filter['id'],
'acewpf_notice' => 'saved',
)
)
);
exit;
}
add_action( 'admin_post_acewpf_save_settings', 'acewpf_handle_settings_save' );
function acewpf_handle_display_settings_save() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to manage these settings.', 'ace-products-filters' ) );
}
check_admin_referer( 'acewpf_save_display_settings' );
$stored_settings = acewpf_get_option_with_legacy( ACEWPF_OPTION_DISPLAY_SETTINGS, array() );
$stored_settings = is_array( $stored_settings ) ? $stored_settings : array();
$posted_settings = acewpf_get_admin_posted_array( 'acewpf_display_settings', 'cpf_display_settings' );
$sanitized_settings = acewpf_sanitize_display_settings( $posted_settings );
update_option( ACEWPF_OPTION_DISPLAY_SETTINGS, array_merge( $stored_settings, $sanitized_settings ) );
wp_safe_redirect(
acewpf_get_admin_page_url(
array(
'acewpf_notice' => 'display_saved',
)
)
);
exit;
}
add_action( 'admin_post_acewpf_save_display_settings', 'acewpf_handle_display_settings_save' );
function acewpf_get_content_filters_plugin_url() {
return 'https://wordpress.org/plugins/ace-content-filters/';
}
function acewpf_should_show_content_filters_promo() {
if ( defined( 'ACEWPCF_VERSION' ) ) {
return false;
}
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
return ! (bool) get_user_meta( get_current_user_id(), 'acewpf_hide_content_filters_notice', true );
}
function acewpf_handle_dismiss_content_filters_notice() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to manage these settings.', 'ace-products-filters' ) );
}
check_admin_referer( 'acewpf_dismiss_content_filters_notice' );
update_user_meta( get_current_user_id(), 'acewpf_hide_content_filters_notice', 1 );
wp_safe_redirect( acewpf_get_admin_page_url() );
exit;
}
add_action( 'admin_post_acewpf_dismiss_content_filters_notice', 'acewpf_handle_dismiss_content_filters_notice' );
function acewpf_render_content_filters_promo() {
if ( ! acewpf_should_show_content_filters_promo() ) {
return;
}
$plugin_url = acewpf_get_content_filters_plugin_url();
$dismiss_url = wp_nonce_url(
admin_url( 'admin-post.php?action=acewpf_dismiss_content_filters_notice' ),
'acewpf_dismiss_content_filters_notice'
);
?>
__( 'You are not allowed to preview these settings.', 'ace-products-filters' ),
),
403
);
}
check_ajax_referer( 'acewpf_preview_filter', 'nonce' );
$stored_filters = acewpf_get_option_with_legacy( ACEWPF_OPTION_FILTER_SETS, array() );
$stored_filters = is_array( $stored_filters ) ? $stored_filters : array();
$posted_filter = acewpf_get_admin_posted_array( 'acewpf_filter', 'cpf_filter' );
$current_filter_id = isset( $posted_filter['current_id'] ) ? sanitize_key( $posted_filter['current_id'] ) : '';
$requested_filter_id = isset( $posted_filter['id'] ) ? sanitize_key( $posted_filter['id'] ) : '';
$stored_filter = isset( $stored_filters[ $current_filter_id ] ) ? $stored_filters[ $current_filter_id ] : array();
if ( '' === $current_filter_id ) {
$current_filter_id = $requested_filter_id;
}
if ( '' === $current_filter_id || ! isset( $stored_filters[ $current_filter_id ] ) ) {
$current_filter_id = '';
$posted_filter['current_id'] = '';
} else {
$posted_filter['current_id'] = $current_filter_id;
}
$posted_filter['id'] = $requested_filter_id;
$prepared_filter = acewpf_prepare_filter_inputs( $posted_filter, $stored_filter );
$sanitized_filter = acewpf_sanitize_filter_set( $current_filter_id, $prepared_filter, array_keys( $stored_filters ) );
wp_send_json_success(
array(
'filter' => $sanitized_filter,
)
);
}
add_action( 'wp_ajax_acewpf_preview_filter', 'acewpf_handle_filter_preview_ajax' );
function acewpf_handle_panel_save() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to manage these settings.', 'ace-products-filters' ) );
}
check_admin_referer( 'acewpf_save_panel' );
$stored_panels = acewpf_get_option_with_legacy( ACEWPF_OPTION_FILTER_PANELS, array() );
$stored_panels = is_array( $stored_panels ) ? $stored_panels : array();
$posted_panel = acewpf_get_admin_posted_array( 'acewpf_panel', 'cpf_panel' );
$current_panel_id = isset( $posted_panel['current_id'] ) ? sanitize_key( $posted_panel['current_id'] ) : '';
$requested_panel_id = isset( $posted_panel['id'] ) ? sanitize_key( $posted_panel['id'] ) : '';
if ( '' === $current_panel_id ) {
$current_panel_id = $requested_panel_id;
}
$is_existing_panel = '' !== $current_panel_id && isset( $stored_panels[ $current_panel_id ] );
if ( acewpf_has_admin_posted_key( 'acewpf_delete_panel', 'cpf_delete_panel' ) ) {
if ( '' !== $current_panel_id && isset( $stored_panels[ $current_panel_id ] ) ) {
unset( $stored_panels[ $current_panel_id ] );
}
update_option( ACEWPF_OPTION_FILTER_PANELS, $stored_panels );
wp_safe_redirect(
acewpf_get_admin_page_url(
array(
'acewpf_notice' => 'panel_deleted',
)
)
);
exit;
}
if ( empty( acewpf_get_filter_sets() ) ) {
wp_safe_redirect(
acewpf_get_admin_page_url(
array(
'acewpf_notice' => 'panel_needs_filters',
)
)
);
exit;
}
if ( ! $is_existing_panel ) {
$current_panel_id = '';
$posted_panel['current_id'] = '';
} else {
$posted_panel = acewpf_prepare_panel_inputs( $posted_panel, $stored_panels[ $current_panel_id ] );
$posted_panel['current_id'] = $current_panel_id;
}
$posted_panel['id'] = $requested_panel_id;
$sanitized_panel = acewpf_sanitize_filter_panel( $current_panel_id, $posted_panel, array_keys( $stored_panels ) );
if ( empty( $sanitized_panel['filter_ids'] ) ) {
wp_safe_redirect(
acewpf_get_admin_page_url(
array(
'acewpf_action' => $is_existing_panel ? 'panel_edit' : 'panel_new',
'panel_id' => $current_panel_id,
'acewpf_notice' => 'panel_requires_filters',
)
)
);
exit;
}
if ( '' === trim( $sanitized_panel['name'] ) ) {
/* translators: %d: next available filter panel number. */
$sanitized_panel['name'] = sprintf( __( 'Filter Panel %d', 'ace-products-filters' ), count( $stored_panels ) + 1 );
}
$stored_panels = acewpf_replace_associative_entry_preserving_order( $stored_panels, $current_panel_id, $sanitized_panel['id'], $sanitized_panel );
update_option( ACEWPF_OPTION_FILTER_PANELS, $stored_panels );
wp_safe_redirect(
acewpf_get_admin_page_url(
array(
'acewpf_action' => 'panel_edit',
'panel_id' => $sanitized_panel['id'],
'acewpf_notice' => 'panel_saved',
)
)
);
exit;
}
add_action( 'admin_post_acewpf_save_panel', 'acewpf_handle_panel_save' );
function acewpf_handle_product_search_save() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to manage these settings.', 'ace-products-filters' ) );
}
check_admin_referer( 'acewpf_save_product_search' );
$stored_searches = acewpf_get_option_with_legacy( ACEWPF_OPTION_PRODUCT_SEARCHES, array() );
$stored_searches = is_array( $stored_searches ) ? $stored_searches : array();
$posted_search = acewpf_get_admin_posted_array( 'acewpf_product_search' );
$current_search_id = isset( $posted_search['current_id'] ) ? sanitize_key( $posted_search['current_id'] ) : '';
$requested_search_id = isset( $posted_search['id'] ) ? sanitize_key( $posted_search['id'] ) : '';
if ( '' === $current_search_id ) {
$current_search_id = $requested_search_id;
}
$is_existing_search = '' !== $current_search_id && isset( $stored_searches[ $current_search_id ] );
if ( acewpf_has_admin_posted_key( 'acewpf_delete_product_search' ) ) {
if ( '' !== $current_search_id && isset( $stored_searches[ $current_search_id ] ) ) {
unset( $stored_searches[ $current_search_id ] );
}
update_option( ACEWPF_OPTION_PRODUCT_SEARCHES, $stored_searches );
wp_safe_redirect(
acewpf_get_admin_page_url(
array(
'acewpf_notice' => 'search_deleted',
)
)
);
exit;
}
if ( ! $is_existing_search ) {
$current_search_id = '';
$posted_search['current_id'] = '';
} else {
$posted_search['current_id'] = $current_search_id;
}
$posted_search['id'] = $requested_search_id;
$sanitized_search = acewpf_sanitize_product_search( $current_search_id, $posted_search, array_keys( $stored_searches ) );
if ( '' === trim( $sanitized_search['name'] ) ) {
/* translators: %d: next available product search number. */
$sanitized_search['name'] = sprintf( __( 'Product Search %d', 'ace-products-filters' ), count( $stored_searches ) + 1 );
}
$stored_searches = acewpf_replace_associative_entry_preserving_order( $stored_searches, $current_search_id, $sanitized_search['id'], $sanitized_search );
update_option( ACEWPF_OPTION_PRODUCT_SEARCHES, $stored_searches );
wp_safe_redirect(
acewpf_get_admin_page_url(
array(
'acewpf_action' => 'search_edit',
'search_id' => $sanitized_search['id'],
'acewpf_notice' => 'search_saved',
)
)
);
exit;
}
add_action( 'admin_post_acewpf_save_product_search', 'acewpf_handle_product_search_save' );
function acewpf_render_admin_notice( $notice ) {
if ( '' === $notice ) {
return;
}
$messages = array(
'saved' => array(
'class' => 'notice notice-success is-dismissible',
'message' => __( 'Filter set saved.', 'ace-products-filters' ),
),
'display_saved' => array(
'class' => 'notice notice-success is-dismissible',
'message' => __( 'Typography settings saved.', 'ace-products-filters' ),
),
'deleted' => array(
'class' => 'notice notice-success is-dismissible',
'message' => __( 'Filter set deleted.', 'ace-products-filters' ),
),
'missing' => array(
'class' => 'notice notice-warning is-dismissible',
'message' => __( 'That filter set no longer exists.', 'ace-products-filters' ),
),
'panel_saved' => array(
'class' => 'notice notice-success is-dismissible',
'message' => __( 'Filter panel saved.', 'ace-products-filters' ),
),
'panel_deleted' => array(
'class' => 'notice notice-success is-dismissible',
'message' => __( 'Filter panel deleted.', 'ace-products-filters' ),
),
'panel_missing' => array(
'class' => 'notice notice-warning is-dismissible',
'message' => __( 'That filter panel no longer exists.', 'ace-products-filters' ),
),
'panel_needs_filters' => array(
'class' => 'notice notice-warning is-dismissible',
'message' => __( 'Create at least one filter set before creating a filter panel.', 'ace-products-filters' ),
),
'panel_requires_filters' => array(
'class' => 'notice notice-warning is-dismissible',
'message' => __( 'Choose at least one filter set for this panel.', 'ace-products-filters' ),
),
'search_saved' => array(
'class' => 'notice notice-success is-dismissible',
'message' => __( 'Product search saved.', 'ace-products-filters' ),
),
'search_deleted' => array(
'class' => 'notice notice-success is-dismissible',
'message' => __( 'Product search deleted.', 'ace-products-filters' ),
),
'search_missing' => array(
'class' => 'notice notice-warning is-dismissible',
'message' => __( 'That product search no longer exists.', 'ace-products-filters' ),
),
);
$messages = apply_filters( 'acewpf_admin_notice_messages', $messages );
if ( ! isset( $messages[ $notice ] ) ) {
return;
}
?>
0 ) ? wp_get_attachment_image_url( $rating_star_attachment_id, 'full' ) : '';
$rating_star_preview_url = ( $rating_star_attachment_id > 0 ) ? wp_get_attachment_image_url( $rating_star_attachment_id, 'thumbnail' ) : '';
if ( ! is_string( $rating_star_preview_url ) || '' === $rating_star_preview_url ) {
$rating_star_preview_url = $rating_star_full_url;
}
$rating_star_full_url = is_string( $rating_star_full_url ) ? $rating_star_full_url : '';
$rating_suffix = isset( $filter['rating_suffix'] ) ? (string) $filter['rating_suffix'] : '';
$orientation = isset( $filter['orientation'] ) ? acewpf_sanitize_filter_orientation( $filter['orientation'] ) : 'horizontal';
$term_ids = isset( $filter['term_ids'] ) && is_array( $filter['term_ids'] ) ? $filter['term_ids'] : ( isset( $filter['category_ids'] ) ? $filter['category_ids'] : array() );
$source_choices = acewpf_get_filter_source_choices();
$orientation_choices = acewpf_get_filter_orientation_choices();
$attribute_taxonomies = acewpf_get_product_attribute_taxonomy_choices();
$product_taxonomies = acewpf_get_product_taxonomy_choices();
$has_registered_attribute_taxonomies = ! empty( $attribute_taxonomies );
$has_registered_product_taxonomies = ! empty( $product_taxonomies );
$term_option_groups = is_array( $category_options ) ? $category_options : array();
$source_taxonomy_choices = 'custom_taxonomy' === $source_type ? $product_taxonomies : $attribute_taxonomies;
$term_panel_title = __( 'Filter terms', 'ace-products-filters' );
$term_panel_description = 'product_cat' === $source_taxonomy
? __( 'Duplicate category names are shown with their full parent path so similarly named terms stay easy to distinguish.', 'ace-products-filters' )
: __( 'Choose which terms should appear in this filter.', 'ace-products-filters' );
$source_description = __( 'Choose whether this filter uses product categories, WooCommerce attributes, product taxonomies, a price range, or product properties such as sale, stock, rating, and featured.', 'ace-products-filters' );
$source_taxonomy_description = __( 'Choose which saved WooCommerce taxonomy this filter should use.', 'ace-products-filters' );
if ( $is_price_filter ) {
$source_description = __( 'Use a price range slider that updates automatically based on the products currently matching other active filters.', 'ace-products-filters' );
} elseif ( $is_property_filter ) {
$term_panel_title = __( 'Filter options', 'ace-products-filters' );
$term_panel_description = __( 'Choose which options should appear in this filter.', 'ace-products-filters' );
$source_description = function_exists( 'acewpf_get_product_property_source_description' )
? acewpf_get_product_property_source_description( $source_type )
: $source_description;
if ( $is_rating_filter ) {
$term_panel_description = $uses_rating_stars
? __( 'Choose which rating thresholds should appear. Star icons replace the storefront text labels.', 'ace-products-filters' )
: __( 'Choose which rating thresholds should appear, and optionally replace the default storefront labels.', 'ace-products-filters' );
}
} elseif ( 'attribute' === $source_type ) {
$source_description = __( 'Use one WooCommerce global attribute and choose exactly which attribute terms should appear in the filter.', 'ace-products-filters' );
$source_taxonomy_description = __( 'Choose the global WooCommerce attribute this filter should use. Product-level custom attributes are not available here.', 'ace-products-filters' );
} elseif ( 'custom_taxonomy' === $source_type ) {
$source_description = __( 'Use any product taxonomy registered on your WooCommerce catalog, such as product tags, brands, manufacturers, or other product taxonomies added by your setup.', 'ace-products-filters' );
$source_taxonomy_description = __( 'Choose the product taxonomy this filter should use.', 'ace-products-filters' );
}
if ( 'attribute' === $source_type && ! $has_registered_attribute_taxonomies ) {
$term_panel_description = __( 'No global product attributes are available yet. Create them in WooCommerce > Products > Attributes, then assign terms to products before using them in a filter.', 'ace-products-filters' );
}
if ( 'custom_taxonomy' === $source_type && ! $has_registered_product_taxonomies ) {
$term_panel_description = __( 'No additional product taxonomies are available yet. Register or install a product taxonomy such as brands or manufacturers before using this filter source.', 'ace-products-filters' );
}
if ( 'attribute' === $source_type && ! isset( $source_choices['attribute'] ) ) {
$source_choices['attribute'] = __( 'Product attributes', 'ace-products-filters' );
}
if ( 'custom_taxonomy' === $source_type && ! isset( $source_choices['custom_taxonomy'] ) ) {
$source_choices['custom_taxonomy'] = __( 'Product taxonomy', 'ace-products-filters' );
}
if ( 'attribute' === $source_type && 'product_cat' !== $source_taxonomy && ! isset( $attribute_taxonomies[ $source_taxonomy ] ) ) {
$attribute_taxonomies[ $source_taxonomy ] = acewpf_get_admin_taxonomy_label( $source_taxonomy );
$source_taxonomy_choices = $attribute_taxonomies;
}
if ( 'custom_taxonomy' === $source_type && 'product_cat' !== $source_taxonomy && '' !== $source_taxonomy && ! isset( $product_taxonomies[ $source_taxonomy ] ) ) {
$product_taxonomies[ $source_taxonomy ] = acewpf_get_admin_taxonomy_label( $source_taxonomy );
$source_taxonomy_choices = $product_taxonomies;
}
$responsive_styles = isset( $styles['responsive'] ) && is_array( $styles['responsive'] ) ? $styles['responsive'] : acewpf_get_default_responsive_style_settings();
$responsive_modes = acewpf_get_responsive_style_modes();
$responsive_layouts = isset( $filter['responsive_layouts'] ) && is_array( $filter['responsive_layouts'] ) ? wp_parse_args( $filter['responsive_layouts'], acewpf_get_default_filter_responsive_layouts() ) : acewpf_get_default_filter_responsive_layouts();
$layout_choices = acewpf_get_filter_layout_choices();
$font_suggestions = acewpf_get_font_family_suggestions();
$font_weight_choices = acewpf_get_font_weight_choices();
$text_transform_choices = acewpf_get_text_transform_choices();
$count_display_choices = acewpf_get_filter_count_display_mode_choices();
$term_search_mode_choices = acewpf_get_filter_term_search_mode_choices();
$term_search_mode = isset( $filter['term_search_mode'] ) ? acewpf_sanitize_filter_term_search_mode( $filter['term_search_mode'] ) : 'terms';
$term_search_placeholder = isset( $filter['term_search_placeholder'] ) ? (string) $filter['term_search_placeholder'] : '';
$term_search_empty_message = isset( $filter['term_search_empty_message'] ) ? (string) $filter['term_search_empty_message'] : '';
$display_mode = isset( $filter['display_mode'] ) ? acewpf_sanitize_filter_display_mode( $filter['display_mode'] ) : 'buttons';
$swatch_shape = isset( $filter['swatch_shape'] ) ? acewpf_sanitize_filter_swatch_shape( $filter['swatch_shape'] ) : 'square';
$swatch_layout = isset( $filter['swatch_layout'] ) ? acewpf_sanitize_filter_swatch_layout( $filter['swatch_layout'] ) : 'wrap';
$term_colors = isset( $filter['term_colors'] ) && is_array( $filter['term_colors'] ) ? $filter['term_colors'] : array();
$uses_swatches = ! $is_price_filter && ! $is_property_filter && 'swatches' === $display_mode;
$field_prefix = 'acewpf_filter';
$shortcode = sprintf( '[acewpf_filter id="%s"]', $filter_id );
$title = $is_new ? __( 'Create Filter Set', 'ace-products-filters' ) : __( 'Edit Filter Set', 'ace-products-filters' );
$responsive_size_args = array(
'min' => '0',
'max' => '100',
'step' => '1',
);
$responsive_spacing_args = array(
'min' => '0',
'max' => '60',
'step' => '1',
);
?>
$panel_filter_order[ $right_id ];
}
if ( $left_selected !== $right_selected ) {
return $left_selected ? -1 : 1;
}
return strcasecmp( isset( $left['name'] ) ? $left['name'] : '', isset( $right['name'] ) ? $right['name'] : '' );
}
);
?>