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 +189 -33 1.5.11.9.7 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 /**
3 3 * The Template for displaying filter dropdown.
4 4 *
5 - * This template can be overridden by copying it to yourtheme/filter/dropdown.php.
5 + * This template can be overridden by copying it to yourtheme/filters/dropdown.php.
6 6 *
7 7 * $set - array, with the Filter Set parameters
8 8 * $filter - array, with the Filter parameters
9 9 * $url_manager - object, of the UrlManager PHP class
@@ -12,50 +12,206 @@
12 12 *
13 13 * @see https://filtereverything.pro/resources/templates-overriding/
14 14 */
15 15
16 -if ( ! defined('WPINC') ) {
17 - wp_die();
16 +if ( ! defined('ABSPATH') ) {
17 + exit;
18 18 }
19 19
20 -// $set_for_urlManager = isset( $set['ID'] ) ? array( array('ID' => $set['ID'] ) ) : [];
21 -$noSelectUrl = ( empty( $filter['values'] ) ) ? $url_manager->getResetUrl() : $url_manager->getTermUrl( reset( $filter['values'] ), $filter['e_name'] /*, $set_for_urlManager*/ );
20 +$noSelectUrl = ( empty( $filter['values'] ) ) ? $url_manager->getResetUrl() : $url_manager->getTermUrl( reset( $filter['values'] ), $filter['e_name'], $filter['entity'] );
21 +$show_term_name = true;
22 +$is_swatch = false;
23 +$is_brand = ( in_array( $filter['e_name'], flrt_brand_filter_entities() ) );
24 +$use_select2 = false;
25 +$data_default = '';
26 +$preload_html = '';
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;
22 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 +
38 +if ( flrt_get_experimental_option( 'select2_dropdowns' ) === 'on' ){
39 + $use_select2 = true;
40 +}
41 +
42 +if ( flrt_get_experimental_option('use_color_swatches') === 'on' ) {
43 + $swatch_taxes = flrt_get_experimental_option( 'color_swatches_taxonomies', [] );
44 + $is_swatch = ( in_array( $filter['e_name'], $swatch_taxes ) );
45 +}
46 +
47 +if ( $is_brand && ! $is_swatch ) {
48 + $data_default = ' data-brand='.FLRT_PLUGIN_DIR_URL.'assets/img/no-image.png';
49 +}
50 +
51 +if ( $is_swatch ){
52 + $data_default = ' data-image='.FLRT_PLUGIN_DIR_URL.'assets/img/no-image.png';
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);
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 +}
23 66 ?>
24 -<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; ?>>
25 68 <?php flrt_filter_header( $filter, $terms ); // Safe, escaped ?>
26 69 <div class="<?php echo esc_attr( flrt_filter_content_class( $filter ) ); ?>">
27 - <?php if( ! empty( $terms ) ): ?>
28 - <select id="wpc-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-<?php echo esc_attr( $filter['ID'] ); ?>" class="wpc-filters-widget-select">
29 - <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
30 - echo esc_html( sprintf( __( '- Select %s -', 'filter-everything' ), $filter['label'] ) );
31 - ?></option><?php
70 + <?php if( ! empty( $terms ) || $view_args['ask_to_select_parent'] ): ?>
71 + <select id="wpc-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-<?php echo esc_attr( $filter['ID'] ); ?>"
72 + aria-label="wpc-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr( $filter['e_name'] ); ?>-<?php echo esc_attr( $filter['ID'] ); ?>"
73 + class="wpc-filters-widget-select" style="width: 100%">
74 + <?php if( $view_args['ask_to_select_parent'] !== false && !$view_args['use_apply_button'] ) : ?>
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
76 + echo esc_html( $view_args['ask_to_select_parent'] );
77 + ?></option>
78 + <?php else: ?>
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 + }?>
32 84
33 - foreach ( $terms as $id => $term_object ){
34 - $selected = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0;
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
35 89
36 - ?><option class="wpc-term-count-<?php echo esc_attr( $term_object->cross_count ); ?> wpc-term-id-<?php echo esc_attr($term_object->term_id); ?>" value="<?php echo esc_attr( $term_object->term_id ); ?>" <?php selected( 1, $selected ); ?> data-wpc-link="<?php echo esc_attr( $url_manager->getTermUrl( $term_object->slug, $filter['e_name'] /*, $set_for_urlManager */ ) ); ?>" id="wpc-option-<?php echo esc_attr( $filter['entity'] ); ?>-<?php echo esc_attr($filter['e_name']); ?>-<?php echo esc_attr( $id ); ?>"><?php
37 - echo esc_html( $term_object->name );
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 = '';
38 98
39 - if( $set['show_count']['value'] === 'yes' ) {
40 - echo esc_html( ' ('.$term_object->cross_count.')' );
99 + if( isset( $term_object->wp_queried ) && $term_object->wp_queried ){
100 + $disabled = 1;
101 + }
102 +
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 + }
113 + }
114 +
115 + if ( $is_swatch ) {
116 + $src = flrt_get_term_swatch_image( $term_object->term_id, $filter );
117 +
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";
121 + } else {
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 + }
128 + }
129 +
130 + if ( $filter['show_term_names'] === 'no' ) {
131 + $term_hidden_class = ' wpc-hidden-term-name';
132 + }
133 + }
134 +
135 + if( $set['show_count']['value'] === 'yes' && $use_select2 ) {
136 + $data_count = ' data-count="' . esc_attr( $term_object->cross_count ) . '"';
137 + }
138 +
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 + }
149 +
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 . '"';
158 + }
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++;
41 192 }
42 - ?></option>
43 - <?php } ?><!-- end foreach -->
44 - </select>
45 - <?php else:
193 + echo $rating_html;
194 + }else{
195 + echo sprintf(
196 + _n('%d star', '%d stars', $rating, 'filter-everything'),
197 + $rating
198 + );
199 + }
200 + }else{
201 + echo esc_html( $term_object->name );
202 + }
46 203
47 - if( ! flrt_is_filter_request() ){
48 - ?><p><?php esc_html_e('There are no terms yet', 'filter-everything' );
204 + if( $set['show_count']['value'] === 'yes' && ! $use_select2 ) {
205 + echo esc_html( ' ('.$term_object->cross_count.')' );
206 + }
207 + ?></option>
208 + <?php } ?><!-- end foreach -->
49 209
50 - if( flrt_is_debug_mode() ){
51 - echo '&nbsp;'.flrt_help_tip(
52 - esc_html__('Possible reasons: 1) Filter\'s criteria doesn\'t contain any terms yet and you have to add them 2) Terms may be created, but no one post that should be filtered attached to these terms 3) You excluded all possible terms in Filter\'s options.', 'filter-everything')
53 - );
54 - }
55 - }else{
56 - esc_html_e('N/A', 'filter-everything' );
57 - }
58 - ?></p>
59 - <?php endif; ?><!-- end if -->
210 + <?php endif; ?>
211 + </select>
212 + <?php echo $preload_html; ?>
213 + <?php else:
214 + flrt_filter_no_terms_message( 'p' );
215 + endif; ?>
60 216 </div>
61 217 </div>