From 5086ab69240975f353365fec7adab10ff7947c18 Mon Sep 17 00:00:00 2001 From: Mohammed Razzaq Date: Tue, 20 Sep 2022 03:06:58 +0530 Subject: [PATCH 1/2] Add option to toggle term counter --- .../components/common/checkbox-list.js | 7 ++++- assets/js/instant-results/config.js | 2 ++ .../Feature/InstantResults/InstantResults.php | 29 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/assets/js/instant-results/components/common/checkbox-list.js b/assets/js/instant-results/components/common/checkbox-list.js index 9a0fbb8c17..2c9df1212f 100644 --- a/assets/js/instant-results/components/common/checkbox-list.js +++ b/assets/js/instant-results/components/common/checkbox-list.js @@ -9,6 +9,7 @@ import { __, _n, sprintf } from '@wordpress/i18n'; */ import Checkbox from './checkbox'; import SmallButton from './small-button'; +import { termCount } from '../../config'; /** * Checkbox list component. @@ -124,6 +125,10 @@ export default ({ disabled, label, options, onChange, selected, sortBy }) => { */ const displayOption = ({ count, id, label, value }) => { const children = childOptions[value]; + /** + * Check for term count option. + */ + const counter = termCount === '1' ? count : ''; if (!showAll && optionsShown >= optionsLimit) { return ; @@ -133,7 +138,7 @@ export default ({ disabled, label, options, onChange, selected, sortBy }) => {
  • 'mark', 'facets' => 'post_type,category,post_tag', 'match_type' => 'all', + 'term_count' => '1', ]; $settings = $this->get_settings() ? $this->get_settings() : array(); @@ -171,6 +172,18 @@ public function output_feature_box_settings() {

    +
    +
    +
    +
    + +

    +
    +
    $this->settings['match_type'], 'paramPrefix' => 'ep-', 'postTypeLabels' => $this->get_post_type_labels(), + 'termCount' => $this->settings['term_count'], ) ); } @@ -923,4 +938,18 @@ public function get_args_schema() { } return $args; } + + /** + * Sanitizes our term count settings. + * + * @param array $settings Array of current settings + * @return mixed + */ + public function sanitize_count_settings( $settings ) { + if ( ! empty( $settings['instant-results']['term_count'] ) ) { + $settings['instant-results']['term_count'] = (bool) $settings['instant-results']['term_count']; + } + + return $settings; + } } From 2741cfa27d2d36b11da050ec3a3854b92952b52c Mon Sep 17 00:00:00 2001 From: Mohammed Razzaq Date: Tue, 4 Oct 2022 17:00:13 +0530 Subject: [PATCH 2/2] Remove unused code --- .../Feature/InstantResults/InstantResults.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/includes/classes/Feature/InstantResults/InstantResults.php b/includes/classes/Feature/InstantResults/InstantResults.php index 69dbb88ce6..c5d3b4bcc6 100644 --- a/includes/classes/Feature/InstantResults/InstantResults.php +++ b/includes/classes/Feature/InstantResults/InstantResults.php @@ -237,7 +237,6 @@ public function setup() { add_action( 'pre_get_posts', [ $this, 'maybe_apply_product_visibility' ] ); add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_frontend_assets' ] ); add_action( 'wp_footer', [ $this, 'render' ] ); - add_filter( 'ep_sanitize_feature_settings', [ $this, 'sanitize_count_settings' ] ); } /** @@ -939,17 +938,4 @@ public function get_args_schema() { return $args; } - /** - * Sanitizes our term count settings. - * - * @param array $settings Array of current settings - * @return mixed - */ - public function sanitize_count_settings( $settings ) { - if ( ! empty( $settings['instant-results']['term_count'] ) ) { - $settings['instant-results']['term_count'] = (bool) $settings['instant-results']['term_count']; - } - - return $settings; - } }