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 +121 -18 1.5.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,13 +86,19 @@
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;
94 + $disabled = 0;
95 +
96 + if( isset( $term->wp_queried ) && $term->wp_queried ){
97 + $checked = 1;
98 + $disabled = 1;
99 + }
100 +
95 101 $id = $id ? $id : $term->term_id;
96 102 $toggleButton = '';
97 103 $visibility_class = '';
98 104
@@ -101,11 +107,12 @@
101 107 return;
102 108 }
103 109
104 110 $atts = array();
105 - //$set = isset( $args['set']['ID'] ) ? array( 0 => array('ID' => $args['set']['ID'] ) ) : [];
106 - $atts['href'] = $url_manager->getTermUrl( $term->slug, $filter['e_name']/*, $set*/ );
111 + $atts['href'] = flrt_get_filtered_term_url($term, $filter, $url_manager);
107 112
113 + $atts['class'] = 'wpc-filter-link';
114 +
108 115 $attributes = '';
109 116 foreach ( $atts as $attr => $value ) {
110 117 if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
111 118 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
@@ -115,34 +122,88 @@
115 122
116 123 $link = apply_filters( 'wpc_filters_checkbox_term_html', '<a'.$attributes.'>'.$term->name.'</a>', $attributes, $term, $filter );
117 124
118 125 if ( isset( $args['set']['show_count']['value'] ) && $args['set']['show_count']['value'] === 'yes' ) {
119 - $link .= '&nbsp;'. flrt_get_count( $term );
126 + $link .= flrt_filter_get_count( $term );
120 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']);
121 130
122 - $output .= "\t<li";
123 - $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 + }
124 141
125 - $parent_opened_elements_flipped = array_flip( $this->parent_opened_elements );
126 - if( isset( $parent_opened_elements_flipped[$id] ) ){
127 - $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 + }
128 148 }
129 149
130 - if( $this->max_depth > 0) {
131 - $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 + }
132 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 + }
133 164
165 + $output .= "\t<li";
166 + $cross_count = isset( $term->cross_count ) ? esc_attr( $term->cross_count ) : '';
167 +
134 168 $css_classes = array(
135 169 0 => 'wpc-checkbox-item',
136 170 1 => 'wpc-term-item',
137 171 3 => 'wpc-term-count-' . $cross_count,
138 - 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),
139 176 );
140 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 +
141 198 if( $checked ){
142 199 $css_classes[2] = 'wpc-term-selected';
143 200 }
144 201
202 + if( $disabled ){
203 + $css_classes[] = 'wpc-term-disabled';
204 + }
205 +
145 206 if( $this->has_children ){
146 207 $css_classes[] = 'wpc-has-children';
147 208 $toggleButton = '<i class="wpc-toggle-children-list" data-tid="'.esc_attr($term->term_id).'"></i>';
148 209 }
@@ -147,21 +208,23 @@
147 208 $toggleButton = '<i class="wpc-toggle-children-list" data-tid="'.esc_attr($term->term_id).'"></i>';
148 209 }
149 210
150 211 $has_not_empty_children_flipped = array_flip( $this->has_not_empty_children );
151 -// if( in_array( $id, $this->has_not_empty_children ) ){
152 212 if( isset( $has_not_empty_children_flipped[$id] ) ){
153 213 $css_classes[] = 'wpc-has-not-empty-children';
154 214 }
155 215
156 216 $css_classes = implode( ' ', $css_classes );
157 - $css_classes .= $visibility_class;
158 217 $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : '';
159 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 +
160 223 $output .= $css_classes;
161 224 $output .= ' id="'.flrt_term_id('term', $filter, $id, false).'">';
162 - $output .= '<div class="wpc-term-item-content-wrapper'.esc_attr( $visibility_class ).'"><input '.checked( 1, $checked, false ).' type="checkbox" data-wpc-link="'.esc_url($atts['href']).'"';
163 - $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";
164 227 $output .= '<label for="'.flrt_term_id('checkbox', $filter, $id, false).'">';
165 228 $output .= "$link\n";
166 229 $output .= "</label>\n";
167 230 $output .= $toggleButton;
@@ -198,11 +261,28 @@
198 261
199 262 $parent_field = $this->db_fields['parent'];
200 263
201 264 // Flat display.
265 + $flrt_more_less_count = flrt_more_less_count();
266 + $isParentFilter = flrtParentFilter($args[0]['filter']);
267 + $hidden_terms_count = 1;
202 268 if ( -1 == $max_depth ) {
203 269 $empty_array = array();
270 +
204 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 +
205 285 $this->display_element( $e, $empty_array, 1, 0, $args, $output );
206 286 }
207 287 return $output;
208 288 }
@@ -251,8 +331,31 @@
251 331 if ( $root->$parent_field == $e->$parent_field ) {
252 332 $top_level_elements[] = $e;
253 333 } else {
254 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++;
255 358 }
256 359 }
257 360 }
258 361