PluginProbe
Filter Everything — WordPress & WooCommerce Filters / 1.9.7
Filter Everything — WordPress & WooCommerce Filters v1.9.7
1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2.2 1.9.2.1 trunk 1.2.1 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.1 1.4.4 1.4.5 1.4.8 1.4.9 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 All 52 releases
← All changes | views/frontend/dropdown.php +133 -76 1.9.2.11.9.7 View file →
@@ -24,9 +24,18 @@
24 24 $use_select2 = false;
25 25 $data_default = '';
26 26 $preload_html = '';
27 27 $data_color = '';
28 +$hide_for_apply_button_mode = flrt_check_apply_buttom_mode($set);
29 +$is_hide_empty_terms = (isset($set['hide_empty']['value']) && $set['hide_empty']['value'] === 'yes');
30 +$empty_parent_filter = !empty($view_args['empty_parent_filter']) && $view_args['empty_parent_filter'] === true;
28 31
32 +$args = [
33 + 'hide_empty' => $set['hide_empty']['value'],
34 + 'use_apply_button' => $view_args['use_apply_button'],
35 + 'hide_empty_filter' => isset($set['hide_empty_filter']['value']) ? $set['hide_empty_filter']['value'] : '',
36 +];
37 +
29 38 if ( flrt_get_experimental_option( 'select2_dropdowns' ) === 'on' ){
30 39 $use_select2 = true;
31 40 }
32 41
@@ -41,116 +50,164 @@
41 50
42 51 if ( $is_swatch ){
43 52 $data_default = ' data-image='.FLRT_PLUGIN_DIR_URL.'assets/img/no-image.png';
44 53 }
54 +$rating_slugs = flrt_rating_slugs();
55 +$parent_filter_apply_button_data = flrt_parent_filter_apply_button_data($filter, $view_args);
56 +$parent_filter_apply_class = flrt_parent_filter_apply_class($filter, $view_args, $terms);
45 57
58 +$is_parent_has_terms = false;
59 +if(!empty($terms) && $view_args['use_apply_button']){
60 +
61 + $first_term = reset($terms);
62 + if(!empty($first_term->show_with_parent)){
63 + $filter['hide_until_parent_class'] = false;
64 + }
65 +}
46 66 ?>
47 -<div class="<?php echo flrt_filter_class( $filter ); // Already escaped ?>" data-fid="<?php echo esc_attr( $filter['ID'] ); ?>">
67 +<div class="<?php echo flrt_filter_class( $filter, [], $terms, $args ); // Already escaped ?><?php echo $parent_filter_apply_class; ?>" data-fid="<?php echo esc_attr( $filter['ID'] ); ?>" data-filter-e-name="<?php echo esc_attr($filter['e_name']); ?>"<?php echo $parent_filter_apply_button_data; ?>>
48 68 <?php flrt_filter_header( $filter, $terms ); // Safe, escaped ?>
49 69 <div class="<?php echo esc_attr( flrt_filter_content_class( $filter ) ); ?>">
50 70 <?php if( ! empty( $terms ) || $view_args['ask_to_select_parent'] ): ?>
51 71 <select id="wpc-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-<?php echo esc_attr( $filter['ID'] ); ?>"
52 72 aria-label="wpc-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-<?php echo esc_attr( $filter['ID'] ); ?>"
53 - class="wpc-filters-widget-select">
54 - <?php if( $view_args['ask_to_select_parent'] !== false ) : ?>
73 + class="wpc-filters-widget-select" style="width: 100%">
74 + <?php if( $view_args['ask_to_select_parent'] !== false && !$view_args['use_apply_button'] ) : ?>
55 75 <option class="wpc-dropdown-default" value="0" data-wpc-link="<?php echo esc_attr( $noSelectUrl ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-0"><?php
56 76 echo esc_html( $view_args['ask_to_select_parent'] );
57 77 ?></option>
58 78 <?php else: ?>
59 - <option<?php echo esc_html( $data_default ); ?> class="wpc-dropdown-default" value="0" data-wpc-link="<?php echo esc_attr( $noSelectUrl ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-0"><?php
60 - echo esc_html( flrt_dropdown_default_option( $filter ) );
61 - ?></option>
62 - <?php
79 + <?php
80 + $default_option_text = esc_html( flrt_dropdown_default_option( $filter ) );
81 + if( $view_args['ask_to_select_parent'] !== false && $empty_parent_filter && $view_args['use_apply_button'] ){
82 + $default_option_text = esc_html( $view_args['ask_to_select_parent'] );
83 + }?>
63 84
64 - foreach ( $terms as $id => $term_object ) {
65 - $disabled = 0;
66 - $data_image = '';
67 - $selected = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0;
68 - $term_hidden_class = '';
69 - $data_count = '';
70 - $data_rating = '';
85 + <option<?php echo esc_html( $data_default ); ?> class="wpc-dropdown-default wpc-dropdown-default-<?php echo esc_attr( $filter['e_name'] ); ?>" value="0" data-wpc-link="<?php echo esc_attr( $noSelectUrl ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-0" data-wpc-select-parent-text="<?php echo esc_attr($view_args['ask_to_select_parent']);?>" data-wpc-default-option-text="<?php echo esc_attr(flrt_dropdown_default_option( $filter )); ?>"><?php
86 + echo $default_option_text;
87 + ?></option>
88 + <?php
71 89
72 - if( isset( $term_object->wp_queried ) && $term_object->wp_queried ){
73 - $disabled = 1;
74 - }
90 + foreach ( $terms as $id => $term_object ) {
91 + $disabled = 0;
92 + $data_image = '';
93 + $data_color = '';
94 + $selected = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0;
95 + $term_hidden_class = '';
96 + $data_count = '';
97 + $data_rating = '';
75 98
76 - if ( $is_brand && ! $is_swatch ) {
77 - $src = flrt_get_term_brand_image( $term_object->term_id, $filter );
78 - if ( $src ) {
79 - $data_image = ' data-brand=' . $src . '';
80 - $preload_html .= '<img class="wpc-preload-img" src='. $src .' />'."\r\n";
99 + if( isset( $term_object->wp_queried ) && $term_object->wp_queried ){
100 + $disabled = 1;
81 101 }
82 102
83 - if ( $filter['show_term_names'] === 'no' ) {
84 - $term_hidden_class = ' wpc-hidden-term-name';
103 + if ( $is_brand && ! $is_swatch ) {
104 + $src = flrt_get_term_brand_image( $term_object->term_id, $filter );
105 + if ( $src ) {
106 + $data_image = ' data-brand="' . esc_url( $src ) . '"';
107 + $preload_html .= '<img class="wpc-preload-img" src="'. esc_url( $src ) .'" />'."\r\n";
108 + }
109 +
110 + if ( $filter['show_term_names'] === 'no' ) {
111 + $term_hidden_class = ' wpc-hidden-term-name';
112 + }
85 113 }
86 - }
87 114
88 - if ( $is_swatch ) {
89 - $src = flrt_get_term_swatch_image( $term_object->term_id, $filter );
115 + if ( $is_swatch ) {
116 + $src = flrt_get_term_swatch_image( $term_object->term_id, $filter );
90 117
91 - if ( $src ) {
92 - $data_image = ' data-image=' . $src . '';
93 - $preload_html .= '<img class="wpc-preload-img" src='. $src .' />'."\r\n";
94 - } else {
95 - $maybe_color = flrt_get_term_swatch_color( $term_object->term_id, $filter );
96 - if ( $maybe_color ) {
97 - $data_color = ' data-color=' . $maybe_color . '';
118 + if ( $src ) {
119 + $data_image = ' data-image="' . esc_url( $src ) . '"';
120 + $preload_html .= '<img class="wpc-preload-img" src="'. esc_url( $src ) .'" />'."\r\n";
98 121 } else {
99 - $data_color = ' data-color=none';
122 + $maybe_color = flrt_get_term_swatch_color( $term_object->term_id, $filter );
123 + if ( $maybe_color ) {
124 + $data_color = ' data-color="' . esc_attr( $maybe_color ) . '"';
125 + } else {
126 + $data_color = ' data-color="none"';
127 + }
100 128 }
129 +
130 + if ( $filter['show_term_names'] === 'no' ) {
131 + $term_hidden_class = ' wpc-hidden-term-name';
132 + }
101 133 }
102 134
103 - if ( $filter['show_term_names'] === 'no' ) {
104 - $term_hidden_class = ' wpc-hidden-term-name';
135 + if( $set['show_count']['value'] === 'yes' && $use_select2 ) {
136 + $data_count = ' data-count="' . esc_attr( $term_object->cross_count ) . '"';
105 137 }
106 - }
107 138
108 - if( $set['show_count']['value'] === 'yes' && $use_select2 ) {
109 - $data_count = ' data-count=' . $term_object->cross_count;
110 - }
139 + $hidden_class_for_apply_button_mode = '';
140 + if($hide_for_apply_button_mode){
141 + $hidden_class_for_apply_button_mode = ($term_object->cross_count <= 0 && $is_hide_empty_terms) ? esc_attr(' wpc-term-count-hidden-0') : '';
142 + if($term_object->cross_count > 0){
143 + $hidden_class_for_apply_button_mode .= esc_attr(' wpc-has-terms');
144 + }
145 + if($selected){
146 + $hidden_class_for_apply_button_mode .= esc_attr(' wpc-term-count-hidden-checked-0');
147 + }
148 + }
111 149
112 - $rating = 0;
113 - if( mb_strpos( $term_object->slug, 'rated-' ) !== false){
114 - $pieces = explode("-", $term_object->slug);
115 - $rating = (int) isset( $pieces[1] ) ? $pieces[1] : 0;
116 - if ($rating < 1 || $rating > 5) {
117 - $rating = 0;
150 + $rating = 0;
151 + if( mb_strpos( $term_object->slug, 'rated-' ) !== false){
152 + $pieces = explode("-", $term_object->slug);
153 + $rating = (int) isset( $pieces[1] ) ? $pieces[1] : 0;
154 + if ($rating < 1 || $rating > 5) {
155 + $rating = 0;
156 + }
157 + $data_rating = ' data-star-rating="' . (int) $rating . '"';
118 158 }
119 - $data_rating = ' data-star-rating=' . $rating;
120 - }
121 - ?>
122 - <option<?php echo esc_html( $data_image ); echo esc_html( $data_color ); echo esc_html( $data_count ); echo esc_html( $data_rating );?> class="wpc-term-count-<?php echo esc_attr( $term_object->cross_count ); ?> wpc-term-id-<?php echo esc_attr($term_object->term_id); echo esc_attr( $term_hidden_class ); ?>" value="<?php echo esc_attr( $term_object->term_id ); ?>" <?php selected( 1, $selected ); ?> <?php disabled( 1, $disabled ); ?> data-wpc-link="<?php echo esc_attr( $url_manager->getTermUrl( $term_object->slug, $filter['e_name'], $filter['entity'] ) ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr($filter['e_name']); ?>-<?php echo esc_attr( $id ); ?>">
123 - <?php
124 - if ($rating > 0){
125 - if($use_select2){
126 - $rating_html = '';
127 - $i = 1;
128 - $label_star = '<span class="flrt-star-label %s">' . flrt_rating_star() . '</span>';
129 - while($i <=5){
130 - $star_class = '';
131 - if($i <= $rating){
132 - $star_class = 'flrt-star-label-hover';
159 + $rating_data = (isset($rating_slugs[$term_object->slug])) ? ' data-rating-num="' . esc_attr($rating_slugs[$term_object->slug]) . '" ' : '';
160 + $show_with_parent_class = '';
161 + if(isset($term_object->show_with_parent)) {
162 + if($term_object->show_with_parent === true){
163 + $show_with_parent_class = ' wpc-show-with-parent-true';
164 + }else{
165 + $show_with_parent_class = ' wpc-show-with-parent-false';
166 + }
167 + }
168 +
169 + if (!isset($term_object->show_with_parent)) {
170 + if ($view_args['ask_to_select_parent'] !== false && $view_args['use_apply_button']) {
171 + if ((!$selected)) {
172 + $show_with_parent_class = ' wpc-show-with-parent-false';
173 + }
174 + }
175 + }
176 +
177 + ?>
178 + <option<?php echo $data_image . $data_color . $data_count . $data_rating; // data-* values are esc_attr/esc_url-escaped and quoted above ?> data-wpc-chip="<?php echo esc_attr( $term_object->name ); ?>" class="wpc-term-item wpc-term-count-<?php echo esc_attr( $term_object->cross_count ); ?> wpc-term-id-<?php echo esc_attr($term_object->term_id); echo esc_attr( $term_hidden_class ); ?><?php echo $hidden_class_for_apply_button_mode; ?><?php echo esc_attr($show_with_parent_class); ?>" value="<?php echo esc_attr( $term_object->term_id ); ?>" <?php selected( 1, $selected ); ?> <?php disabled( 1, $disabled ); ?> data-wpc-link="<?php echo esc_attr( $url_manager->getTermUrl( $term_object->slug, $filter['e_name'], $filter['entity'] ) ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr($filter['e_name']); ?>-<?php echo esc_attr( $id ); ?>" data-wpc-e-name="<?php echo esc_attr($filter['e_name']); ?>" data-wpc-slug="<?php echo esc_attr( $term_object->slug ); ?>" data-term-id="<?php echo esc_attr($id); ?>"<?php echo $rating_data; ?>>
179 + <?php
180 + if ($rating > 0){
181 + if($use_select2){
182 + $rating_html = '';
183 + $i = 1;
184 + $label_star = '<span class="flrt-star-label %s">' . flrt_rating_star() . '</span>';
185 + while($i <=5){
186 + $star_class = '';
187 + if($i <= $rating){
188 + $star_class = 'flrt-star-label-hover';
189 + }
190 + $rating_html .= sprintf($label_star, $star_class);
191 + $i++;
133 192 }
134 - $rating_html .= sprintf($label_star, $star_class);
135 - $i++;
193 + echo $rating_html;
194 + }else{
195 + echo sprintf(
196 + _n('%d star', '%d stars', $rating, 'filter-everything'),
197 + $rating
198 + );
136 199 }
137 - echo $rating_html;
138 200 }else{
139 - echo sprintf(
140 - _n('%d star', '%d stars', $rating, 'filter-everything'),
141 - $rating
142 - );
201 + echo esc_html( $term_object->name );
143 202 }
144 - }else{
145 - echo esc_html( $term_object->name );
146 - }
147 203
148 - if( $set['show_count']['value'] === 'yes' && ! $use_select2 ) {
149 - echo esc_html( ' ('.$term_object->cross_count.')' );
150 - }
151 - ?></option>
152 - <?php } ?><!-- end foreach -->
204 + if( $set['show_count']['value'] === 'yes' && ! $use_select2 ) {
205 + echo esc_html( ' ('.$term_object->cross_count.')' );
206 + }
207 + ?></option>
208 + <?php } ?><!-- end foreach -->
209 +
153 210 <?php endif; ?>
154 211 </select>
155 212 <?php echo $preload_html; ?>
156 213 <?php else: