| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * The Template for displaying filter radio buttons. |
| 4 | 4 | * |
| 5 | - * This template can be overridden by copying it to yourtheme/filter/radio.php | |
| 5 | + * This template can be overridden by copying it to yourtheme/filters/radio.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 |
| @@ -11,38 +11,100 @@ | ||
| 11 | 11 | * |
| 12 | 12 | * @see https://filtereverything.pro/resources/templates-overriding/ |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -if ( ! defined('WPINC') ) { | |
| 16 | - wp_die(); | |
| 15 | +if ( ! defined('ABSPATH') ) { | |
| 16 | + exit; | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | +$args = [ | |
| 20 | + 'hide' => $view_args['ask_to_select_parent'], | |
| 21 | + 'use_apply_button' => $view_args['use_apply_button'], | |
| 22 | + 'hide_empty' => $set['hide_empty']['value'], | |
| 23 | + 'hide_empty_filter' => isset($set['hide_empty_filter']['value']) ? $set['hide_empty_filter']['value'] : '', | |
| 24 | +]; | |
| 25 | +$rating_slugs = flrt_rating_slugs(); | |
| 26 | +$hide_for_apply_button_mode = flrt_check_apply_buttom_mode($set); | |
| 27 | +$is_hide_empty_terms = (isset($set['hide_empty']['value']) && $set['hide_empty']['value'] === 'yes'); | |
| 28 | +$parent_filter_apply_button_data = flrt_parent_filter_apply_button_data($filter, $view_args); | |
| 29 | +$parent_filter_apply_class = flrt_parent_filter_apply_class($filter, $view_args, $terms); | |
| 30 | +$isMoreLess = flrtIsMoreLess($filter); | |
| 31 | +$flrt_more_less_count = flrt_more_less_count(); | |
| 32 | +$isParentFilter = flrtParentFilter($filter); | |
| 19 | 33 | ?> |
| 20 | -<div class="<?php echo flrt_filter_class( $filter ); // Already escaped ?>" data-fid="<?php echo esc_attr( $filter['ID'] ); ?>"> | |
| 34 | +<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; ?>> | |
| 21 | 35 | <?php flrt_filter_header( $filter, $terms ); // Safe, escaped ?> |
| 22 | 36 | <div class="<?php echo esc_attr( flrt_filter_content_class( $filter ) ); ?>"> |
| 23 | - <?php if( $filter['search'] === 'yes' ): ?> | |
| 24 | - <div class="wpc-filter-search-wrapper wpc-filter-search-wrapper-<?php echo esc_attr( $filter['ID'] ); ?>"> | |
| 25 | - <input class="wpc-filter-search-field" type="text" value="" placeholder="<?php esc_html_e('Search', 'filter-everything' ) ?>" /> | |
| 26 | - <button class="wpc-search-clear" type="button" title="<?php esc_html_e('Clear search', 'filter-everything' ) ?>"><span class="wpc-search-clear-icon">×</span></button> | |
| 27 | - </div> | |
| 28 | - <?php endif; ?> | |
| 37 | + <?php flrt_filter_search_field( $filter, $view_args, $terms ); ?> | |
| 29 | 38 | <ul class="wpc-filters-ul-list wpc-filters-radio wpc-filters-list-<?php echo esc_attr( $filter['ID'] ); ?>"> |
| 30 | - <?php if( ! empty( $terms ) ): | |
| 31 | - // $set_for_urlManager = isset( $set['ID'] ) ? array( array('ID' => $set['ID'] ) ) : []; | |
| 32 | - ?> | |
| 39 | + <?php if( ! empty( $terms ) || $view_args['ask_to_select_parent'] ): | |
| 40 | + if( $view_args['ask_to_select_parent'] !== false && !$view_args['use_apply_button']) { ?> | |
| 41 | + <li class="wpc-ask-to-parent-display"><?php echo esc_html( $view_args['ask_to_select_parent'] ); ?></li> | |
| 42 | + <?php } else { | |
| 43 | + if( $view_args['ask_to_select_parent'] !== false && $view_args['use_apply_button'] ) { ?> | |
| 44 | + <li class="wpc-ask-to-parent-display"><?php echo esc_html( $view_args['ask_to_select_parent'] ); ?></li> | |
| 45 | + <?php } | |
| 46 | + $hidden_terms_count = 1; | |
| 47 | + foreach ( $terms as $id => $term_object ) { | |
| 48 | + $disabled = 0; | |
| 49 | + $checked = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0; | |
| 50 | + if ( isset( $term_object->wp_queried ) && $term_object->wp_queried ) { | |
| 51 | + $checked = 1; | |
| 52 | + $disabled = 1; | |
| 53 | + } | |
| 33 | 54 | |
| 34 | - <?php foreach ( $terms as $id => $term_object ){ | |
| 55 | + $active_class = $checked ? ' wpc-term-selected' : ''; | |
| 56 | + $disabled_class = $disabled ? ' wpc-term-disabled' : ''; | |
| 57 | + $link = flrt_get_filtered_term_url($term_object, $filter, $url_manager); | |
| 58 | + $link_attributes = 'href="'.esc_url($link).'"'; | |
| 59 | + $link_attributes .= ' class="wpc-filter-link"'; | |
| 60 | + $name = ( $disabled > 0 ) ? $filter['e_name'] . '-disabled' : $filter['e_name']; | |
| 61 | + $rating_data = (isset($rating_slugs[$term_object->slug])) ? ' data-rating-num="' . esc_attr($rating_slugs[$term_object->slug]) . '" ' : ''; | |
| 62 | + $hidden_class_for_apply_button_mode = ''; | |
| 63 | + if($hide_for_apply_button_mode){ | |
| 64 | + $hidden_class_for_apply_button_mode = ($term_object->cross_count <= 0 && $is_hide_empty_terms) ? esc_attr(' wpc-term-count-hidden-0') : ''; | |
| 65 | + if($term_object->cross_count > 0){ | |
| 66 | + $hidden_class_for_apply_button_mode .= esc_attr(' wpc-has-terms'); | |
| 67 | + } | |
| 68 | + if($checked){ | |
| 69 | + $hidden_class_for_apply_button_mode .= esc_attr(' wpc-term-count-hidden-checked-0'); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + $checked_data = ($checked) ? ' data-wpc-was-checked=true' : ' data-wpc-was-checked=false'; | |
| 73 | + $show_with_parent_class = ''; | |
| 74 | + if (isset($term_object->show_with_parent)) { | |
| 75 | + if ($term_object->show_with_parent === true) { | |
| 76 | + $show_with_parent_class = ' wpc-show-with-parent-true'; | |
| 77 | + } else { | |
| 78 | + $show_with_parent_class = ' wpc-show-with-parent-false'; | |
| 79 | + } | |
| 80 | + } | |
| 35 | 81 | |
| 36 | - $checked = ( in_array( $term_object->slug, $filter['values'] ) ) ? 1 : 0; | |
| 37 | - $active_class = $checked ? ' wpc-term-selected' : ''; | |
| 38 | - $link = $url_manager->getTermUrl( $term_object->slug, $filter['e_name'] /*, $set_for_urlManager */ ); | |
| 39 | - $link_attributes = 'href="'.esc_url($link).'"'; | |
| 82 | + if (!isset($term_object->show_with_parent)) { | |
| 83 | + if ($view_args['ask_to_select_parent'] !== false && $view_args['use_apply_button']) { | |
| 84 | + if ((!$checked)) { | |
| 85 | + $show_with_parent_class = ' wpc-show-with-parent-false'; | |
| 86 | + } | |
| 87 | + } | |
| 88 | + } | |
| 89 | + $more_less_hidden_class = ''; | |
| 90 | + if ( $isMoreLess ) { | |
| 91 | + $is_visible = ! $isParentFilter || ( isset( $term_object->show_with_parent ) && $term_object->show_with_parent === true ) || !isset( $term_object->show_with_parent ); | |
| 92 | + $has_results = ! $is_hide_empty_terms || $term_object->cross_count > 0; | |
| 93 | + | |
| 94 | + if ( $is_visible && $has_results ) { | |
| 95 | + if ( $hidden_terms_count <= $flrt_more_less_count ) { | |
| 96 | + $more_less_hidden_class = ' wpc-not-hidden-term'; | |
| 97 | + } | |
| 98 | + $hidden_terms_count++; | |
| 99 | + } | |
| 100 | + } | |
| 40 | 101 | ?> |
| 41 | - <li class="wpc-radio-item wpc-term-item<?php echo esc_attr( $active_class ); ?> wpc-term-count-<?php echo esc_attr( $term_object->cross_count ); ?> wpc-term-id-<?php echo esc_attr($id); ?>" id="<?php flrt_term_id('term', $filter, $id); ?>"> | |
| 102 | + <li class="wpc-radio-item wpc-term-item<?php echo esc_attr( $active_class ); ?><?php echo esc_attr( $disabled_class ); ?> wpc-term-count-<?php echo esc_attr( $term_object->cross_count ); ?> wpc-term-id-<?php echo esc_attr($id); ?><?php echo $hidden_class_for_apply_button_mode; ?><?php echo esc_attr($show_with_parent_class); ?><?php echo esc_attr( $more_less_hidden_class ); ?>" id="<?php flrt_term_id('term', $filter, $id); ?>"> | |
| 42 | 103 | <div class="wpc-term-item-content-wrapper"> |
| 43 | - <input <?php checked( 1, $checked ); ?> type="radio" data-wpc-link="<?php echo esc_url( $link ); ?>" name="<?php echo esc_attr($filter['e_name']); ?>" id="<?php flrt_term_id('radio', $filter, $id); ?>"/> | |
| 44 | - <label for="<?php flrt_term_id('radio', $filter, $id); ?>"><?php | |
| 104 | + <input <?php checked( 1, $checked ); disabled( 1, $disabled ) ?> type="radio" data-wpc-link="<?php echo esc_url( $link ); ?>" name="<?php echo esc_attr( $name ); ?>" id="<?php flrt_term_id('radio', $filter, $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;?><?php echo esc_attr($checked_data);?> /> | |
| 105 | + <label for="<?php flrt_term_id('radio', $filter, $id); ?>"> | |
| 106 | + <?php | |
| 45 | 107 | |
| 46 | 108 | /** |
| 47 | 109 | * Allow developers to change filter terms html |
| 48 | 110 | */ |
| @@ -47,28 +109,14 @@ | ||
| 47 | 109 | * Allow developers to change filter terms html |
| 48 | 110 | */ |
| 49 | 111 | echo apply_filters( 'wpc_filters_radio_term_html', '<a '.$link_attributes.'>'.$term_object->name.'</a>', $link_attributes, $term_object, $filter ); |
| 50 | 112 | |
| 51 | - ?> <?php flrt_count( $term_object, $set['show_count']['value'] ); ?> | |
| 52 | - </label> | |
| 53 | - </div> | |
| 54 | - </li> | |
| 55 | - <?php } ?><!-- end foreach --> | |
| 56 | - | |
| 113 | + ?><?php flrt_filter_count( $term_object, $set['show_count']['value'] ); ?></label></div></li> | |
| 114 | + <?php } /* end foreach */ ?> | |
| 115 | + <?php } /* end if ask to select parent */ ?> | |
| 57 | 116 | <?php else: |
| 58 | - if( ! flrt_is_filter_request() ){ | |
| 59 | - ?> | |
| 60 | - <li><?php esc_html_e('There are no terms yet', 'filter-everything' ); | |
| 61 | - if( flrt_is_debug_mode() ){ | |
| 62 | - echo ' '.flrt_help_tip( | |
| 63 | - 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') | |
| 64 | - ); | |
| 65 | - } | |
| 66 | - ?></li> | |
| 67 | - <?php }else{ | |
| 68 | - esc_html_e('N/A', 'filter-everything' ); | |
| 69 | - } | |
| 70 | - | |
| 71 | - endif; ?><!-- end if --> | |
| 72 | - </ul> | |
| 117 | + flrt_filter_no_terms_message(); | |
| 118 | + endif; | |
| 119 | +?> </ul> | |
| 120 | + <?php flrt_filter_more_less( $filter ); ?> | |
| 73 | 121 | </div> |
| 74 | 122 | </div> |