PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.1.1
Post Grid Gutenberg Blocks – PostX v5.1.1
5.1.1 5.1.0 5.0.41 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 All 240 releases
← All changes | blocks/Advanced_Filter.php +102 -289 5.0.19 → 5.1.1 View file →
@@ -9,15 +9,20 @@
9 9 * Class Advanced_Filter
10 10 */
11 11 class Advanced_Filter {
12 12 /**
13 - * Types of pro select filters supported by the advanced filter.
13 + * Select filter types rendered by PostX itself.
14 14 *
15 + * Further types are added through the `ultp_advanced_filter_select_types` filter.
16 + *
15 17 * @var array
16 18 */
17 - private $pro_select_types = array(
18 - 'adv_sort',
19 - 'custom_tax',
19 + private $select_types = array(
20 + 'category',
21 + 'tags',
22 + 'author',
23 + 'order',
24 + 'order_by',
20 25 );
21 26
22 27 /**
23 28 * Order Value for select
@@ -23,18 +28,20 @@
23 28 * Order Value for select
24 29 *
25 30 * @var array
26 31 */
27 - public $order = array(
28 - array(
29 - 'id' => 'DESC',
30 - 'name' => 'DESC',
31 - ),
32 - array(
33 - 'id' => 'ASC',
34 - 'name' => 'ASC',
35 - ),
36 - );
32 + public function get_order_options() {
33 + return array(
34 + array(
35 + 'id' => 'DESC',
36 + 'name' => __( 'DESC', 'ultimate-post' ),
37 + ),
38 + array(
39 + 'id' => 'ASC',
40 + 'name' => __( 'ASC', 'ultimate-post' ),
41 + ),
42 + );
43 + }
37 44
38 45 /**
39 46 * Order by Value for select
40 47 *
@@ -107,90 +114,8 @@
107 114 add_action( 'init', array( $this, 'register' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
108 115 }
109 116
110 117 /**
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 118 * Get_select_attributes
194 119 *
195 120 * @return array
196 121 */
@@ -210,22 +135,8 @@
210 135 );
211 136 }
212 137
213 138 /**
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 139 * Get_clear_attributes
229 140 *
230 141 * @return array
231 142 */
@@ -275,11 +186,12 @@
275 186 * @param mixed $ids string.
276 187 * @param mixed $post_types string.
277 188 * @param mixed $allText string.
278 189 * @param mixed $option string.
190 + * @param mixed $order array.
279 191 * @return array
280 192 */
281 - public function get_button_data( $type, $data_ids, $post_types = '', $allText = 'All', $option = '' ) {
193 + public function get_button_data( $type, $data_ids, $post_types = '', $allText = 'All', $option = '', $order = array() ) {
282 194
283 195 $res = array();
284 196
285 197 if ( in_array( '_all', $data_ids ) ) {
@@ -290,21 +202,9 @@
290 202 }
291 203
292 204 $ids = implode( ',', $data_ids );
293 205
294 - $adv_sort = $this->get_adv_filter_options();
295 -
296 206 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 207 case 'category':
308 208 $args = array(
309 209 'taxonomy' => 'category',
310 210 'hide_empty' => false,
@@ -324,13 +224,13 @@
324 224 }
325 225 }
326 226 break;
327 227 case 'tags':
328 - $args = array(
228 + $args = array(
329 229 'taxonomy' => 'post_tag',
330 230 'hide_empty' => false,
331 231 );
332 - if ( 'all' !== $option && ! empty( $ids ) && $ids !== '_all') {
232 + if ( 'all' !== $option && ! empty( $ids ) && $ids !== '_all' ) {
333 233 $args['include'] = wp_parse_id_list( $ids );
334 234 $args['orderby'] = 'include';
335 235 }
336 236
@@ -371,51 +271,23 @@
371 271 }
372 272 }
373 273 }
374 274 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 275 default:
276 + /**
277 + * Inline (button) options for a select filter type PostX does not render itself.
278 + *
279 + * @param array $res Options keyed by value. Holds '_all' when that button is enabled.
280 + * @param string $type Filter type.
281 + * @param array $data_ids Values chosen in the block settings.
282 + * @param array|string $post_types Post types the filter applies to, or ''.
283 + * @param string $option 'all' or 'specific'.
284 + */
285 + $res = apply_filters( 'ultp_advanced_filter_button_data', $res, $type, $data_ids, $post_types, $option );
414 286 break;
415 287 }
416 288
417 - return $res;
289 + return is_array( $res ) ? $res : array();
418 290 }
419 291
420 292 /**
421 293 * Inserts all option depending on condition
@@ -433,10 +305,9 @@
433 305 array_splice( $arr, $idx, 0, array( $item ) );
434 306 }
435 307 }
436 308
437 - public function get_select_data( $type, $all_text, $post_types = '', $specific = array(), $mode = 'all' ) {
438 -
309 + public function get_select_data( $type, $all_text, $post_types = '', $specific = array(), $mode = 'all', $order = array() ) {
439 310 $all = null;
440 311 $all_idx = array_search( '_all', $specific, true );
441 312 $filtered_specific = $specific;
442 313
@@ -453,10 +324,8 @@
453 324 }
454 325 );
455 326 }
456 327
457 - $adv_sort = $this->get_adv_filter_options();
458 -
459 328 switch ( $type ) {
460 329
461 330 case 'category':
462 331 $categories = array();
@@ -542,10 +411,10 @@
542 411 case 'order':
543 412 $filtered_specific = array_map( 'strtoupper', $filtered_specific );
544 413
545 414 return 'specific' === $mode ?
546 - $this->filter_select_options( $this->order, $filtered_specific )
547 - : $this->order;
415 + $this->filter_select_options( $order, $filtered_specific )
416 + : $order;
548 417
549 418 case 'order_by':
550 419 return 'specific' === $mode ?
551 420 $this->filter_select_options( $this->order_by, $filtered_specific )
@@ -550,74 +419,45 @@
550 419 return 'specific' === $mode ?
551 420 $this->filter_select_options( $this->order_by, $filtered_specific )
552 421 : $this->order_by;
553 422
554 - case 'adv_sort':
555 - $data = 'specific' === $mode ?
556 - $this->filter_select_options( $adv_sort, $filtered_specific )
557 - : $adv_sort;
423 + default:
424 + /**
425 + * Dropdown options for a select filter type PostX does not render itself.
426 + *
427 + * Return a list of array( 'id' => ..., 'name' => ... ) items, without the
428 + * '_all' item: PostX inserts that. Return null to render no options at all.
429 + *
430 + * @param array|null $data Options. Null when no callback handles the type.
431 + * @param string $type Filter type.
432 + * @param array|string $post_types Post types the filter applies to, or ''.
433 + * @param array $specific Values chosen in the block settings, without '_all'.
434 + * @param string $mode 'all' or 'specific'.
435 + */
436 + $data = apply_filters( 'ultp_advanced_filter_select_data', null, $type, $post_types, $filtered_specific, $mode );
558 437
559 - $this->maybe_insert_all_option( $data, $all, $all_idx, $mode );
560 -
561 - return $data;
562 -
563 - case 'custom_tax':
564 - if ( '' === $post_types ) {
438 + if ( ! is_array( $data ) ) {
565 439 return array();
566 440 }
567 441
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 442 $this->maybe_insert_all_option( $data, $all, $all_idx, $mode );
607 443
608 444 return $data;
609 - default:
610 - return array();
611 445 }
612 446 }
613 447
614 448 public function select_content( $attr ) {
615 449 $block_name = 'filter-select';
616 - $is_active = ultimate_post()->is_lc_active();
617 450 $attr = wp_parse_args( $attr, $this->get_select_attributes() );
618 451
619 - if ( ! $is_active && in_array( $attr['type'], $this->pro_select_types ) ) {
452 + /**
453 + * Select filter types that render on the front end.
454 + *
455 + * @param array $types Types PostX renders itself.
456 + */
457 + $types = apply_filters( 'ultp_advanced_filter_select_types', $this->select_types );
458 +
459 + if ( ! empty( $attr['type'] ) && ! in_array( $attr['type'], (array) $types, true ) ) {
620 460 return '';
621 461 }
622 462
623 463 $post_types = isset( $attr['postTypes'] ) ? $attr['postTypes'] : '';
@@ -632,10 +472,11 @@
632 472 $post_types = json_decode( $post_types, true );
633 473 }
634 474 }
635 475
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' );
476 + $attr['blockId'] = ultimate_post()->sanitize_attr( $attr, 'blockId', 'sanitize_html_class', 'missing_block_id' );
477 + $attr['allText'] = ultimate_post()->sanitize_attr( $attr, 'allText', 'sanitize_text_field', 'missing_block_id' );
478 + $current_page_post_id = ( isset( $attr['currentPostId'] ) && $attr['currentPostId'] ) ? sanitize_html_class( $attr['currentPostId'] ) : ultimate_post()->get_page_post_id( $attr['blockId'] );
638 479
639 480 if ( 'inline' === $attr['filterStyle'] ) {
640 481 $inline_values = json_decode( $attr['filterValues'], true );
641 482
@@ -642,19 +483,19 @@
642 483 if ( ! is_array( $inline_values ) ) {
643 484 return '';
644 485 }
645 486
646 - $data = $this->get_button_data( $attr['type'], $inline_values, $post_types, $attr['allText'], $attr['dropdownOptionsType'] );
487 + $data = $this->get_button_data( $attr['type'], $inline_values, $post_types, $attr['allText'], $attr['dropdownOptionsType'], $this->get_order_options() );
647 488
648 489 $btn_wrapper_attrs = get_block_wrapper_attributes(
649 490 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',
491 + 'class' => 'ultp-block-' . $attr['blockId'] . ' ultp-filter-button',
492 + 'role' => 'button',
493 + 'data-blockId' => $attr['blockId'],
494 + 'data-is-active' => 'false',
495 + 'data-builder' => ultimate_post()->get_builder_attr( 'archiveBuilderFilter' ),
496 + 'data-current-postid' => $current_page_post_id,
497 + 'data-filter-label' => isset( $attr['allText'] ) ? $attr['allText'] : 'All',
657 498 )
658 499 );
659 500
660 501 ob_start();
@@ -667,15 +508,15 @@
667 508 ?>
668 509 <?php
669 510 if ( is_array( $value ) ) {
670 511 $name = $value['name'];
671 - $tax = isset( $value['taxonomy'] ) ? 'data-tax="' . esc_attr( $value['taxonomy'] ) . '"' : '';
512 + $tax = isset( $value['taxonomy'] ) ? $value['taxonomy'] : null;
672 513 } else {
673 514 $name = $value;
674 - $tax = '';
515 + $tax = null;
675 516 }
676 517 ?>
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'] ); ?>">
518 + <div <?php echo $btn_wrapper_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() returns pre-escaped attribute HTML; escaping it again would corrupt it. ?> <?php echo null !== $tax ? 'data-tax="' . esc_attr( $tax ) . '"' : ''; ?> data-selected="<?php echo esc_attr( $key ); ?>" data-type="<?php echo esc_attr( $attr['type'] ); ?>">
678 519 <?php echo esc_html( $name ); ?>
679 520 </div>
680 521 <?php endforeach ?>
681 522 </div>
@@ -700,29 +541,29 @@
700 541 );
701 542 }
702 543 }
703 544
704 - $data = $this->get_select_data( $attr['type'], $attr['allText'], $post_types, $specific, $mode );
545 + $data = $this->get_select_data( $attr['type'], $attr['allText'], $post_types, $specific, $mode, $this->get_order_options() );
705 546
706 547 $def_value = ! empty( current( $data ) ) ? current( $data ) : null;
707 548
708 549 $wrapper_attrs = get_block_wrapper_attributes(
709 550 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',
551 + 'class' => 'ultp-block-' . $attr['blockId'] . ' ultp-filter-select',
552 + 'data-selected' => isset( $def_value['id'] ) ? $def_value['id'] : 0,
553 + 'data-type' => $attr['type'],
554 + 'data-blockId' => $attr['blockId'],
555 + 'aria-expanded' => 'false',
556 + 'aria-label' => 'Select Filter (' . $attr['type'] . ')',
557 + 'data-builder' => ultimate_post()->get_builder_attr( 'archiveBuilderFilter' ),
558 + 'data-current-postid' => $current_page_post_id,
559 + 'data-filter-label' => isset( $def_value['name'] ) ? $def_value['name'] : 'All',
719 560 )
720 561 );
721 562
722 563 ob_start();
723 564 ?>
724 - <div <?php echo $wrapper_attrs; ?>>
565 + <div <?php echo $wrapper_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() returns pre-escaped attribute HTML; escaping it again would corrupt it. ?>>
725 566 <div class="ultp-filter-select-field ultp-filter-select__parent">
726 567 <span class="ultp-filter-select-field-selected ultp-filter-select__parent-inner">
727 568 <?php echo esc_html( isset( $def_value['name'] ) ? $def_value['name'] : '' ); ?>
728 569 </span>
@@ -742,12 +583,9 @@
742 583 />
743 584 <?php endif; ?>
744 585
745 586 <?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'] ); ?>">
587 + <li class="ultp-filter-select__dropdown-inner" <?php echo isset( $item['taxonomy'] ) ? 'data-tax="' . esc_attr( $item['taxonomy'] ) . '"' : ''; ?> data-id="<?php echo esc_attr( $item['id'] ); ?>">
750 588 <?php echo esc_html( $item['name'] ); ?>
751 589 </li>
752 590 <?php endforeach; ?>
753 591
@@ -764,48 +602,24 @@
764 602
765 603 /**
766 604 * Search_content
767 605 *
606 + * The search filter is rendered by PostX Pro through the
607 + * `ultp_advanced_filter_search_content` filter; PostX itself outputs nothing.
608 + *
768 609 * @param mixed $attr array.
769 610 * @return string
770 611 */
771 612 public function search_content( $attr ) {
772 - $block_name = 'filter-search-adv';
773 - $is_active = ultimate_post()->is_lc_active();
613 + /**
614 + * Front-end markup for the Advanced Filter search block.
615 + *
616 + * @param string $content Markup. Empty by default.
617 + * @param array $attr Block attributes, unsanitized.
618 + */
619 + $content = apply_filters( 'ultp_advanced_filter_search_content', '', (array) $attr );
774 620
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;
621 + return is_string( $content ) ? $content : '';
808 622 }
809 623
810 624 /**
811 625 * Clear_content
@@ -814,9 +628,8 @@
814 628 * @return array
815 629 */
816 630 public function clear_content( $attr ) {
817 631 $block_name = 'filter-clear';
818 - // $is_active = ultimate_post()->is_lc_active();
819 632 $attr = wp_parse_args( $attr, $this->get_clear_attributes() );
820 633
821 634 $attr['blockId'] = ultimate_post()->sanitize_attr( $attr, 'blockId', 'sanitize_html_class', 'missing_block_id' );
822 635 $attr['clearButtonText'] = ultimate_post()->sanitize_attr( $attr, 'clearButtonText', 'sanitize_text_field' );
@@ -837,10 +650,10 @@
837 650
838 651 ob_start();
839 652 ?>
840 653
841 - <div class="ultp-block-<?php echo $attr['blockId']; ?>-wrapper">
842 - <div <?php echo $selected_filter_wrapper_attr; ?>>
654 + <div class="ultp-block-<?php echo sanitize_html_class( $attr['blockId'] ); ?>-wrapper">
655 + <div <?php echo $selected_filter_wrapper_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() returns pre-escaped attribute HTML; escaping it again would corrupt it. ?>>
843 656 <div class="ultp-selected-filter">
844 657 <span class="ultp-selected-filter-icon" role="button">
845 658 <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 659 </span>
@@ -848,9 +661,9 @@
848 661 </span>
849 662 </div>
850 663 </div>
851 664
852 - <div <?php echo $wrapper_attrs; ?>>
665 + <div <?php echo $wrapper_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() returns pre-escaped attribute HTML; escaping it again would corrupt it. ?>>
853 666 <button class="ultp-clear-button">
854 667 <?php echo esc_html( $attr['clearButtonText'] ); ?>
855 668 </button>
856 669 </div>