PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.26
Post Grid Gutenberg Blocks – PostX v5.0.26
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.26, at blocks/Advanced_Filter.php

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