| @@ -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,117 +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 | - $data_color = ''; | |
| 68 | - $selected = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0; | |
| 69 | - $term_hidden_class = ''; | |
| 70 | - $data_count = ''; | |
| 71 | - $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 | |
| 72 | 89 | |
| 73 | - if( isset( $term_object->wp_queried ) && $term_object->wp_queried ){ | |
| 74 | - $disabled = 1; | |
| 75 | - } | |
| 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 = ''; | |
| 76 | 98 | |
| 77 | - if ( $is_brand && ! $is_swatch ) { | |
| 78 | - $src = flrt_get_term_brand_image( $term_object->term_id, $filter ); | |
| 79 | - if ( $src ) { | |
| 80 | - $data_image = ' data-brand="' . esc_url( $src ) . '"'; | |
| 81 | - $preload_html .= '<img class="wpc-preload-img" src="'. esc_url( $src ) .'" />'."\r\n"; | |
| 99 | + if( isset( $term_object->wp_queried ) && $term_object->wp_queried ){ | |
| 100 | + $disabled = 1; | |
| 82 | 101 | } |
| 83 | 102 | |
| 84 | - if ( $filter['show_term_names'] === 'no' ) { | |
| 85 | - $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 | + } | |
| 86 | 113 | } |
| 87 | - } | |
| 88 | 114 | |
| 89 | - if ( $is_swatch ) { | |
| 90 | - $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 ); | |
| 91 | 117 | |
| 92 | - if ( $src ) { | |
| 93 | - $data_image = ' data-image="' . esc_url( $src ) . '"'; | |
| 94 | - $preload_html .= '<img class="wpc-preload-img" src="'. esc_url( $src ) .'" />'."\r\n"; | |
| 95 | - } else { | |
| 96 | - $maybe_color = flrt_get_term_swatch_color( $term_object->term_id, $filter ); | |
| 97 | - if ( $maybe_color ) { | |
| 98 | - $data_color = ' data-color="' . esc_attr( $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"; | |
| 99 | 121 | } else { |
| 100 | - $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 | + } | |
| 101 | 128 | } |
| 129 | + | |
| 130 | + if ( $filter['show_term_names'] === 'no' ) { | |
| 131 | + $term_hidden_class = ' wpc-hidden-term-name'; | |
| 132 | + } | |
| 102 | 133 | } |
| 103 | 134 | |
| 104 | - if ( $filter['show_term_names'] === 'no' ) { | |
| 105 | - $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 ) . '"'; | |
| 106 | 137 | } |
| 107 | - } | |
| 108 | 138 | |
| 109 | - if( $set['show_count']['value'] === 'yes' && $use_select2 ) { | |
| 110 | - $data_count = ' data-count="' . esc_attr( $term_object->cross_count ) . '"'; | |
| 111 | - } | |
| 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 | + } | |
| 112 | 149 | |
| 113 | - $rating = 0; | |
| 114 | - if( mb_strpos( $term_object->slug, 'rated-' ) !== false){ | |
| 115 | - $pieces = explode("-", $term_object->slug); | |
| 116 | - $rating = (int) isset( $pieces[1] ) ? $pieces[1] : 0; | |
| 117 | - if ($rating < 1 || $rating > 5) { | |
| 118 | - $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 . '"'; | |
| 119 | 158 | } |
| 120 | - $data_rating = ' data-star-rating="' . (int) $rating . '"'; | |
| 121 | - } | |
| 122 | - ?> | |
| 123 | - <option<?php echo $data_image . $data_color . $data_count . $data_rating; // data-* values are esc_attr/esc_url-escaped and quoted above ?> 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 ); ?>"> | |
| 124 | - <?php | |
| 125 | - if ($rating > 0){ | |
| 126 | - if($use_select2){ | |
| 127 | - $rating_html = ''; | |
| 128 | - $i = 1; | |
| 129 | - $label_star = '<span class="flrt-star-label %s">' . flrt_rating_star() . '</span>'; | |
| 130 | - while($i <=5){ | |
| 131 | - $star_class = ''; | |
| 132 | - if($i <= $rating){ | |
| 133 | - $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++; | |
| 134 | 192 | } |
| 135 | - $rating_html .= sprintf($label_star, $star_class); | |
| 136 | - $i++; | |
| 193 | + echo $rating_html; | |
| 194 | + }else{ | |
| 195 | + echo sprintf( | |
| 196 | + _n('%d star', '%d stars', $rating, 'filter-everything'), | |
| 197 | + $rating | |
| 198 | + ); | |
| 137 | 199 | } |
| 138 | - echo $rating_html; | |
| 139 | 200 | }else{ |
| 140 | - echo sprintf( | |
| 141 | - _n('%d star', '%d stars', $rating, 'filter-everything'), | |
| 142 | - $rating | |
| 143 | - ); | |
| 201 | + echo esc_html( $term_object->name ); | |
| 144 | 202 | } |
| 145 | - }else{ | |
| 146 | - echo esc_html( $term_object->name ); | |
| 147 | - } | |
| 148 | 203 | |
| 149 | - if( $set['show_count']['value'] === 'yes' && ! $use_select2 ) { | |
| 150 | - echo esc_html( ' ('.$term_object->cross_count.')' ); | |
| 151 | - } | |
| 152 | - ?></option> | |
| 153 | - <?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 | + | |
| 154 | 210 | <?php endif; ?> |
| 155 | 211 | </select> |
| 156 | 212 | <?php echo $preload_html; ?> |
| 157 | 213 | <?php else: |