PluginProbe
Filter Everything — WordPress & WooCommerce Filters / 1.9.2.1
Filter Everything — WordPress & WooCommerce Filters v1.9.2.1
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
filter-everything / src / Admin / Widgets / FiltersWidget.php

FiltersWidget.php in Filter Everything — WordPress & WooCommerce Filters 1.9.2.1, at src/Admin/Widgets/FiltersWidget.php

667 lines 30.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FilterEverything\Filter;
4
5 if ( ! defined('ABSPATH') ) {
6 exit;
7 }
8
9 class FiltersWidget extends \WP_Widget
10 {
11 public $show_instance_in_rest = false;
12
13 public function __construct() {
14 parent::__construct(
15 'wpc_filters_widget', // Base ID
16 esc_html__( 'Filter Everything &mdash; Filters', 'filter-everything'),
17 array(
18 'description' => esc_html__( 'Displays filters', 'filter-everything' ),
19 'show_instance_in_rest' => false,
20 )
21 );
22 }
23
24 /**
25 * Outputs the content for the current Filters widget instance.
26 * @since 1.0.0
27 * @param array $args Display arguments including 'before_title', 'after_title',
28 * 'before_widget', and 'after_widget'.
29 * @param array $instance Settings for the current Filters widget instance.
30 */
31 public function widget( $args, $instance ) {
32 if ( is_array( $args ) ){
33 extract( $args );
34 }
35
36 $title = isset( $instance['title'] ) ? $instance['title'] : '';
37 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
38 $show_selected_class = ( !empty( $instance['chips'] ) ) ? ' wpc-show-on-desktop' : '';
39 $show_count = ( !empty( $instance['show_count'] ) ) ? $instance['show_count'] : '';
40 $horizontal = ( !empty( $instance['horizontal'] ) ) ? $instance['horizontal'] : '';
41 $cols_count = ( isset( $instance['cols_count'] ) && $instance['cols_count'] > 0 ) ? $instance['cols_count'] : 3;
42
43 $set_id = isset( $instance['id'] ) ? preg_replace('/[^\d]?/', '', $instance['id'] ) : 0;
44 $popup_title = esc_html__('Filters', 'filter-everything');
45
46 if ( ! empty( $title ) ) {
47 $popup_title = $title;
48 }
49
50 // Display nothing in Page Builders preview mode
51 if( isset( $_GET['legacy-widget-preview'] ) || isset( $_GET['_locale'] ) ){
52 return;
53 }
54
55 if( isset( $_POST['action'] ) && $_POST['action'] === 'elementor_ajax' ){
56 echo '<strong>'.esc_html__( 'Filter Everything &mdash; Filters', 'filter-everything' ).'</strong>';
57 return;
58 }
59
60 if( isset( $_GET['action'] ) && $_GET['action'] === 'elementor' ){
61 echo '<strong>'.esc_html__( 'Filter Everything &mdash; Filters', 'filter-everything' ).'</strong>';
62 return;
63 }
64
65 /**
66 * Fires before current widget output
67 */
68 do_action( 'wpc_before_filters_widget', $args, $instance );
69
70 /**
71 * @feature Add ability to choose what filter Set to display in widget settings
72 */
73 $debug_mode = flrt_is_debug_mode();
74 $container = Container::instance();
75 $wpManager = $container->getWpManager();
76 $fss = $container->getFilterSetService();
77
78 /**
79 * Display debug messages in case if the current page has not Filter Set
80 */
81 if( empty( $wpManager->getQueryVar('wpc_page_related_set_ids') ) ){
82 $under_limit_filter_set = $fss->under_limit_filter_set($set_id);
83 if( $debug_mode ){
84 $this->_debug_messages($under_limit_filter_set);
85 }
86 return false;
87 }
88
89 $templateManager = $container->getTemplateManager();
90 $em = $container->getEntityManager();
91 $urlManager = Container::instance()->getUrlManager();
92
93 $has_not_empty_children = [];
94 $theSet = flrt_the_set( $set_id );
95
96 // Display or not Filter Set in dependency from the Apply button configuration
97 if( isset( $theSet['show_on_the_page'] ) && ! $theSet['show_on_the_page'] ){
98 $theSet = flrt_the_set( $set_id );
99 }
100
101 if( ! $theSet ){
102 return false;
103 }
104
105 $setId = $theSet['ID'];
106 $posType = $theSet['filtered_post_type'];
107 $set = $fss->getSet( $theSet['ID'] );
108
109 $chipsObj = new Chips(true, array($setId) );
110 $chips = $chipsObj->getChips();
111
112 $set_edit_url = ( isset( $theSet['ID'] )) ? admin_url('post.php?post='.$theSet['ID'].'&action=edit') : admin_url( 'edit.php?post_type=filter-set' );
113
114 $related_filters = $em->getSetsRelatedFilters( array( $theSet ) );
115 $found_posts = flrt_posts_found_quantity( $setId, true );
116 $actionUrl = $urlManager->getFormActionOrFullPageUrl(true);
117 $view_args = [ 'ask_to_select_parent' => false ];
118
119 // Apply button preparations
120 $filters_counter = 0;
121 $use_apply_button = ( isset( $set['use_apply_button']['value'] ) && $set['use_apply_button']['value'] === 'yes' );
122 $use_search_field = ( isset( $set['use_search_field']['value'] ) && $set['use_search_field']['value'] === 'yes' );
123 $apply_button_menu_order = isset( $set['apply_button_menu_order']['value'] ) ? (int) $set['apply_button_menu_order']['value'] : -1;
124 $search_field_menu_order = isset( $set['search_field_menu_order']['value'] ) ? (int) $set['search_field_menu_order']['value'] : -1;
125
126 $has_not_empty_children_flipped = [];
127 $wrapper_class = '';
128 if ( flrt_is_filter_request() ) {
129 $wrapper_class = ' wpc-filter-request';
130 }
131
132 if (isset($set['horizontal_view_priority']['value']) && $set['horizontal_view_priority']['value'] === 'filter_set') {
133
134 if (isset($set['horizontal_view']['value'])) {
135 $horizontal = ( $set['horizontal_view']['value'] === 'yes') ? true : false;
136 if ( $horizontal ) {
137 $cols_count = ( isset( $set['horizontal_view_column']['value'] ) && $set['horizontal_view_column']['value'] > 0 ) ? $set['horizontal_view_column']['value'] : 3;
138 }
139 }
140 }
141
142 if ( $horizontal ) {
143 $wrapper_class .= ' wpc-horizontal-layout';
144 $wrapper_class .= ' wpc-horizontal-cols-' . $cols_count;
145 }
146
147 if ( $use_apply_button ) {
148
149 $base_permalink = '';
150
151 if ( defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO ) {
152 $base_permalink = flrt_get_location_permalink( $set );
153 }
154
155 $apply_url = $urlManager->getTermUrl( '', '', '', $base_permalink );
156 $reset_url = $urlManager->getResetUrl();
157 }
158
159 do_action( 'wpc_before_display_filters_widget', $setId, $args, $instance );
160
161 if ( empty( $related_filters ) && ! $use_search_field ) {
162 if ( $debug_mode ) {
163
164 echo '<p class="wpc-debug-message">';
165 echo sprintf(
166 wp_kses(
167 __( 'There are no filters in the Filter Set yet. Please add them to the <a href="%s">Filter Set</a> related to this page.', 'filter-everything' ),
168 array( 'a' => array('href' => true) )
169 ),
170 $set_edit_url
171 );
172 echo '</p>';
173
174 flrt_debug_title();
175 }
176 return false;
177 }
178
179 echo $before_widget;
180 echo '<div class="wpc-filters-main-wrap wpc-filter-set-'.esc_attr( $setId ).$wrapper_class.'" data-set="'.esc_attr( $setId ).'">'."\n";
181 // Open/Closed status class
182 $widgetContentClass = flrt_filters_widget_content_class($setId);
183 $widgetContentClass .= ' wpc-show-counts-' . $set['show_count']['value'];
184
185 if ( flrt_get_experimental_option('disable_buttons') !== 'on' ) {
186 flrt_filters_button( $setId, $widgetContentClass );
187 }
188
189 if ( $use_apply_button ) {
190 $widgetContentClass .= ( $theSet['query_on_the_page'] ) ? ' wpc-query-on-the-page' : ' wpc-query-not-on-the-page';
191 }
192
193 echo flrt_spinner_html();
194
195 echo '<div class="wpc-filters-widget-content'.esc_attr($widgetContentClass).'">';
196 echo '<div class="wpc-widget-close-container">
197 <a class="wpc-widget-close-icon">
198 <span class="wpc-icon-html-wrapper">
199 <span class="wpc-icon-line-1"></span><span class="wpc-icon-line-2"></span><span class="wpc-icon-line-3"></span>
200 </span>
201 </a>';
202
203 echo '<span class="wpc-widget-popup-title">'.$popup_title.'</span>';
204 echo '</div>';
205 echo '<div class="wpc-filters-widget-containers-wrapper">'."\r\n";
206
207 do_action( 'wpc_before_mobile_filters_widget', $setId, $args, $instance );
208
209 echo '<div class="wpc-filters-widget-top-container'.esc_attr($show_selected_class).'">';
210 echo '<div class="wpc-widget-top-inside">';
211
212 // Add selected terms for mobile widget
213 echo '<div class="wpc-inner-widget-chips-wrapper">';
214 $templateManager->includeFrontView( 'chips', array( 'chips' => $chips, 'setid' => $setId ) );
215 echo '</div>';
216
217 echo '</div>';
218 echo '</div>';
219
220 if ( ! empty( $title ) ) {
221 echo '<div class="wpc-filter-set-widget-title">'."\n";
222 echo $before_title . $title . $after_title;
223 echo '</div>'."\n";
224 }
225
226 echo '<div class="wpc-filters-scroll-container">';
227 echo '<div class="wpc-filters-widget-wrapper">'."\r\n";
228
229 if( $show_count ){
230 flrt_posts_found( $setId );
231 } else {
232 flrt_posts_found( $setId, false, true );
233 }
234
235 $to = count( $related_filters );
236 if ( $use_apply_button ) {
237 $to += 2;
238 }
239 if ( $use_search_field ) {
240 $to += 2;
241 }
242
243 // Add Search field and Apply Button to the array if they enabled
244 //@todo if Filter Set in Free version contains filter for PRO counters are incorrect (-1 from filters count)
245 // and that's why Apply button or Search field on the last position(s) may not appear
246 $filters_and_fields = [];
247 $related_filters = array_reverse( $related_filters, true );
248 $search_field_displayed = false;
249 $apply_button_displayed = false;
250
251 for ( $i = 1; $i <= $to; $i++ ) {
252 if ( $use_apply_button && $apply_button_menu_order === $i ) {
253 $filters_and_fields[-1] = array();
254 } else if ( $use_search_field && $search_field_menu_order === $i ) {
255 $filters_and_fields[-2] = array();
256 } else {
257 // To avoid "empty" filter
258 if ( ! empty( $related_filters ) ) {
259 $key = array_key_last($related_filters);
260 $value = array_pop($related_filters);
261 $filters_and_fields[$key] = $value;
262 }
263 }
264 }
265
266 foreach ( $filters_and_fields as $filter_id => $filter ){
267 $filters_counter++;
268
269 $is_rating = (isset($filter['view']) && $filter['view'] === 'rating' && $filter['e_name'] === 'product_visibility' ) ? true : false;
270 if ( $filter_id > 0 ) {
271 /**
272 * Allows the developer to modify a filter before output.
273 */
274 $filter = apply_filters('wpc_filter_options_before_display', $filter, $set);
275
276 $terms = flrt_get_filter_terms( $filter, $posType, $em );
277
278 // Collect terms for a parent filter, if exists
279 if ( $filter['parent_filter'] > 0) {
280 // Here we have to calculate all related with the parent filter
281 $parent_filter_id = (int)$filter['parent_filter'];
282 if ( isset( $filters_and_fields[$parent_filter_id] ) ) {
283 $parent_filter = $filters_and_fields[$parent_filter_id];
284
285 $parent_filter_terms = flrt_get_filter_terms( $parent_filter, $posType, $em );
286 $wp_queried_term = flrt_get_wp_queried_term( $parent_filter_terms );
287
288 if ( $wp_queried_term ) {
289 $parent_filter['values'][] = $wp_queried_term->slug;
290 }
291
292 if ( empty( $parent_filter['values'] ) ) {
293
294 // Do not show this filter, until parent is selected
295 if ( $filter['hide_until_parent'] === 'yes' && empty( $filter['values'] ) ) {
296 continue;
297 }
298
299 if ( ! empty( $filter['values'] ) ) {
300 $actual_filter_terms = [];
301 $filter_values_flipped = array_flip( $filter['values'] );
302 foreach ( $terms as $single_term ) {
303 if(!$is_rating) {
304 if (isset($filter_values_flipped[$single_term->slug])) {
305 $actual_filter_terms[] = $single_term;
306 }
307 }else{
308 $actual_filter_terms[] = $single_term;
309 }
310 }
311 $terms = $actual_filter_terms;
312 } else {
313 if( isset( $parent_filter['label'] ) && $parent_filter['label'] ) {
314 $view_args['ask_to_select_parent'] = sprintf( esc_html__('Select %s first', 'filter-everything'), $parent_filter['label'] );
315 } else {
316 $view_args['ask_to_select_parent'] = esc_html__('First, select another filter', 'filter-everything');
317 }
318 }
319
320 // Here we have to setup signal that forces message "Select parent first"
321 } else {
322 if ( ! in_array( $filter['entity'], ['post_meta_num', 'tax_numeric'] ) ) {
323 // Selected values are term slugs
324 $actual_parent_filter_posts = [];
325 $parent_filter_values_flipped = array_flip( $parent_filter['values'] );
326
327 foreach ( $parent_filter_terms as $parent_filter_term ) {
328 if ( isset( $parent_filter_values_flipped[$parent_filter_term->slug] ) ) {
329 $actual_parent_filter_posts = array_merge($actual_parent_filter_posts, $parent_filter_term->posts);
330 }
331 }
332 $actual_filter_terms = [];
333 // if ! empty( $filter['values'] )
334 foreach ($terms as $single_term) {
335 if(!$is_rating){
336 $current_intersection = array_intersect($actual_parent_filter_posts, $single_term->posts);
337 if (!empty($current_intersection)) {
338 $actual_filter_terms[] = $single_term;
339 }
340 }else{
341 $actual_filter_terms[] = $single_term;
342 }
343 }
344
345 $terms = $actual_filter_terms;
346 }
347 }
348 }
349 } else {
350 $view_args['ask_to_select_parent'] = false;
351 }
352
353 if ( $filter['hierarchy'] === 'yes' ) {
354 $hierarchy_key = 'cross_count';
355 if ($set['hide_empty']['value'] === 'initial') {
356 $hierarchy_key = 'count';
357 }
358
359 $has_not_empty_children = flrt_get_parents_with_not_empty_children($terms, $hierarchy_key);
360 $has_not_empty_children_flipped = array_flip($has_not_empty_children);
361 }
362
363 // Create a list with excluded empty terms
364 if (($set['hide_empty']['value'] === 'yes') || ($set['hide_empty']['value'] === 'initial') || (isset($set['hide_empty_filter']) && $set['hide_empty_filter']['value'] === 'yes')) {
365 $allWpQueriedPostIds = $em->getAllSetWpQueriedPostIds($setId);
366 $allWpQueriedPostIds_flipped = array_flip($allWpQueriedPostIds);
367 $checkTerms = $terms;
368
369 if(!$is_rating) {
370 if ($set['hide_empty']['value'] === 'initial') {
371 foreach ($checkTerms as $index => $term) {
372 if ($filter['hierarchy'] === 'yes') {
373
374 $intersection = false;
375 foreach ($term->posts as $post_id) {
376 if (isset($allWpQueriedPostIds_flipped[$post_id])) {
377 $intersection = true;
378 break;
379 }
380 }
381
382 if (!$intersection && !isset($has_not_empty_children_flipped[$term->term_id])) {
383 unset($checkTerms[$index]);
384 }
385
386 } else {
387
388 $intersection = false;
389 foreach ($term->posts as $post_id) {
390 if (isset($allWpQueriedPostIds_flipped[$post_id])) {
391 $intersection = true;
392 break;
393 }
394 }
395
396 if (!$intersection) {
397 unset($checkTerms[$index]);
398 }
399 }
400 }
401 } else {
402 $checkTerms = flrt_remove_empty_terms($terms, $filter, $has_not_empty_children_flipped);
403 }
404 }
405 }
406
407 // Remove empty terms, if such option is enabled
408 if (
409 ($set['hide_empty']['value'] === 'yes' || $set['hide_empty']['value'] === 'initial')
410 &&
411 ! in_array( $filter['entity'], ['post_meta_num', 'tax_numeric', 'post_date', 'post_meta_date'] )
412 ) {
413 $terms = $checkTerms;
414 }
415 /**
416 * @todo we have to check this for Dates and consider if we need to hide
417 * filter by dates at all
418 */
419 // Hide entire Filter if there are no posts in its terms
420 if ( isset( $set['hide_empty_filter'] )
421 &&
422 $set['hide_empty_filter']['value'] === 'yes') {
423
424 if ( in_array( $filter['entity'], ['post_meta_num', 'tax_numeric'] ) ) {
425 // Temporary not ideal solution
426 // Sometimes it is $terms[0] sometimes $terms['max']
427 if (isset($terms[0])) {
428 if ((int)$terms[0]->max === 0 && (int)$terms[1]->min === 0) {
429 // Huh, finally
430 continue;
431 }
432 }
433
434 if (isset($terms['min'])) {
435 if ((int)$terms['max']->max === 0 && (int)$terms['min']->min === 0) {
436 // Huh, finally
437 continue;
438 }
439 }
440
441 } else if ( in_array( $filter['entity'], ['post_date', 'post_meta_date'] ) ) {
442 if ( $found_posts < 1 ) {
443 // Huh, finally
444 continue;
445 }
446 } else {
447 $checkTerms = flrt_remove_empty_terms($terms, $filter, $has_not_empty_children_flipped);
448 if (empty($checkTerms)) {
449 // Huh, finally
450 continue;
451 }
452 }
453 }
454 /**
455 * Extract only needed values without extra fields
456 */
457 $terms = flrt_extract_objects_vars( $terms, array(
458 'term_id',
459 'slug',
460 'name',
461 'count',
462 'cross_count',
463 'max',
464 'min',
465 'from',
466 'to',
467 'time_to',
468 'time_from',
469 'parent',
470 'wp_queried'
471 )
472 );
473
474 // Hook terms before display to allow developers modify them.
475 $terms = apply_filters('wpc_terms_before_display', $terms, $filter, $set, $urlManager);
476 $templateManager->includeFrontView(
477 /**
478 * Allows you to include your own filters template
479 */
480 apply_filters('wpc_view_include_filename', $filter['view'], $filter, $set),
481
482 array(
483 'filter' => $filter,
484 'terms' => $terms,
485 'set' => $set,
486 'url_manager' => $urlManager,
487 'view_args' => $view_args
488 )
489 );
490
491 } else {
492
493 // Show Search Field if enabled
494 if ( $use_search_field && $search_field_menu_order === $filters_counter) {
495 $templateManager->includeFrontView( 'search', array( 'set' => $set, 'url_manager' => $urlManager, 'wp_manager' => $wpManager ) );
496 $search_field_displayed = true;
497 }
498
499 // Show Apply button if configured
500 if ( $use_apply_button && $apply_button_menu_order === $filters_counter) {
501 $templateManager->includeFrontView('apply-button', array('set' => $set, 'apply_url' => $apply_url, 'reset_url' => $reset_url, 'found_posts' => $found_posts, 'is_filter_request' => flrt_is_filter_request() ));
502 $apply_button_displayed = true;
503 }
504 }
505
506 } // end $related_filters foreach
507
508 if ( $use_search_field && $search_field_displayed === false ) {
509 $templateManager->includeFrontView( 'search', array( 'set' => $set, 'url_manager' => $urlManager, 'wp_manager' => $wpManager ) );
510 }
511
512 if ( $use_apply_button && $apply_button_displayed === false ) {
513 $templateManager->includeFrontView('apply-button', array('set' => $set, 'apply_url' => $apply_url, 'reset_url' => $reset_url, 'found_posts' => $found_posts, 'is_filter_request' => flrt_is_filter_request() ));
514 }
515
516 echo '</div>'."\r\n";
517 echo '</div>' . "\r\n";
518 echo '<div class="wpc-filters-widget-controls-container">
519 <div class="wpc-filters-widget-controls-wrapper">';
520
521 $templateManager->includeFrontView( 'bottom-controls', array( 'action_url' => $actionUrl, 'found_posts' => $found_posts ) );
522
523 echo '
524 </div>';
525
526 if( $use_apply_button ){
527 $templateManager->includeFrontView( 'apply-button', array( 'set' => $set, 'apply_url' => $apply_url, 'reset_url' => $reset_url, 'found_posts' => $found_posts, 'is_filter_request' => flrt_is_filter_request() ) );
528 }
529
530 echo '</div>';
531
532 if( current_user_can( flrt_plugin_user_caps() ) ){
533 echo '<div class="wpc-edit-filter-set">';
534 echo sprintf(
535 wp_kses(
536 __( '<a href="%s">Edit</a> Filter Set', 'filter-everything' ),
537 array( 'a' => array('href' => true) )
538 ),
539 $set_edit_url
540 );
541 echo '</div>';
542 }
543
544 do_action( 'wpc_after_mobile_filters_widget', $setId, $args, $instance );
545
546 echo '</div>' . "\r\n";
547 echo '</div>' . "\r\n"; // end .wpc-filters-widget-content
548 echo '</div>'."\n"; // <!-- wpc-filters-main-wrap -->
549 echo $after_widget;
550
551 do_action( 'wpc_after_filters_widget', $args, $instance );
552 }
553
554 /**
555 * Outputs the settings form for the Filters widget.
556 * @since 1.0.0
557 * @param array $instance Current settings.
558 */
559 public function form( $instance ) {
560
561 $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : '';
562 $show_count = isset( $instance['show_count'] ) ? (bool) $instance['show_count'] : true;
563 $chips = isset( $instance['chips'] ) ? (bool) $instance['chips'] : false;
564 $horizontal = isset( $instance['horizontal'] ) ? (bool) $instance['horizontal'] : false;
565 $cols_count = isset( $instance['cols_count'] ) ? $instance['cols_count'] : 3;
566
567 ?>
568 <p>
569 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:' ); ?></label>
570 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
571 </p>
572 <p>
573 <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_count' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_count' ) ); ?>"<?php checked( $show_count ); ?> />
574 <label for="<?php echo esc_attr( $this->get_field_id( 'show_count' ) ); ?>"><?php esc_html_e( 'Show the number of posts found', 'filter-everything' ); ?></label>
575 </p>
576 <p>
577 <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'chips' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'chips' ) ); ?>"<?php checked( $chips ); ?> />
578 <label for="<?php echo esc_attr( $this->get_field_id( 'chips' ) ); ?>"><?php esc_html_e( 'Show selected terms (Chips)', 'filter-everything' ); ?></label>
579 </p>
580 <p>
581 <input type="checkbox" class="checkbox wpc-horizontal-checkbox" id="<?php echo esc_attr( $this->get_field_id( 'horizontal' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'horizontal' ) ); ?>"<?php checked( $horizontal ); ?> disabled="disabled"/>
582 <label for="<?php echo esc_attr( $this->get_field_id( 'horizontal' ) ); ?>" style="color:#b7b7b7;"><?php esc_html_e( 'Horizontal filters', 'filter-everything' ); ?>.</label>
583 <span class="wpc-columns-wrapper" style="display: none">
584 <label for="<?php echo $this->get_field_id( 'cols_count' ); ?>"><?php _e( 'Columns', 'filter-everything' ); ?>:</label>
585 <select id="<?php echo $this->get_field_id( 'cols_count' ); ?>" name="<?php echo $this->get_field_name( 'cols_count' ); ?>" style="display: none" disabled="disabled">
586 <?php for ( $i = 2; $i <= 5; $i++ ) : ?>
587 <option value="<?php echo esc_attr( $i ); ?>" <?php selected( $cols_count, $i ); ?>>
588 <?php echo esc_html( $i ); ?>
589 </option>
590 <?php endfor; ?>
591 </select>
592 </span>
593 <br>
594 <span>(<?php esc_html_e('This setting has moved to the Filter Set', 'filter-everything'); ?>)</span>
595 </p>
596 <?php
597 }
598
599 /**
600 * Handles updating settings for the current Filters widget instance.
601 * @since 1.0.0
602 * @param array $new_instance New settings for this instance as input by the user via
603 * WP_Widget::form().
604 * @param array $old_instance Old settings for this instance.
605 * @return array Updated settings to save.
606 */
607 public function update( $new_instance, $old_instance ) {
608 $instance = [];
609 $instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
610 $instance['chips'] = ( !empty( $new_instance['chips'] ) ) ? 1 : 0;
611 $instance['show_count'] = ( !empty( $new_instance['show_count'] ) ) ? 1 : 0;
612 $instance['horizontal'] = ( !empty( $new_instance['horizontal'] ) ) ? 1 : 0;
613 $instance['cols_count'] = ( isset( $new_instance['cols_count'] ) && $new_instance['cols_count'] > 0 ) ? $new_instance['cols_count'] : 3;
614
615 return $instance;
616 }
617
618 /**
619 * Outputs Filters widget debug messages
620 * @since 1.2.2
621 */
622 private function _debug_messages($under_limit_filter_set = false){
623 if ( defined('FLRT_FILTERS_PRO') ) {
624 echo '<p class="wpc-debug-message">';
625 echo sprintf(
626 wp_kses(
627 __( 'No one Filter Set is related to this page. You can configure it in the <a href="%s">Filter Set</a> -> "Where to filter?" field.', 'filter-everything' ),
628 array( 'a' => array('href' => true) )
629 ),
630 admin_url( 'edit.php?post_type=filter-set' )
631 );
632 echo '</p>';
633 } else {
634 if ( is_singular() ) {
635 echo '<p class="wpc-debug-message">';
636 echo sprintf(
637 wp_kses(
638 __( 'The free version allows up to 3 filter sets per post type. Upgrade to <a href="%s">PRO</a> to display more filter sets.', 'filter-everything' ),
639 array( 'a' => array('href' => true) )
640 ),
641 esc_url(FLRT_PLUGIN_URL .'/?get_pro=true')
642 );
643 echo '</p>';
644 } else if ( $under_limit_filter_set ) {
645 echo '<p class="wpc-debug-message">';
646 echo sprintf(
647 wp_kses(
648 __( 'The free version allows up to 3 filter sets per post type. Upgrade to <a href="%s">PRO</a> to display more filter sets.', 'filter-everything' ),
649 array( 'a' => array('href' => true) )
650 ),
651 esc_url(FLRT_PLUGIN_URL .'/?get_pro=true')
652 );
653 echo '</p>';
654 } else {
655 echo '<p class="wpc-debug-message">';
656 echo sprintf(
657 wp_kses(
658 __( 'No one Filter Set is configured for this post type pages. You can create a new <a href="%s">Filter Set</a> for them.', 'filter-everything' ),
659 array( 'a' => array('href' => true) )
660 ),
661 admin_url( 'edit.php?post_type=filter-set' )
662 );
663 echo '</p>';
664 }
665 }
666 }
667 }