PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.22
Post Grid Gutenberg Blocks – PostX v5.0.22
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / blocks / Advanced_Filter.php

Advanced_Filter.php in Post Grid Gutenberg Blocks – PostX 5.0.22, at blocks/Advanced_Filter.php

864 lines 22.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP\blocks;
3
4 use WP_Taxonomy;
5
6 defined( 'ABSPATH' ) || exit;
7
8 /**
9 * Class Advanced_Filter
10 */
11 class Advanced_Filter {
12 /**
13 * Types of pro select filters supported by the advanced filter.
14 *
15 * @var array
16 */
17 private $pro_select_types = array(
18 'adv_sort',
19 'custom_tax',
20 );
21
22 /**
23 * Order Value for select
24 *
25 * @var array
26 */
27 public $order = array(
28 array(
29 'id' => 'DESC',
30 'name' => 'DESC',
31 ),
32 array(
33 'id' => 'ASC',
34 'name' => 'ASC',
35 ),
36 );
37
38 /**
39 * Order by Value for select
40 *
41 * @var array
42 */
43 public $order_by = array(
44 array(
45 'id' => 'date',
46 'name' => 'Created Date',
47 ),
48 array(
49 'id' => 'modified',
50 'name' => 'Date Modified',
51 ),
52 array(
53 'id' => 'title',
54 'name' => 'Title',
55 ),
56 array(
57 'id' => 'menu_order',
58 'name' => 'Menu Order',
59 ),
60 array(
61 'id' => 'rand',
62 'name' => 'Random',
63 ),
64 // array(
65 // 'id' => 'post__in',
66 // 'name' => 'Post In',
67 // ),
68 array(
69 'id' => 'comment_count',
70 'name' => 'Number of Comments',
71 ),
72 );
73
74 /**
75 * Filter_select_options
76 *
77 * @param MIXED | $options (ARRAY).
78 * @param mixed | $filter (ARRAY).
79 * @return array
80 */
81 private function filter_select_options( $options, $filter ) {
82 $res = array();
83 $map = array();
84
85 foreach ( $options as $option ) {
86 $map[ $option['id'] ] = $option['name'];
87 }
88
89 foreach ( $filter as $f ) {
90
91 if ( isset( $map[ $f ] ) ) {
92 $res[] = array(
93 'id' => strtolower( $f ),
94 'name' => $map[ $f ],
95 );
96 }
97 }
98
99 return $res;
100 }
101
102 /**
103 * Advanced_Filter constructor.
104 */
105 public function __construct() {
106 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
107 add_action( 'init', array( $this, 'register' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
108 }
109
110 /**
111 * Get_adv_filter_options
112 *
113 * @return array
114 */
115 private function get_adv_filter_options() {
116 return array(
117 array(
118 'id' => 'popular_post_1_day_view',
119 'name' => __( 'Trending Today', 'ultimate-post' ),
120 ),
121 array(
122 'id' => 'popular_post_7_days_view',
123 'name' => __( 'This Week’s Popular Posts', 'ultimate-post' ),
124 ),
125 array(
126 'id' => 'popular_post_30_days_view',
127 'name' => __( 'Top Posts of the Month', 'ultimate-post' ),
128 ),
129 array(
130 'id' => 'popular_post_all_times_view',
131 'name' => __( 'All-Time Favorites', 'ultimate-post' ),
132 ),
133 array(
134 'id' => 'random_post',
135 'name' => __( 'Random Posts', 'ultimate-post' ),
136 ),
137 array(
138 'id' => 'random_post_7_days',
139 'name' => __( 'Random Posts (7 Days)', 'ultimate-post' ),
140 ),
141 array(
142 'id' => 'random_post_30_days',
143 'name' => __( 'Random Posts (30 Days)', 'ultimate-post' ),
144 ),
145 array(
146 'id' => 'latest_post_published',
147 'name' => __( 'Latest Posts - Published Date', 'ultimate-post' ),
148 ),
149 array(
150 'id' => 'latest_post_modified',
151 'name' => __( 'Latest Posts - Last Modified Date', 'ultimate-post' ),
152 ),
153 array(
154 'id' => 'oldest_post_published',
155 'name' => __( 'Oldest Posts - Published Date', 'ultimate-post' ),
156 ),
157 array(
158 'id' => 'oldest_post_modified',
159 'name' => __( 'Oldest Posts - Last Modified Date', 'ultimate-post' ),
160 ),
161 array(
162 'id' => 'alphabet_asc',
163 'name' => __( 'Alphabetical ASC', 'ultimate-post' ),
164 ),
165 array(
166 'id' => 'alphabet_desc',
167 'name' => __( 'Alphabetical DESC', 'ultimate-post' ),
168 ),
169 array(
170 'id' => 'sticky_posts',
171 'name' => __( 'Sticky Post', 'ultimate-post' ),
172 ),
173 array(
174 'id' => 'most_comment',
175 'name' => __( 'Most Comments', 'ultimate-post' ),
176 ),
177 array(
178 'id' => 'most_comment_1_day',
179 'name' => __( 'Most Comments (1 Day)', 'ultimate-post' ),
180 ),
181 array(
182 'id' => 'most_comment_7_days',
183 'name' => __( 'Most Comments (7 Days)', 'ultimate-post' ),
184 ),
185 array(
186 'id' => 'most_comment_30_days',
187 'name' => __( 'Most Comments (30 Days)', 'ultimate-post' ),
188 ),
189 );
190 }
191
192 /**
193 * Get_select_attributes
194 *
195 * @return array
196 */
197 public function get_select_attributes() {
198 return array(
199 'advanceId' => '',
200 'blockId' => '',
201 'advanceCss' => '',
202 'filterStyle' => 'dropdown',
203 'filterValues' => '["_all"]',
204 'dropdownOptionsType' => 'all',
205 'dropdownOptions' => '["_all"]',
206 'allText' => 'All',
207 'sPlaceholderText' => 'Search...',
208 'searchEnabled' => false,
209 'inlineMultiSelect' => true,
210 );
211 }
212
213 /**
214 * Get_search_attributes
215 *
216 * @return array
217 */
218 public function get_search_attributes() {
219 return array(
220 'advanceId' => '',
221 'blockId' => '',
222 'advanceCss' => '',
223 'placeholder' => 'Search...',
224 );
225 }
226
227 /**
228 * Get_clear_attributes
229 *
230 * @return array
231 */
232 public function get_clear_attributes() {
233 return array(
234 'advanceId' => '',
235 'blockId' => '',
236 'clearButtonText' => 'Clear Filters',
237 'clearButtonPosition' => 'normal',
238 'cAlign' => 'margin-bottom: inherit',
239 );
240 }
241
242 public function register() {
243 register_block_type(
244 'ultimate-post/filter-select',
245 array(
246 'editor_script' => 'ultp-blocks-editor-script',
247 'editor_style' => 'ultp-blocks-editor-css',
248 'render_callback' => array( $this, 'select_content' ),
249 )
250 );
251
252 register_block_type(
253 'ultimate-post/filter-search-adv',
254 array(
255 'editor_script' => 'ultp-blocks-editor-script',
256 'editor_style' => 'ultp-blocks-editor-css',
257 'render_callback' => array( $this, 'search_content' ),
258 )
259 );
260
261 register_block_type(
262 'ultimate-post/filter-clear',
263 array(
264 'editor_script' => 'ultp-blocks-editor-script',
265 'editor_style' => 'ultp-blocks-editor-css',
266 'render_callback' => array( $this, 'clear_content' ),
267 )
268 );
269 }
270
271 /**
272 * Get_button_data
273 *
274 * @param mixed $type string.
275 * @param mixed $ids string.
276 * @param mixed $post_types string.
277 * @param mixed $allText string.
278 * @param mixed $option string.
279 * @return array
280 */
281 public function get_button_data( $type, $data_ids, $post_types = '', $allText = 'All', $option = '' ) {
282
283 $res = array();
284
285 if ( in_array( '_all', $data_ids ) ) {
286 $res['_all'] = $allText;
287 // $ids = array_filter($ids, function ($item) {
288 // return $item != '_all';
289 // });
290 }
291
292 $ids = implode( ',', $data_ids );
293
294 $adv_sort = $this->get_adv_filter_options();
295
296 switch ( $type ) {
297 case 'adv_sort':
298 $adv_sort_id = explode( ',', $ids );
299 foreach ( $adv_sort as $adv ) {
300 foreach ( $adv_sort_id as $id ) {
301 if ( $adv['id'] === $id ) {
302 $res[ $id ] = $adv['name'];
303 }
304 }
305 }
306 break;
307 case 'category':
308 $args = array(
309 'taxonomy' => 'category',
310 'hide_empty' => false,
311 );
312
313 if ( 'all' !== $option && ! empty( $ids ) && '_all' !== $ids ) {
314 $args['include'] = wp_parse_id_list( $ids );
315 $args['orderby'] = 'include';
316 }
317
318 $categories = get_terms( $args );
319
320 if ( ! is_wp_error( $categories ) && ! empty( $categories ) ) {
321 foreach ( $categories as $category ) {
322 $res['_all'] = $allText;
323 $res[ $category->slug ] = $category->name;
324 }
325 }
326 break;
327 case 'tags':
328 $args = array(
329 'taxonomy' => 'post_tag',
330 'hide_empty' => false,
331 );
332 if ( 'all' !== $option && ! empty( $ids ) && $ids !== '_all') {
333 $args['include'] = wp_parse_id_list( $ids );
334 $args['orderby'] = 'include';
335 }
336
337 $tags = get_terms( $args );
338 if ( ! is_wp_error( $tags ) && ! empty( $tags ) ) {
339 foreach ( $tags as $tag ) {
340 $res[ $tag->slug ] = $tag->name;
341 }
342 }
343 break;
344 case 'author':
345 if ( ! empty( $ids ) && $ids !== '_all' ) {
346 $authors = get_users(
347 array(
348 'per_page' => -1,
349 'role__in' => array( 'administrator', 'editor', 'author', 'contributor' ),
350 'include' => $ids,
351 )
352 );
353
354 foreach ( $authors as $author ) {
355 $res[ $author->ID ] = $author->display_name;
356 }
357 }
358
359 break;
360 case 'order':
361 foreach ( $this->order as $order ) {
362 $res[ $order['id'] ] = $order['name'];
363 }
364 break;
365 case 'order_by':
366 $orders = explode( ',', $ids );
367 foreach ( $this->order_by as $order_by ) {
368 foreach ( $orders as $order ) {
369 if ( $order_by['id'] === $order ) {
370 $res[ $order ] = $order_by['name'];
371 }
372 }
373 }
374 break;
375 case 'custom_tax':
376 if ( '' === $post_types ) {
377 break;
378 }
379
380 foreach ( $post_types as $post_type ) {
381 $taxonomies = get_object_taxonomies( $post_type );
382
383 foreach ( $taxonomies as $taxonomy ) {
384 if ( 'category' !== $taxonomy && 'post_tag' !== $taxonomy ) {
385 $terms = get_terms(
386 array(
387 'taxonomy' => $taxonomy,
388 'hide_empty' => false,
389 )
390 );
391 foreach ( $terms as $term ) {
392 $should_add = true;
393 if ( 'specific' === $option ) {
394 $should_add = false;
395 if ( is_array( $data_ids ) ) {
396 $should_add = in_array( $term->slug, $data_ids, true );
397 } elseif ( is_string( $data_ids ) ) {
398 $data_ids_arr = array_filter( array_map( 'trim', explode( ',', $data_ids ) ), 'strlen' );
399 $should_add = in_array( $term->slug, $data_ids_arr, true );
400 }
401 }
402 if ( $should_add ) {
403 $res[ $term->slug ] = array(
404 'name' => $term->name,
405 'taxonomy' => $taxonomy,
406 );
407 }
408 }
409 }
410 }
411 }
412
413 default:
414 break;
415 }
416
417 return $res;
418 }
419
420 /**
421 * Inserts all option depending on condition
422 *
423 * @param array $arr array.
424 * @param array $item all item.
425 * @param int $idx all item idx.
426 * @param string $mode mode.
427 * @return void
428 */
429 private function maybe_insert_all_option( &$arr, &$item, $idx, $mode ) {
430 if ( 'all' === $mode ) {
431 array_unshift( $arr, $item );
432 } elseif ( ! empty( $item ) && false !== $idx ) {
433 array_splice( $arr, $idx, 0, array( $item ) );
434 }
435 }
436
437 public function get_select_data( $type, $all_text, $post_types = '', $specific = array(), $mode = 'all' ) {
438
439 $all = null;
440 $all_idx = array_search( '_all', $specific, true );
441 $filtered_specific = $specific;
442
443 if ( false !== $all_idx || 'all' === $mode ) {
444 $all = array(
445 'id' => '_all',
446 'name' => $all_text,
447 );
448
449 $filtered_specific = array_filter(
450 $specific,
451 function ( $item ) {
452 return '_all' !== $item;
453 }
454 );
455 }
456
457 $adv_sort = $this->get_adv_filter_options();
458
459 switch ( $type ) {
460
461 case 'category':
462 $categories = array();
463
464 if ( 'all' === $mode || ( 'specific' === $mode && count( $filtered_specific ) > 0 ) ) {
465 $categories = get_categories(
466 array(
467 'per_page' => -1,
468
469 'include' => $filtered_specific,
470 'orderby' => 'include',
471 )
472 );
473
474 $categories = array_map(
475 function ( $category ) {
476 return array(
477 'id' => $category->slug,
478 'name' => $category->name,
479 );
480 },
481 $categories
482 );
483 }
484
485 $this->maybe_insert_all_option( $categories, $all, $all_idx, $mode );
486
487 return $categories;
488
489 case 'tags':
490 $tags = array();
491
492 if ( 'all' === $mode || ( 'specific' === $mode && count( $filtered_specific ) > 0 ) ) {
493 $tags = get_tags(
494 array(
495 'per_page' => -1,
496 'include' => $filtered_specific,
497 )
498 );
499 $tags = array_map(
500 function ( \WP_Term $tag ) {
501 return array(
502 'id' => $tag->slug,
503 'name' => $tag->name,
504 );
505 },
506 $tags
507 );
508 }
509
510 $this->maybe_insert_all_option( $tags, $all, $all_idx, $mode );
511
512 return $tags;
513
514 case 'author':
515 $authors = array();
516
517 if ( 'all' === $mode || ( 'specific' === $mode && count( $filtered_specific ) > 0 ) ) {
518
519 $authors = get_users(
520 array(
521 'per_page' => -1,
522 'include' => $filtered_specific,
523 'role__not_in' => array( 'subscriber', 'translator' ),
524 )
525 );
526
527 $authors = array_map(
528 function ( $author ) {
529 return array(
530 'id' => $author->ID,
531 'name' => $author->display_name,
532 );
533 },
534 $authors
535 );
536 }
537
538 $this->maybe_insert_all_option( $authors, $all, $all_idx, $mode );
539
540 return $authors;
541
542 case 'order':
543 $filtered_specific = array_map( 'strtoupper', $filtered_specific );
544
545 return 'specific' === $mode ?
546 $this->filter_select_options( $this->order, $filtered_specific )
547 : $this->order;
548
549 case 'order_by':
550 return 'specific' === $mode ?
551 $this->filter_select_options( $this->order_by, $filtered_specific )
552 : $this->order_by;
553
554 case 'adv_sort':
555 $data = 'specific' === $mode ?
556 $this->filter_select_options( $adv_sort, $filtered_specific )
557 : $adv_sort;
558
559 $this->maybe_insert_all_option( $data, $all, $all_idx, $mode );
560
561 return $data;
562
563 case 'custom_tax':
564 if ( '' === $post_types ) {
565 return array();
566 }
567
568 $data = array();
569
570 foreach ( $post_types as $post_type ) {
571 $taxonomies = get_object_taxonomies( sanitize_text_field( $post_type ) );
572 foreach ( $taxonomies as $taxonomy ) {
573 if ( 'category' !== $taxonomy && 'post_tag' !== $taxonomy ) {
574 $terms = array();
575
576 if ( 'specific' === $mode && count( $filtered_specific ) > 0 ) {
577 foreach ( $filtered_specific as $s ) {
578 $res = get_term_by( 'slug', $s, $taxonomy );
579 if ( ! empty( $res ) ) {
580 $terms[] = $res;
581 }
582 }
583 } else {
584 $terms = get_terms(
585 array(
586 'taxonomy' => $taxonomy,
587 'hide_empty' => false,
588 )
589 );
590 }
591
592 foreach ( $terms as $term ) {
593 $existing_ids = array_column( $data, 'id' );
594 if ( ! in_array( $term->slug, $existing_ids, true ) ) {
595 $data[] = array(
596 'id' => $term->slug,
597 'name' => $term->name,
598 'taxonomy' => $taxonomy,
599 );
600 }
601 }
602 }
603 }
604 }
605
606 $this->maybe_insert_all_option( $data, $all, $all_idx, $mode );
607
608 return $data;
609 default:
610 return array();
611 }
612 }
613
614 public function select_content( $attr ) {
615 $block_name = 'filter-select';
616 $is_active = ultimate_post()->is_lc_active();
617 $attr = wp_parse_args( $attr, $this->get_select_attributes() );
618
619 if ( ! $is_active && in_array( $attr['type'], $this->pro_select_types ) ) {
620 return '';
621 }
622
623 $post_types = isset( $attr['postTypes'] ) ? $attr['postTypes'] : '';
624
625 if ( is_string( $post_types ) ) {
626 $post_types = json_decode( $post_types, true );
627 }
628
629 if ( is_array( $post_types ) && in_array( 'customPostType', $post_types, true ) ) {
630 $post_types = json_decode( $attr['queryPostType'][0] ?? '[]', true );
631 if ( is_string( $post_types ) ) {
632 $post_types = json_decode( $post_types, true );
633 }
634 }
635
636 $attr['blockId'] = ultimate_post()->sanitize_attr( $attr, 'blockId', 'sanitize_html_class', 'missing_block_id' );
637 $attr['allText'] = ultimate_post()->sanitize_attr( $attr, 'allText', 'sanitize_text_field', 'missing_block_id' );
638
639 if ( 'inline' === $attr['filterStyle'] ) {
640 $inline_values = json_decode( $attr['filterValues'], true );
641
642 if ( ! is_array( $inline_values ) ) {
643 return '';
644 }
645
646 $data = $this->get_button_data( $attr['type'], $inline_values, $post_types, $attr['allText'], $attr['dropdownOptionsType'] );
647
648 $btn_wrapper_attrs = get_block_wrapper_attributes(
649 array(
650 'class' => 'ultp-block-' . $attr['blockId'] . ' ultp-filter-button',
651 'role' => 'button',
652 'data-blockId' => $attr['blockId'],
653 'data-is-active' => 'false',
654 'data-builder' => ultimate_post()->get_builder_attr( 'archiveBuilderFilter' ),
655 'data-current-postid' => get_the_ID(),
656 'data-filter-label' => isset($attr['allText']) ? $attr['allText'] : 'All',
657 )
658 );
659
660 ob_start();
661 ?>
662 <div class="ultp-block-<?php echo esc_attr( $attr['blockId'] ); ?>-wrapper" data-multiselect="<?php echo isset( $attr['inlineMultiSelect'] ) && $attr['inlineMultiSelect'] ? 'true' : 'false'; ?>" >
663
664 <?php
665
666 foreach ( $data as $key => $value ) :
667 ?>
668 <?php
669 if ( is_array( $value ) ) {
670 $name = $value['name'];
671 $tax = isset( $value['taxonomy'] ) ? 'data-tax="' . esc_attr( $value['taxonomy'] ) . '"' : '';
672 } else {
673 $name = $value;
674 $tax = '';
675 }
676 ?>
677 <div <?php echo $btn_wrapper_attrs; ?> <?php echo $tax; ?> data-selected="<?php echo esc_attr( $key ); ?>" data-type="<?php echo esc_attr( $attr['type'] ); ?>">
678 <?php echo esc_html( $name ); ?>
679 </div>
680 <?php endforeach ?>
681 </div>
682 <?php
683
684 $content = ob_get_clean();
685 return $content;
686 } elseif ( 'dropdown' === $attr['filterStyle'] ) {
687
688 $mode = 'all';
689 $specific = array();
690
691 if ( 'specific' === $attr['dropdownOptionsType'] && isset( $attr['dropdownOptions'] ) ) {
692 $specific_data = json_decode( stripslashes( $attr['dropdownOptions'] ) );
693 $mode = 'specific';
694 if ( is_array( $specific_data ) ) {
695 $specific = array_map(
696 function ( $item ) {
697 return sanitize_text_field( $item );
698 },
699 $specific_data
700 );
701 }
702 }
703
704 $data = $this->get_select_data( $attr['type'], $attr['allText'], $post_types, $specific, $mode );
705
706 $def_value = ! empty( current( $data ) ) ? current( $data ) : null;
707
708 $wrapper_attrs = get_block_wrapper_attributes(
709 array(
710 'class' => 'ultp-block-' . $attr['blockId'] . ' ultp-filter-select',
711 'data-selected' => isset( $def_value['id'] ) ? $def_value['id'] : 0,
712 'data-type' => $attr['type'],
713 'data-blockId' => $attr['blockId'],
714 'aria-expanded' => 'false',
715 'aria-label' => 'Select Filter (' . $attr['type'] . ')',
716 'data-builder' => ultimate_post()->get_builder_attr( 'archiveBuilderFilter' ),
717 'data-current-postid' => get_the_ID(),
718 'data-filter-label' => isset($def_value['name']) ? $def_value['name'] : 'All',
719 )
720 );
721
722 ob_start();
723 ?>
724 <div <?php echo $wrapper_attrs; ?>>
725 <div class="ultp-filter-select-field ultp-filter-select__parent">
726 <span class="ultp-filter-select-field-selected ultp-filter-select__parent-inner">
727 <?php echo esc_html( isset( $def_value['name'] ) ? $def_value['name'] : '' ); ?>
728 </span>
729 <span class="ultp-filter-select-field-icon">
730 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 34.1 19.95"><path d="M17.05 19.949.601 3.499a2.05 2.05 0 0 1 2.9-2.9l13.551 13.55L30.603.599a2.05 2.05 0 0 1 2.9 2.9Z"/></svg>
731 </span>
732 </div>
733 <ul style="display: none;" class="ultp-filter-select-options ultp-filter-select__dropdown">
734
735 <?php
736 if ( isset( $attr['searchEnabled'] ) && $attr['searchEnabled'] ) :
737 ?>
738 <input
739 type="search"
740 class="ultp-filter-select-search"
741 placeholder="<?php echo esc_attr( isset( $attr['sPlaceholderText'] ) ? $attr['sPlaceholderText'] : '' ); ?>"
742 />
743 <?php endif; ?>
744
745 <?php foreach ( $data as $item ) : ?>
746 <?php
747 $tax = isset( $item['taxonomy'] ) ? 'data-tax="' . esc_attr( $item['taxonomy'] ) . '"' : '';
748 ?>
749 <li class="ultp-filter-select__dropdown-inner" <?php echo $tax; ?> data-id="<?php echo esc_attr( $item['id'] ); ?>">
750 <?php echo esc_html( $item['name'] ); ?>
751 </li>
752 <?php endforeach; ?>
753
754 </ul>
755 </div>
756
757 <?php
758 $content = ob_get_clean();
759 return $content;
760 }
761
762 return '';
763 }
764
765 /**
766 * Search_content
767 *
768 * @param mixed $attr array.
769 * @return string
770 */
771 public function search_content( $attr ) {
772 $block_name = 'filter-search-adv';
773 $is_active = ultimate_post()->is_lc_active();
774
775 if ( ! $is_active ) {
776 return '';
777 }
778
779 $attr = wp_parse_args( $attr, $this->get_search_attributes() );
780
781 $attr['blockId'] = ultimate_post()->sanitize_attr( $attr, 'blockId', 'sanitize_html_class', 'missing_block_id' );
782 $attr['placeholder'] = ultimate_post()->sanitize_attr( $attr, 'placeholder', 'sanitize_text_field' );
783
784 $wrapper_attrs = get_block_wrapper_attributes(
785 array(
786 'class' => 'ultp-block-' . $attr['blockId'] . ' ultp-filter-search',
787 'aria-label' => 'Search Filter',
788 'role' => 'searchbox',
789 )
790 );
791
792 ob_start();
793 ?>
794 <div <?php echo $wrapper_attrs; ?>>
795 <div class="ultp-filter-search-input">
796 <input
797 type="search"
798 placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>"
799 />
800 <span class="ultp-filter-search-input-icon">
801 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 47.05 47.05" fill="currentColor"><path stroke="currentColor" strokeMiterlimit="10" d="m43.051 45.948-9.618-9.616a20.183 20.183 0 1 1 2.9-2.9l9.617 9.616a2.05 2.05 0 1 1-2.9 2.9Zm-22.367-9.179A16.084 16.084 0 1 0 4.6 20.684a16.1 16.1 0 0 0 16.084 16.085Z"/></svg>
802 </span>
803 </div>
804 </div>
805 <?php
806 $content = ob_get_clean();
807 return $content;
808 }
809
810 /**
811 * Clear_content
812 *
813 * @param mixed $attr array.
814 * @return array
815 */
816 public function clear_content( $attr ) {
817 $block_name = 'filter-clear';
818 // $is_active = ultimate_post()->is_lc_active();
819 $attr = wp_parse_args( $attr, $this->get_clear_attributes() );
820
821 $attr['blockId'] = ultimate_post()->sanitize_attr( $attr, 'blockId', 'sanitize_html_class', 'missing_block_id' );
822 $attr['clearButtonText'] = ultimate_post()->sanitize_attr( $attr, 'clearButtonText', 'sanitize_text_field' );
823
824 $wrapper_attrs = get_block_wrapper_attributes(
825 array(
826 'class' => 'ultp-block-' . $attr['blockId'] . ' ultp-filter-clear ultp-filter-clear-button ',
827 'data-blockid' => $attr['blockId'],
828 )
829 );
830
831 $selected_filter_wrapper_attr = get_block_wrapper_attributes(
832 array(
833 'class' => 'ultp-block-' . $attr['blockId'] . ' ultp-filter-clear ultp-filter-clear-template',
834 'style' => 'display: none;',
835 )
836 );
837
838 ob_start();
839 ?>
840
841 <div class="ultp-block-<?php echo $attr['blockId']; ?>-wrapper">
842 <div <?php echo $selected_filter_wrapper_attr; ?>>
843 <div class="ultp-selected-filter">
844 <span class="ultp-selected-filter-icon" role="button">
845 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 31.1 31.25"><path stroke="rgba(0,0,0,0)" strokeMiterlimit="10" d="M27.1 30.153 15.549 18.601 4 30.153a2.05 2.05 0 0 1-2.9-2.9l11.551-11.55L1.1 4.153a2.05 2.05 0 0 1 2.9-2.9l11.549 11.552L27.1 1.253a2.05 2.05 0 0 1 2.9 2.9l-11.553 11.55L30 27.253a2.05 2.05 0 1 1-2.9 2.9Z"/></svg>
846 </span>
847 <span class="ultp-selected-filter-text">
848 </span>
849 </div>
850 </div>
851
852 <div <?php echo $wrapper_attrs; ?>>
853 <button class="ultp-clear-button">
854 <?php echo esc_html( $attr['clearButtonText'] ); ?>
855 </button>
856 </div>
857 </div>
858
859 <?php
860 $content = ob_get_clean();
861 return $content;
862 }
863 }
864