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 | src/Walkers/WalkerCheckbox.php +110 -18 1.6.11.9.7 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 2
3 3 namespace FilterEverything\Filter;
4 4
5 -if ( ! defined('WPINC') ) {
6 - wp_die();
5 +if ( ! defined('ABSPATH') ) {
6 + exit;
7 7 }
8 8
9 9
10 10 class WalkerCheckbox extends \Walker
@@ -86,9 +86,8 @@
86 86 * @param array $args Optional. An array of arguments. See wp_list_categories(). Default empty array.
87 87 * @param int $id Optional. ID of the current category. Default 0.
88 88 */
89 89 public function start_el( &$output, $term, $depth = 0, $args = array(), $id = 0 ) {
90 -
91 90 $term_name = esc_attr( $term->name );
92 91 $url_manager = $args['url_manager'];
93 92 $filter = $args['filter'];
94 93 $checked = ( in_array( $term->slug, $filter['values'] ) ) ? 1 : 0;
@@ -108,11 +107,12 @@
108 107 return;
109 108 }
110 109
111 110 $atts = array();
112 - //$set = isset( $args['set']['ID'] ) ? array( 0 => array('ID' => $args['set']['ID'] ) ) : [];
113 - $atts['href'] = $url_manager->getTermUrl( $term->slug, $filter['e_name']/*, $set*/ );
111 + $atts['href'] = flrt_get_filtered_term_url($term, $filter, $url_manager);
114 112
113 + $atts['class'] = 'wpc-filter-link';
114 +
115 115 $attributes = '';
116 116 foreach ( $atts as $attr => $value ) {
117 117 if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
118 118 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
@@ -122,30 +122,80 @@
122 122
123 123 $link = apply_filters( 'wpc_filters_checkbox_term_html', '<a'.$attributes.'>'.$term->name.'</a>', $attributes, $term, $filter );
124 124
125 125 if ( isset( $args['set']['show_count']['value'] ) && $args['set']['show_count']['value'] === 'yes' ) {
126 - $link .= '&nbsp;'. flrt_get_count( $term );
126 + $link .= flrt_filter_get_count( $term );
127 127 }
128 + $is_hide_empty_terms = (isset($args['set']['hide_empty']['value']) && $args['set']['hide_empty']['value'] === 'yes');
129 + $hide_for_apply_button_mode = flrt_check_apply_buttom_mode($args['set']);
128 130
129 - $output .= "\t<li";
130 - $cross_count = isset( $term->cross_count ) ? esc_attr( $term->cross_count ) : '';
131 + $show_with_parent_class = '';
132 + $isShowWithParentClass = false;
133 + if(isset($term->show_with_parent)) {
134 + if($term->show_with_parent === true){
135 + $isShowWithParentClass = true;
136 + $show_with_parent_class = 'wpc-show-with-parent-true';
137 + }else{
138 + $show_with_parent_class = 'wpc-show-with-parent-false';
139 + }
140 + }
131 141
132 - $parent_opened_elements_flipped = array_flip( $this->parent_opened_elements );
133 - if( isset( $parent_opened_elements_flipped[$id] ) ){
134 - $visibility_class = ' wpc-opened';
142 + if (!isset($term->show_with_parent)) {
143 + if ($args['ask_to_select_parent'] !== false && $args['use_apply_button']) {
144 + if ((!$checked)) {
145 + $show_with_parent_class = 'wpc-show-with-parent-false';
146 + }
147 + }
135 148 }
136 149
137 - if( $this->max_depth > 0) {
138 - $visibility_class = ' '. flrt_get_status_css_class( $id, FLRT_HIERARCHY_LIST_COOKIE_NAME );
150 +
151 + $hidden_class_for_apply_button_mode = '';
152 + $more_less_hidden_class = '';
153 + if ($args['isMoreLess']) {
154 + if (!empty($term->apply_button_style) && $term->apply_button_style === true) {
155 + $more_less_hidden_class = 'wpc-not-hidden-term';
156 + }
139 157 }
158 + if($hide_for_apply_button_mode){
159 + $hidden_class_for_apply_button_mode = ($term->cross_count <= 0 && $is_hide_empty_terms) ? esc_attr(' wpc-term-count-hidden-0') : '';
160 + if($checked){
161 + $hidden_class_for_apply_button_mode .= esc_attr('wpc-term-count-hidden-checked-0');
162 + }
163 + }
140 164
165 + $output .= "\t<li";
166 + $cross_count = isset( $term->cross_count ) ? esc_attr( $term->cross_count ) : '';
167 +
141 168 $css_classes = array(
142 169 0 => 'wpc-checkbox-item',
143 170 1 => 'wpc-term-item',
144 171 3 => 'wpc-term-count-' . $cross_count,
145 - 4 => 'wpc-term-id-'.$id
172 + 4 => 'wpc-term-id-'.$id,
173 + 5 => $hidden_class_for_apply_button_mode,
174 + 6 => $more_less_hidden_class,
175 + 7 => esc_attr($show_with_parent_class),
146 176 );
147 177
178 + if( $this->max_depth > 0 ) {
179 + $visibility_class = flrt_get_status_css_class( $id, FLRT_HIERARCHY_LIST_COOKIE_NAME );
180 + // If has already saved visibility class
181 + if ( $visibility_class === '' ) {
182 + // If there is no saved visibility class
183 + $parent_opened_elements_flipped = array_flip( $this->parent_opened_elements );
184 +
185 + if ( isset( $parent_opened_elements_flipped[$id] ) ) {
186 + $visibility_class = 'wpc-opened';
187 + }
188 +
189 + if ( $this->has_children && $checked && $visibility_class === '' ) {
190 + $visibility_class = 'wpc-opened';
191 + }
192 + }
193 +
194 + $css_classes[] = $visibility_class;
195 + }
196 +
197 +
148 198 if( $checked ){
149 199 $css_classes[2] = 'wpc-term-selected';
150 200 }
151 201
@@ -158,21 +208,23 @@
158 208 $toggleButton = '<i class="wpc-toggle-children-list" data-tid="'.esc_attr($term->term_id).'"></i>';
159 209 }
160 210
161 211 $has_not_empty_children_flipped = array_flip( $this->has_not_empty_children );
162 -// if( in_array( $id, $this->has_not_empty_children ) ){
163 212 if( isset( $has_not_empty_children_flipped[$id] ) ){
164 213 $css_classes[] = 'wpc-has-not-empty-children';
165 214 }
166 215
167 216 $css_classes = implode( ' ', $css_classes );
168 - $css_classes .= $visibility_class;
169 217 $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
170 218
219 + $rating_slugs = flrt_rating_slugs();
220 +
221 + $rating_data = (isset($rating_slugs[$term->slug])) ? ' data-rating-num="' . esc_attr($rating_slugs[$term->slug]) . '" ' : '';
222 +
171 223 $output .= $css_classes;
172 224 $output .= ' id="'.flrt_term_id('term', $filter, $id, false).'">';
173 - $output .= '<div class="wpc-term-item-content-wrapper'.esc_attr( $visibility_class ).'"><input '.checked( 1, $checked, false ).' '.disabled( 1, $disabled, false ).' type="checkbox" data-wpc-link="'.esc_url($atts['href']).'"';
174 - $output .= ' id="'.flrt_term_id('checkbox', $filter, $id, false).'" />'."\n";
225 + $output .= '<div class="wpc-term-item-content-wrapper"><input '.checked( 1, $checked, false ).' '.disabled( 1, $disabled, false ).' type="checkbox" data-wpc-link="'.esc_url($atts['href']).'" data-wpc-e-name="'.esc_attr($filter['e_name']).'" data-wpc-slug="'.esc_attr($term->slug).'" data-term-id="' . esc_attr($id) . '"';
226 + $output .= ' id="'.flrt_term_id('checkbox', $filter, $id, false).'"' . $rating_data .' />'."\n";
175 227 $output .= '<label for="'.flrt_term_id('checkbox', $filter, $id, false).'">';
176 228 $output .= "$link\n";
177 229 $output .= "</label>\n";
178 230 $output .= $toggleButton;
@@ -209,11 +261,28 @@
209 261
210 262 $parent_field = $this->db_fields['parent'];
211 263
212 264 // Flat display.
265 + $flrt_more_less_count = flrt_more_less_count();
266 + $isParentFilter = flrtParentFilter($args[0]['filter']);
267 + $hidden_terms_count = 1;
213 268 if ( -1 == $max_depth ) {
214 269 $empty_array = array();
270 +
215 271 foreach ( $elements as $e ) {
272 + if ( $args[0]['isMoreLess'] ) {
273 +
274 + $is_visible = !$isParentFilter || ( isset( $e->show_with_parent ) && $e->show_with_parent === true ) || !isset( $e->show_with_parent );
275 + $has_results = !$args[0]['is_hide_empty_terms'] || $e->cross_count > 0;
276 +
277 + if ( $is_visible && $has_results ) {
278 + if ( $hidden_terms_count <= $flrt_more_less_count ) {
279 + $e->apply_button_style = true;
280 + }
281 + $hidden_terms_count++;
282 + }
283 + }
284 +
216 285 $this->display_element( $e, $empty_array, 1, 0, $args, $output );
217 286 }
218 287 return $output;
219 288 }
@@ -262,8 +331,31 @@
262 331 if ( $root->$parent_field == $e->$parent_field ) {
263 332 $top_level_elements[] = $e;
264 333 } else {
265 334 $children_elements[ $e->$parent_field ][] = $e;
335 + }
336 + }
337 + }
338 +
339 + /*
340 + * Same More/Less marking as in the flat branch above. Only top-level terms
341 + * are counted: the reveal CSS (.wpc-filters-ul-list > li.wpc-not-hidden-term)
342 + * targets direct children of the list, nested children follow their parent.
343 + * Without this, a hierarchical More/Less list renders with all terms hidden
344 + * until JS re-marks them.
345 + */
346 + if ( $args[0]['isMoreLess'] ) {
347 + $has_not_empty_children_flipped = array_flip( $this->has_not_empty_children );
348 +
349 + foreach ( $top_level_elements as $e ) {
350 + $is_visible = !$isParentFilter || ( isset( $e->show_with_parent ) && $e->show_with_parent === true ) || !isset( $e->show_with_parent );
351 + $has_results = !$args[0]['is_hide_empty_terms'] || $e->cross_count > 0 || isset( $has_not_empty_children_flipped[ $e->term_id ] );
352 +
353 + if ( $is_visible && $has_results ) {
354 + if ( $hidden_terms_count <= $flrt_more_less_count ) {
355 + $e->apply_button_style = true;
356 + }
357 + $hidden_terms_count++;
266 358 }
267 359 }
268 360 }
269 361