PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
← All changes | includes/blocks/taxonomy-listing/block.php +840 -0 2.7.5 → 2.14.0 View file →
@@ -1,0 +1,840 @@
1 +<?php
2 +
3 +namespace ABlocks\Blocks\taxonomyListing;
4 +
5 +if ( ! defined( 'ABSPATH' ) ) {
6 + exit;
7 +}
8 +
9 +use ABlocks\Classes\BlockBaseAbstract;
10 +use ABlocks\Classes\CssGenerator;
11 +use ABlocks\Controls\Alignment;
12 +use ABlocks\Controls\Typography;
13 +use ABlocks\Controls\Dimensions;
14 +use ABlocks\Controls\Icon;
15 +use ABlocks\Controls\Border;
16 +use ABlocks\Controls\BoxShadow;
17 +
18 +use WP_Query;
19 +
20 +class Block extends BlockBaseAbstract {
21 +
22 +
23 + protected $block_name = 'taxonomy-listing';
24 +
25 + public function build_css( $attributes ) {
26 + $css_generator = new CssGenerator( $attributes, $this->block_name );
27 +
28 + $wrapper_styles = $this->get_wrapper_css( $attributes );
29 + $css_generator->add_class_styles(
30 + '{{WRAPPER}}',
31 + $wrapper_styles,
32 + $this->get_wrapper_css( $attributes, 'Tablet' ),
33 + $this->get_wrapper_css( $attributes, 'Mobile' ),
34 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } )
35 + );
36 +
37 + $card_styles = $this->get_card_css( $attributes );
38 + $css_generator->add_class_styles(
39 + '{{WRAPPER}} .ablocks-taxonomy-listing-item',
40 + $card_styles,
41 + $this->get_card_css( $attributes, 'Tablet' ),
42 + $this->get_card_css( $attributes, 'Mobile' ),
43 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_card_css( $attributes, $device ); } )
44 + );
45 +
46 + $card_hover_styles = $this->get_card_hover_css( $attributes );
47 + $css_generator->add_class_styles(
48 + '{{WRAPPER}} .ablocks-taxonomy-listing-item:hover',
49 + $card_hover_styles,
50 + $this->get_card_hover_css( $attributes, 'Tablet' ),
51 + $this->get_card_hover_css( $attributes, 'Mobile' ),
52 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_card_hover_css( $attributes, $device ); } )
53 + );
54 +
55 + $card_padding_styles = $this->get_card_padding_css( $attributes );
56 + $css_generator->add_class_styles(
57 + '{{WRAPPER}} .ablocks-taxonomy-listing-item_content',
58 + $card_padding_styles,
59 + $this->get_card_padding_css( $attributes, 'Tablet' ),
60 + $this->get_card_padding_css( $attributes, 'Mobile' ),
61 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_card_padding_css( $attributes, $device ); } )
62 + );
63 +
64 + $taxonomy_title_styles = $this->get_taxonomy_title_css( $attributes );
65 + $css_generator->add_class_styles(
66 + '{{WRAPPER}} .ablocks-taxonomy-title',
67 + $taxonomy_title_styles,
68 + $this->get_taxonomy_title_css( $attributes, 'Tablet' ),
69 + $this->get_taxonomy_title_css( $attributes, 'Mobile' ),
70 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_taxonomy_title_css( $attributes, $device ); } )
71 + );
72 + $taxonomy_title_hover_styles = $this->get_taxonomy_hover_title_css( $attributes );
73 + $css_generator->add_class_styles(
74 + '{{WRAPPER}} .ablocks-taxonomy-title:hover',
75 + $taxonomy_title_hover_styles,
76 + $this->get_taxonomy_hover_title_css( $attributes, 'Tablet' ),
77 + $this->get_taxonomy_hover_title_css( $attributes, 'Mobile' ),
78 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_taxonomy_hover_title_css( $attributes, $device ); } )
79 + );
80 + // Icon style
81 + $icons_style = $this->get_icons( $attributes );
82 + $css_generator->add_class_styles(
83 + '{{WRAPPER}} .ablocks-taxonomy-icon',
84 + $icons_style,
85 + $this->get_icons( $attributes, 'Tablet' ),
86 + $this->get_icons( $attributes, 'Mobile' ),
87 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icons( $attributes, $device ); } )
88 + );
89 + // Icon style
90 + $icons_svg_style = $this->get_icons_svg( $attributes );
91 + $css_generator->add_class_styles(
92 + '{{WRAPPER}} .ablocks-taxonomy-icon svg',
93 + $icons_svg_style,
94 + $this->get_icons_svg( $attributes, 'Tablet' ),
95 + $this->get_icons_svg( $attributes, 'Mobile' ),
96 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icons_svg( $attributes, $device ); } )
97 + );
98 + // Icon style
99 + $icon_svg_path_style = $this->get_icon_svg_path( $attributes );
100 + $css_generator->add_class_styles(
101 + '{{WRAPPER}} .ablocks-taxonomy-icon svg path',
102 + $icon_svg_path_style,
103 + $this->get_icon_svg_path( $attributes, 'Tablet' ),
104 + $this->get_icon_svg_path( $attributes, 'Mobile' ),
105 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_svg_path( $attributes, $device ); } )
106 + );
107 + // Post Title Start
108 + $post_title_styles = $this->get_post_title_css( $attributes );
109 + $css_generator->add_class_styles(
110 + '{{WRAPPER}} .ablocks-taxonomy-posts a',
111 + $post_title_styles,
112 + $this->get_post_title_css( $attributes, 'Tablet' ),
113 + $this->get_post_title_css( $attributes, 'Mobile' ),
114 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_title_css( $attributes, $device ); } )
115 + );
116 +
117 + $post_hover_styles = $this->get_post_hover_title_css( $attributes );
118 + $css_generator->add_class_styles(
119 + '{{WRAPPER}} .ablocks-taxonomy-posts a:hover',
120 + $post_hover_styles,
121 + $this->get_post_hover_title_css( $attributes, 'Tablet' ),
122 + $this->get_post_hover_title_css( $attributes, 'Mobile' ),
123 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_hover_title_css( $attributes, $device ); } )
124 + );
125 + $post_active_styles = $this->get_post_active_title_css( $attributes );
126 + $css_generator->add_class_styles(
127 + '{{WRAPPER}} .ablocks-taxonomy-posts a.active-post-link',
128 + $post_active_styles,
129 + $this->get_post_active_title_css( $attributes, 'Tablet' ),
130 + $this->get_post_active_title_css( $attributes, 'Mobile' ),
131 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_active_title_css( $attributes, $device ); } )
132 + );
133 + // Post Title End
134 +
135 + $post_count_styles = $this->get_post_title_count_css( $attributes );
136 + $css_generator->add_class_styles(
137 + '{{WRAPPER}} .ablocks-taxonomy-title__post-count',
138 + $post_count_styles,
139 + $this->get_post_title_count_css( $attributes, 'Tablet' ),
140 + $this->get_post_title_count_css( $attributes, 'Mobile' ),
141 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_title_count_css( $attributes, $device ); } )
142 + );
143 +
144 + $post_count_hover_styles = $this->get_post_title_hover_count_css( $attributes );
145 + $css_generator->add_class_styles(
146 + '{{WRAPPER}} .ablocks-taxonomy-title__post-count:hover',
147 + $post_count_hover_styles,
148 + $this->get_post_title_hover_count_css( $attributes, 'Tablet' ),
149 + $this->get_post_title_hover_count_css( $attributes, 'Mobile' ),
150 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_post_title_hover_count_css( $attributes, $device ); } )
151 + );
152 +
153 + $button_styles = $this->get_button_css( $attributes );
154 + $css_generator->add_class_styles(
155 + '{{WRAPPER}} .ablocks-reload-button',
156 + $button_styles,
157 + $this->get_button_css( $attributes, 'Tablet' ),
158 + $this->get_button_css( $attributes, 'Mobile' ),
159 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_css( $attributes, $device ); } )
160 + );
161 +
162 + $button_hover_styles = $this->get_button_hover_css( $attributes );
163 + $css_generator->add_class_styles(
164 + '{{WRAPPER}} .ablocks-reload-button:hover',
165 + $button_hover_styles,
166 + $this->get_button_hover_css( $attributes, 'Tablet' ),
167 + $this->get_button_hover_css( $attributes, 'Mobile' ),
168 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_hover_css( $attributes, $device ); } )
169 + );
170 + // Icon Style
171 +
172 + $css_generator->add_class_styles(
173 + '{{WRAPPER}} .ablocks-icon-wrap',
174 + Icon::get_wrapper_css( $attributes ),
175 + Icon::get_wrapper_css( $attributes, 'Tablet' ),
176 + Icon::get_wrapper_css( $attributes, 'Mobile' ),
177 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_wrapper_css( $attributes, $device ); } )
178 + );
179 +
180 + $css_generator->add_class_styles(
181 + '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
182 + Icon::get_element_image_css( $attributes ),
183 + Icon::get_element_image_css( $attributes, 'Tablet' ),
184 + Icon::get_element_image_css( $attributes, 'Mobile' ),
185 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_css( $attributes, $device ); } )
186 + );
187 + $css_generator->add_class_styles(
188 + '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon:hover',
189 + Icon::get_element_image_hover_css( $attributes ),
190 + Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
191 + Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
192 + );
193 + $css_generator->add_class_styles(
194 + '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
195 + Icon::get_element_css( $attributes ),
196 + Icon::get_element_css( $attributes, 'Tablet' ),
197 + Icon::get_element_css( $attributes, 'Mobile' ),
198 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_css( $attributes, $device ); } )
199 + );
200 + $css_generator->add_class_styles(
201 + '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon:hover',
202 + Icon::get_element_image_hover_css( $attributes ),
203 + Icon::get_element_image_hover_css( $attributes, 'Tablet' ),
204 + Icon::get_element_image_hover_css( $attributes, 'Mobile' ),
205 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return Icon::get_element_image_hover_css( $attributes, $device ); } )
206 + );
207 + // Layout grid
208 +
209 + if ( $attributes['taxonomyLayout'] === 'flex' ) {
210 + $main_wrapper_css = $this->get_card_wrapper( $attributes );
211 + $css_generator->add_class_styles(
212 + '{{WRAPPER}} .ablocks-taxonomy-listing_flex',
213 + $main_wrapper_css,
214 + $this->get_card_wrapper( $attributes, 'Tablet' ),
215 + $this->get_card_wrapper( $attributes, 'Mobile' ),
216 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_card_wrapper( $attributes, $device ); } )
217 + );
218 + }
219 +
220 + return $css_generator->generate_css();
221 + }
222 +
223 + public function get_wrapper_css( $attributes, $device = '' ) {
224 + return isset( $attributes['alignment'] )
225 + ? Alignment::get_css( $attributes['alignment'], 'text-align', $device )
226 + : [];
227 + }
228 +
229 +
230 + public function get_taxonomy_title_css( $attributes, $device = '' ) {
231 + $css = [];
232 +
233 + // Color
234 + if ( ! empty( $attributes['taxonomyTitlecolor'] ) ) {
235 + $css['color'] = $attributes['taxonomyTitlecolor'];
236 + }
237 +
238 + // Background
239 + if ( ! empty( $attributes['taxonomyTitletBgColor'] ) ) {
240 + $css['background'] = $attributes['taxonomyTitletBgColor'];
241 + }
242 +
243 + // Justify content (alignment)
244 + if ( isset( $attributes['taxonomyTitlePosition'][ 'value' . $device ] ) ) {
245 + $css['justify-content'] = $attributes['taxonomyTitlePosition'][ 'value' . $device ];
246 + }
247 +
248 + // Flex direction
249 + if ( isset( $attributes['taxonomyTitleDirection'][ 'value' . $device ] ) ) {
250 + $css['flex-direction'] = $attributes['taxonomyTitleDirection'][ 'value' . $device ];
251 + }
252 + $typographyValueGlobal = ! empty( $attributes['taxonomyTitleTypographyGlobal'] ) ? $attributes['taxonomyTitleTypographyGlobal'] : [];
253 + return array_merge(
254 + Typography::get_css( $attributes['taxonomyTitleTypography'] ?? [], '', $device, $typographyValueGlobal ),
255 + Border::get_css( $attributes['taxonomyTitleBorder'] ?? [], '', $device ),
256 + Dimensions::get_css( $attributes['taxonomyTitlePadding'] ?? [], 'padding', $device ),
257 + $css
258 + );
259 + }
260 +
261 + public function get_taxonomy_hover_title_css( $attributes, $device = '' ) {
262 + $css = [];
263 +
264 + $taxonomy_title_border = ! empty( $attributes['taxonomyTitleBorder'] ) ? Border::get_hover_css( $attributes['taxonomyTitleBorder'], '', $device ) : array();
265 +
266 + return array_merge(
267 + $taxonomy_title_border
268 + );
269 + }
270 +
271 + public function get_post_title_count_css( $attributes, $device = '' ) {
272 + $css = [];
273 +
274 + if ( ! empty( $attributes['postCountColor'] ) ) {
275 + $css['color'] = $attributes['postCountColor'];
276 + }
277 + if ( ! empty( $attributes['postCountBgColor'] ) ) {
278 + $css['background'] = $attributes['postCountBgColor'];
279 + }
280 + if ( ! empty( $attributes['postCountWidth'] ) ) {
281 + $css['width'] = $attributes['postCountWidth'] . 'px';
282 + }
283 + if ( ! empty( $attributes['postCountWidth'] ) ) {
284 + $css['height'] = $attributes['postCountWidth'] . 'px';
285 + }
286 + $typographyValueGlobal = ! empty( $attributes['postCountTypographyGlobal'] ) ? $attributes['postCountTypographyGlobal'] : [];
287 + return array_merge(
288 + Border::get_css( $attributes['postCountBorder'] ?? [], '', $device ),
289 + Dimensions::get_css( $attributes['padding'] ?? [], 'padding', $device ),
290 + Typography::get_css( $attributes['postCountTypography'] ?? [], '', $device, $typographyValueGlobal ),
291 + $css
292 + );
293 + }
294 +
295 + public function get_post_title_hover_count_css( $attributes, $device = '' ) {
296 + $post_count_hover_border_style = ! empty( $attributes['postCountBorder'] ) ? Border::get_hover_css( $attributes['postCountBorder'], '', $device ) : array();
297 + return array_merge(
298 + $post_count_hover_border_style
299 + );
300 + }
301 +
302 + public function get_card_css( $attributes, $device = '' ) {
303 + $css = [];
304 +
305 + if ( ! empty( $attributes['cardBgColor'] ) ) {
306 + $css['background'] = $attributes['cardBgColor'];
307 + }
308 +
309 + return array_merge(
310 + Border::get_css( $attributes['cardBorder'] ?? [], '', $device ),
311 + BoxShadow::get_css( $attributes['cardBoxShadow'] ?? [], '', $device ),
312 + $css
313 + );
314 + }
315 +
316 + public function get_card_hover_css( $attributes, $device = '' ) {
317 + $css = [];
318 + $card_hover_border = ! empty( $attributes['cardBorder'] ) ? Border::get_hover_css( $attributes['cardBorder'], '', $device ) : array();
319 + if ( ! empty( $attributes['cardBgHoverColor'] ) ) {
320 + $css['background'] = $attributes['cardBgHoverColor'];
321 + }
322 +
323 + return array_merge(
324 + $css,
325 + $card_hover_border,
326 + BoxShadow::get_hover_css( $attributes['cardBoxShadow'], '', $device ),
327 + );
328 + }
329 +
330 + public function get_card_padding_css( $attributes, $device = '' ) {
331 + return Dimensions::get_css( $attributes['cardPadding'] ?? [], 'padding', $device );
332 + }
333 +
334 + // Taxonomy Title Start
335 + public function get_post_title_css( $attributes, $device = '' ) {
336 + $css = [];
337 +
338 + if ( ! empty( $attributes['postTitleColor'] ) ) {
339 + $css['color'] = $attributes['postTitleColor'];
340 + }
341 +
342 + if ( ! empty( $attributes['postBackgroundColor'] ) ) {
343 + $css['background'] = $attributes['postBackgroundColor'];
344 + }
345 + $typographyValueGlobal = ! empty( $attributes['postTitleTypographyGlobal'] ) ? $attributes['postTitleTypographyGlobal'] : [];
346 +
347 + $typography = Typography::get_css($attributes['postTitleTypography'] ?? [], [
348 + 'weight' => '500',
349 + ], $device, $typographyValueGlobal);
350 +
351 + $postpadding = Dimensions::get_css( $attributes['postPadding'] ?? [], 'padding', $device );
352 +
353 + $border = Border::get_css($attributes['postBorder'] ?? [], [
354 + 'unitWidth' => 'px',
355 + 'unitRadius' => 'px',
356 + ], $device);
357 +
358 + return array_merge(
359 + $css,
360 + $typography,
361 + $postpadding,
362 + $border
363 + );
364 + }
365 +
366 + public function get_post_hover_title_css( $attributes, $device = '' ) {
367 + $css = [];
368 +
369 + if ( ! empty( $attributes['postTitleHoverColor'] ) ) {
370 + $css['color'] = $attributes['postTitleHoverColor'];
371 + }
372 +
373 + if ( ! empty( $attributes['hoverPostBackgroundColor'] ) ) {
374 + $css['background'] = $attributes['hoverPostBackgroundColor'];
375 + }
376 +
377 + return $css;
378 + }
379 +
380 + public function get_post_active_title_css( $attributes, $device = '' ) {
381 + $css = [];
382 +
383 + if ( ! empty( $attributes['postTitleActiveColor'] ) ) {
384 + $css['color'] = $attributes['postTitleActiveColor'];
385 + }
386 +
387 + if ( ! empty( $attributes['activePostBackgroundColor'] ) ) {
388 + $css['background'] = $attributes['activePostBackgroundColor'];
389 + }
390 +
391 + $border = Border::get_css($attributes['activePostBorder'] ?? [], [
392 + 'unitWidth' => 'px',
393 + 'unitRadius' => 'px',
394 + ], $device);
395 +
396 + return array_merge(
397 + $css,
398 + $border
399 + );
400 + }
401 +
402 + // Post Title End
403 + public function get_button_css( $attributes, $device = '' ) {
404 + $css = [];
405 +
406 + if ( ! empty( $attributes['buttonColor'] ) ) {
407 + $css['color'] = $attributes['buttonColor'];
408 + }
409 +
410 + if ( ! empty( $attributes['buttonBgColor'] ) ) {
411 + $css['background'] = $attributes['buttonBgColor'];
412 + }
413 +
414 + // Display
415 + if ( isset( $attributes['buttonPosition'][ 'value' . $device ] ) ) {
416 + $css['display'] = $attributes['buttonPosition'][ 'value' . $device ];
417 + }
418 + $typographyValueGlobal = ! empty( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : [];
419 +
420 + return array_merge(
421 + Typography::get_css( $attributes['buttonTypography'] ?? [], '', $device, $typographyValueGlobal ),
422 + Border::get_css( $attributes['buttonBorder'] ?? [], '', $device ),
423 + Dimensions::get_css( $attributes['buttonPadding'] ?? [], 'padding', $device ),
424 + $css
425 + );
426 + }
427 +
428 + public function get_button_hover_css( $attributes, $device = '' ) {
429 + $css = [];
430 + $button_hover_border = ! empty( $attributes['buttonBorder'] ) ? Border::get_hover_css( $attributes['buttonBorder'], '', $device ) : array();
431 + if ( ! empty( $attributes['buttonHoverColor'] ) ) {
432 + $css['color'] = $attributes['buttonHoverColor'];
433 + }
434 + if ( ! empty( $attributes['buttonHoverBgColor'] ) ) {
435 + $css['background'] = $attributes['buttonHoverBgColor'];
436 + }
437 +
438 + return array_merge(
439 + $button_hover_border,
440 + $css
441 + );
442 + }
443 +
444 + // Icon Style
445 +
446 + public function get_icons( $attributes, $device = '' ) {
447 + $css = [];
448 +
449 + if ( ! empty( $attributes['iconBgColor'] ) ) {
450 + $css['background'] = $attributes['iconBgColor'];
451 + }
452 +
453 + return array_merge(
454 + Dimensions::get_css( $attributes['iconPadding'] ?? [], 'padding', $device ),
455 + Dimensions::get_css( $attributes['iconBorderRadius'] ?? [], 'border-radius', $device ),
456 + $css
457 + );
458 + }
459 +
460 + public function get_icons_svg( $attributes, $device = '' ) {
461 + $css = [];
462 + if ( ! empty( $attributes['iconsSize'] ) ) {
463 + $css['width'] = $attributes['iconsSize'] . 'px';
464 + }
465 + if ( ! empty( $attributes['iconsSize'] ) ) {
466 + $css['height'] = $attributes['iconsSize'] . 'px';
467 + }
468 +
469 + return array_merge(
470 + $css
471 + );
472 + }
473 +
474 + public function get_icon_svg_path( $attributes, $device = '' ) {
475 + $css = [];
476 + if ( ! empty( $attributes['iconColor'] ) ) {
477 + $css['fill'] = $attributes['iconColor'];
478 + }
479 +
480 + return array_merge(
481 + $css
482 + );
483 + }
484 +
485 + public function get_card_wrapper( $attributes, $device = '' ) {
486 + $css = [];
487 + if ( $attributes['taxonomyLayout'] === 'flex' ) {
488 + $css['display'] = 'grid';
489 + $css['gap'] = '1.5em';
490 + if ( $device === 'Tablet' ) {
491 + $css['grid-template-columns'] = 'repeat(2, 1fr)';
492 + } elseif ( $device === 'Mobile' ) {
493 + $css['grid-template-columns'] = 'repeat(1, 1fr)';
494 + } elseif ( ! empty( $attributes['itemsPerRow'] ) ) {
495 + $css['grid-template-columns'] = 'repeat(' . $attributes['itemsPerRow'] . ', 1fr)';
496 + }
497 + }
498 + return array_merge(
499 + $css
500 + );
501 + }
502 +
503 + public function render_callback( $attributes, $content, $block_instance ) {
504 + $content = '';
505 + return parent::render_callback( $attributes, $content, $block_instance );
506 + }
507 +
508 +
509 + // Markup Start
510 +
511 + protected function inherit_selected_terms( array $active_taxonomy, array $selected_terms, string $selected_post_type, bool $show_inherit ): array {
512 + if ( ! $show_inherit || empty( $active_taxonomy ) ) {
513 + return $selected_terms;
514 + }
515 +
516 + $queried_object = get_queried_object();
517 +
518 + if ( is_tax() || is_post_type_archive() ) {
519 + foreach ( $active_taxonomy as $taxonomy ) {
520 + if ( isset( $queried_object->taxonomy ) && $queried_object->taxonomy === $taxonomy ) {
521 + $selected_terms[ $taxonomy ] = [ $queried_object->term_id ];
522 + } else {
523 + $terms = get_terms([
524 + 'taxonomy' => $taxonomy,
525 + 'hide_empty' => true
526 + ]);
527 + if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
528 + $selected_terms[ $taxonomy ] = wp_list_pluck( $terms, 'term_id' );
529 + }
530 + }
531 + }
532 + } elseif ( is_singular( $selected_post_type ) && $queried_object instanceof \WP_Post ) {
533 + foreach ( $active_taxonomy as $taxonomy ) {
534 + $terms = get_the_terms( $queried_object->ID, $taxonomy );
535 + if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
536 + $selected_terms[ $taxonomy ] = wp_list_pluck( $terms, 'term_id' );
537 + }
538 + }
539 + } else {
540 + foreach ( $active_taxonomy as $taxonomy ) {
541 + $terms = get_terms([
542 + 'taxonomy' => $taxonomy,
543 + 'hide_empty' => true
544 + ]);
545 + if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
546 + $selected_terms[ $taxonomy ] = wp_list_pluck( $terms, 'term_id' );
547 + }
548 + }
549 + }//end if
550 +
551 + return $selected_terms;
552 + }
553 +
554 + /**
555 + * Taxonomy Wise Query
556 + */
557 + protected function build_term_query( string $taxonomy, int $term_id, string $post_type, int $per_page, string $orderby, string $order ): \WP_Query {
558 + return new \WP_Query([
559 + 'post_type' => $post_type,
560 + 'post_status' => 'publish',
561 + 'posts_per_page' => $per_page,
562 + 'orderby' => $orderby,
563 + 'order' => $order,
564 + 'tax_query' => [
565 + [
566 + 'taxonomy' => $taxonomy,
567 + 'field' => 'term_id',
568 + 'terms' => $term_id,
569 + ]
570 + ],
571 + ]);
572 + }
573 +
574 + /**
575 + * Accordion Open Use current post ID Check
576 + */
577 + protected function should_open_section( \WP_Query $query, int $current_post_id ): bool {
578 + if ( ! $current_post_id || ! $query->have_posts() ) {
579 + return false;
580 + }
581 + $open = false;
582 + while ( $query->have_posts() ) {
583 + $query->the_post();
584 + if ( get_the_ID() === $current_post_id ) {
585 + $open = true;
586 + break;
587 + }
588 + }
589 + $query->rewind_posts();
590 + wp_reset_postdata();
591 + return $open;
592 + }
593 +
594 + /**
595 + * Post ID Use Active class
596 + */
597 + protected function render_posts_list( \WP_Query $query, bool $show_post, int $current_post_id ): void {
598 + if ( ! $query->have_posts() || ! $show_post ) {
599 + return;
600 + }
601 + echo '<ul class="ablocks-taxonomy-posts">';
602 + while ( $query->have_posts() ) {
603 + $query->the_post();
604 + $post_link = get_permalink();
605 + $is_active = ( get_the_ID() === $current_post_id ) ? ' active-post-link' : '';
606 + echo '<a class="ablocks-post-link' . esc_attr( $is_active ) . '" href="' . esc_url( $post_link ) . '" rel="noreferrer">' . esc_html( get_the_title() ) . '</a>';
607 + }
608 + wp_reset_postdata();
609 + echo '</ul>';
610 + }
611 +
612 + /**
613 + * Reload Button
614 + */
615 + protected function render_reload_button( bool $enable_reload, $term_link, string $button_text ): void {
616 + if ( ! $enable_reload || is_wp_error( $term_link ) ) {
617 + return;
618 + }
619 + echo '<div class="ablocks-reload-button-wrapper">';
620 + echo '<a href="' . esc_url( $term_link ) . '" class="ablocks-reload-button">' . esc_html( $button_text ) . '</a>';
621 + echo '</div>';
622 + }
623 +
624 +
625 + public function render_block_content( $attributes, $content, $block_instance ) {
626 + $taxonomy_layout = $attributes['taxonomyLayout'] ?? 'list';
627 + $page_links = $attributes['pageLinks'] ?? 'singlePagelink';
628 + $items_per_row = $attributes['itemsPerRow'] ?? 3;
629 + $active_taxonomy = $attributes['activeTaxonomy'] ?? [];
630 + $selected_terms = $attributes['selectedTerms'] ?? [];
631 + $selected_post_type = $attributes['selectedPostType'] ?? 'post';
632 + $number_of_posts = $attributes['numberOfPosts'] ?? 6;
633 + $post_order = $attributes['postOrder'] ?? 'desc';
634 + $post_order_by = $attributes['postOrderBy'] ?? 'date';
635 + $show_term_count = $attributes['showTermCount'] ?? false;
636 + $enable_reload = $attributes['enableReloadButton'] ?? false;
637 + $allow_icon = $attributes['allowIcon'] ?? false;
638 + $Button_text = $attributes['buttonText'] ?? 'View More';
639 + $tab_view = $attributes['showTab'] ?? false;
640 + $showTabScrolling = $attributes['showTabScrolling'] ?? false;
641 + $icon_class = $attributes['iconClass'] ?? 'far fa-copy';
642 + $icon_svg = $attributes['iconSvgPath'] ?? '';
643 + $icon_url = $attributes['iconImageUrl'] ?? '';
644 + $show_post_link = $attributes['showPostLink'] ?? false;
645 + $show_post = $attributes['showPost'] ?? false;
646 + $show_inherit = $attributes['showInherit'] ?? false;
647 + $show_Count_Prefix = $attributes['showTermCountPrefix'] ?? false;
648 + $showIconDffent = $attributes['showIconDffent'] ?? false;
649 + $count_prefix_text = $attributes['countPrefixText'] ?? 'Items';
650 +
651 + $selected_terms = $this->inherit_selected_terms( $active_taxonomy, $selected_terms, $selected_post_type, $show_inherit );
652 +
653 + ob_start();
654 +
655 + $inline_style = '';
656 + $use_accordion = ( $taxonomy_layout === 'list' && $tab_view );
657 +
658 + $current_post_id = get_queried_object_id();
659 + $current_term_id = 0;
660 + $current_taxonomy = '';
661 + if ( is_category() || is_tag() || is_tax() ) {
662 + $current_term = get_queried_object();
663 + if ( $current_term && ! is_wp_error( $current_term ) ) {
664 + $current_term_id = (int) $current_term->term_id;
665 + $current_taxonomy = (string) $current_term->taxonomy;
666 + }
667 + }
668 +
669 + $showTabScrollingtrue = $showTabScrolling ? 'ablocks-taxonomy-listing-scrolling' : '';
670 +
671 + ?>
672 + <div class="ablocks-taxonomy-listing_<?php echo esc_attr( $taxonomy_layout ); ?> <?php echo esc_attr( $showTabScrollingtrue ); ?>" <?php
673 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
674 + echo $inline_style; ?>>
675 +
676 + <?php
677 + $accordion_index = 1;
678 + $accordion_name = 'ablocks-blower-group-' . ( $attributes['block_id'] ?? '' );
679 +
680 + // Prime term caches for every listed term in one query so the per-term
681 + // get_term()/get_term_link()/get_taxonomy() calls below are served from
682 + // cache instead of hitting the DB per term.
683 + $all_term_ids = [];
684 + foreach ( $active_taxonomy as $prime_taxonomy ) {
685 + foreach ( ( $selected_terms[ $prime_taxonomy ] ?? [] ) as $prime_term_id ) {
686 + $all_term_ids[] = (int) $prime_term_id;
687 + }
688 + }
689 + if ( ! empty( $all_term_ids ) ) {
690 + _prime_term_caches( array_values( array_unique( $all_term_ids ) ) );
691 + }
692 +
693 + foreach ( $active_taxonomy as $taxonomy ) :
694 + $term_ids = $selected_terms[ $taxonomy ] ?? [];
695 +
696 + foreach ( $term_ids as $term_id ) :
697 + $term = get_term( $term_id, $taxonomy );
698 +
699 + if ( ! $term || is_wp_error( $term ) ) {
700 + continue; }
701 +
702 + $query = $this->build_term_query( $taxonomy, (int) $term_id, $selected_post_type, (int) $number_of_posts, $post_order_by, $post_order );
703 + $term_public_count = (int) $query->found_posts;
704 +
705 + $input_id = 'ablocks-blower-' . $accordion_index++;
706 + $should_open = $this->should_open_section( $query, (int) $current_post_id );
707 + if (
708 + $use_accordion &&
709 + $showTabScrolling &&
710 + $current_term_id &&
711 + $current_taxonomy === $taxonomy &&
712 + (int) $term_id === $current_term_id
713 + ) {
714 + $should_open = true;
715 + }
716 +
717 + $term_link = get_term_link( $term );
718 +
719 + $taxonomy = $term->taxonomy;
720 + $tax_obj = get_taxonomy( $taxonomy );
721 + $post_types = ( $tax_obj && ! empty( $tax_obj->object_type ) )
722 + ? array_values( array_unique( $tax_obj->object_type ) )
723 + : 'any';
724 +
725 + $post_ids = get_posts( [
726 + 'post_type' => $post_types,
727 + 'fields' => 'ids',
728 + 'post_status' => 'publish',
729 + 'posts_per_page' => 1,
730 + 'orderby' => $post_order_by,
731 + 'order' => $post_order,
732 + 'ignore_sticky_posts' => true,
733 + 'no_found_rows' => true,
734 + 'tax_query' => [
735 + [
736 + 'taxonomy' => $taxonomy,
737 + 'field' => 'term_id',
738 + 'terms' => (int) $term->term_id,
739 + ],
740 + ],
741 + ] );
742 +
743 + $first_post_id = ! empty( $post_ids ) ? (int) $post_ids[0] : 0;
744 + $first_post_link = $first_post_id ? get_permalink( $first_post_id ) : '';
745 +
746 + $link_url = '';
747 + if ( $show_post_link && ! is_wp_error( $term_link ) ) {
748 + if ( $page_links === 'singlePagelink' && $first_post_link ) {
749 + $link_url = $first_post_link;
750 + } elseif ( $page_links === 'archivePagelink' ) {
751 + $link_url = $term_link;
752 + }
753 + }
754 + ?>
755 +
756 + <?php if ( $use_accordion ) : ?>
757 + <div class="ablocks-taxonomy-blower ablocks-taxonomy-listing-item">
758 + <input type="checkbox" name="<?php echo esc_attr( $accordion_name ); ?>" id="<?php echo esc_attr( $input_id ); ?>" <?php echo $should_open ? 'checked' : ''; ?>>
759 + <?php if ( $link_url ) :
760 + ?><a class="ablocks-taxonomy-title__link" href="<?php echo esc_url( $link_url ); ?>"><?php endif; ?>
761 + <label for="<?php echo esc_attr( $input_id ); ?>" class="ablocks-taxonomy-blower__label ablocks-taxonomy-title">
762 + <?php else : ?>
763 + <div class="ablocks-taxonomy-listing-item">
764 + <?php if ( $link_url ) :
765 + ?><a class="ablocks-taxonomy-title__link" href="<?php echo esc_url( $link_url ); ?>"><?php endif; ?>
766 + <h3 class="ablocks-taxonomy-title">
767 + <?php endif; ?>
768 +
769 + <?php if ( $allow_icon && ( $showIconDffent == true ) ) : ?>
770 + <span class="ablocks-taxonomy-icon">
771 + <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M245,110.64A16,16,0,0,0,232,104H216V88a16,16,0,0,0-16-16H130.67L102.94,51.2a16.14,16.14,0,0,0-9.6-3.2H40A16,16,0,0,0,24,64V208h0a8,8,0,0,0,8,8H211.1a8,8,0,0,0,7.59-5.47l28.49-85.47A16.05,16.05,0,0,0,245,110.64ZM93.34,64,123.2,86.4A8,8,0,0,0,128,88h72v16H69.77a16,16,0,0,0-15.18,10.94L40,158.7V64Zm112,136H43.1l26.67-80H232Z"></path></svg>
772 + </span>
773 + <?php endif; ?>
774 +
775 + <span class="<?php echo $showIconDffent === true ? 'ablocks-taxonomy-listing_direction' : ''; ?>">
776 + <?php if ( $allow_icon && ( $showIconDffent == false ) ) : ?>
777 + <span class="ablocks-taxonomy-icon">
778 + <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M245,110.64A16,16,0,0,0,232,104H216V88a16,16,0,0,0-16-16H130.67L102.94,51.2a16.14,16.14,0,0,0-9.6-3.2H40A16,16,0,0,0,24,64V208h0a8,8,0,0,0,8,8H211.1a8,8,0,0,0,7.59-5.47l28.49-85.47A16.05,16.05,0,0,0,245,110.64ZM93.34,64,123.2,86.4A8,8,0,0,0,128,88h72v16H69.77a16,16,0,0,0-15.18,10.94L40,158.7V64Zm112,136H43.1l26.67-80H232Z"></path></svg>
779 + </span>
780 + <?php endif; ?>
781 +
782 + <?php
783 + echo esc_html( $term->name );
784 +
785 + if ( $show_term_count && ( $showIconDffent == true ) ) :
786 + ?>
787 + <span class="ablocks-taxonomy-title__post-count">
788 +
789 + <?php echo $term_public_count; ?><?php if ( $show_Count_Prefix ) : ?>
790 + <span><?php echo esc_html( $count_prefix_text ); ?></span>
791 + <?php endif; ?>
792 + </span>
793 + <?php endif; ?>
794 + </span>
795 +
796 + <?php if ( $show_term_count && ( $showIconDffent == false ) ) : ?>
797 + <span class="ablocks-taxonomy-title__post-count">
798 + <?php echo $term_public_count; ?><?php if ( $show_Count_Prefix ) : ?>
799 + <span><?php echo esc_html( $count_prefix_text ); ?></span>
800 + <?php endif; ?>
801 + </span>
802 + <?php endif; ?>
803 +
804 + <?php
805 + echo $use_accordion ? '</label>' : '</h3>';
806 +
807 + if ( $link_url ) {
808 + echo '</a>';
809 + }
810 + ?>
811 + <?php if ( $show_post ) :
812 +
813 + echo $use_accordion ? '<div class="ablocks-taxonomy-blower__content ablocks-taxonomy-listing-item_content">' : '<div class="ablocks-taxonomy-listing-item_content">'; ?>
814 +
815 + <?php if ( $query->have_posts() ) : ?>
816 +
817 + <?php
818 +
819 + $this->render_posts_list( $query, $show_post, (int) $current_post_id );
820 +
821 + $this->render_reload_button( (bool) $enable_reload, $term_link, (string) $Button_text );
822 + ?>
823 +
824 + <?php else : ?>
825 + <p><?php echo esc_html__( 'No posts found.', 'ablocks' ); ?></p>
826 + <?php endif; ?>
827 +
828 + </div>
829 + <?php endif; ?>
830 + </div>
831 + <?php endforeach; ?>
832 + <?php endforeach; ?>
833 +
834 +
835 + </div>
836 + <?php
837 + return ob_get_clean();
838 + }
839 +
840 +}