-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathrender.php
More file actions
52 lines (47 loc) · 1.13 KB
/
render.php
File metadata and controls
52 lines (47 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Render callback for the Key Takeaways block.
*
* @var array $attributes Block attributes.
* @var string $content Block content.
* @var WP_Block $block Block instance.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$block_title = $attributes['title'] ?? '';
$layout = $attributes['render'] ?? 'list';
$takeaways = $attributes['takeaways'] ?? [];
// If there are no takeaways, don't render the block.
if ( empty( $takeaways ) ) {
return;
}
?>
<div <?php echo get_block_wrapper_attributes(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php if ( $block_title ) : ?>
<h2 class="wp-block-heading wp-block-classifai-key-takeaways__title">
<?php echo wp_kses_post( $block_title ); ?>
</h2>
<?php endif; ?>
<div class="wp-block-classifai-key-takeaways__content">
<?php
if ( 'list' === $layout ) {
echo '<ul>';
foreach ( (array) $takeaways as $takeaway ) {
printf(
'<li>%s</li>',
esc_html( $takeaway )
);
}
echo '</ul>';
} else {
foreach ( (array) $takeaways as $takeaway ) {
printf(
'<p>%s</p>',
esc_html( $takeaway )
);
}
}
?>
</div>
</div>