PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 2.1.7
bBlocks – Essential Gutenberg Blocks & Patterns Collection v2.1.7
2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 107 releases
b-blocks / build / news-ticker / render.php

render.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 2.1.7, at build/news-ticker/render.php

115 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render
4 */
5
6 $post_type = isset( $attributes['postType'] ) ? $attributes['postType'] : 'post';
7 $selected_posts = isset( $attributes['selectedPosts'] ) ? $attributes['selectedPosts'] : array();
8 $selected_categories = isset( $attributes['selectedCategories'] ) ? $attributes['selectedCategories'] : array();
9 $select_all_categories = isset( $attributes['selectAllCategories'] ) ? $attributes['selectAllCategories'] : false;
10 $speed = isset( $attributes['speed'] ) ? $attributes['speed'] : 50;
11 $enable_click = isset( $attributes['enableClick'] ) ? $attributes['enableClick'] : true;
12 $text_color = isset( $attributes['textColor'] ) ? $attributes['textColor'] : '#ffffff';
13 $background_color = isset( $attributes['backgroundColor'] ) ? $attributes['backgroundColor'] : '#667eea';
14 $font_size = isset( $attributes['fontSize'] ) ? $attributes['fontSize'] : 15;
15 $font_weight = isset( $attributes['fontWeight'] ) ? $attributes['fontWeight'] : '400';
16 $font_family = isset( $attributes['fontFamily'] ) ? $attributes['fontFamily'] : '';
17 $heading_text = isset( $attributes['headingText'] ) ? $attributes['headingText'] : __( 'News:', 'news-ticker' );
18
19 if ( $select_all_categories && ! empty( $selected_categories ) ) {
20 $taxonomies = get_object_taxonomies( $post_type, 'objects' );
21 $tax_query = array();
22
23 if ( ! empty( $taxonomies ) ) {
24 foreach ( $taxonomies as $taxonomy ) {
25 if ( $taxonomy->publicly_queryable ) {
26 $tax_query[] = array(
27 'taxonomy' => $taxonomy->name,
28 'field' => 'term_id',
29 'terms' => $selected_categories,
30 );
31 break;
32 }
33 }
34 }
35
36 $args = array(
37 'post_type' => $post_type,
38 'posts_per_page' => -1,
39 'post_status' => 'publish',
40 'orderby' => 'date',
41 'order' => 'DESC',
42 );
43
44 if ( ! empty( $tax_query ) ) {
45 $args['tax_query'] = $tax_query;
46 }
47 } elseif ( ! empty( $selected_posts ) ) {
48 $args = array(
49 'post_type' => $post_type,
50 'post__in' => $selected_posts,
51 'posts_per_page' => -1,
52 'post_status' => 'publish',
53 'orderby' => 'post__in',
54 );
55 } else {
56 return;
57 }
58
59 $query = new WP_Query( $args );
60
61 if ( ! $query->have_posts() ) {
62 return;
63 }
64
65 $wrapper_attributes = get_block_wrapper_attributes( array(
66 'data-speed' => esc_attr( $speed ),
67 'data-enable-click' => esc_attr( $enable_click ? '1' : '0' ),
68 'style' => sprintf(
69 'background-color: %s; color: %s;',
70 esc_attr( $background_color ),
71 esc_attr( $text_color )
72 ),
73 ) );
74
75 $item_style = sprintf(
76 'color: %s; font-size: %spx; font-weight: %s;%s',
77 esc_attr( $text_color ),
78 esc_attr( $font_size ),
79 esc_attr( $font_weight ),
80 $font_family ? ' font-family: ' . esc_attr( $font_family ) . ';' : ''
81 );
82
83 $item_class = $enable_click ? 'news-ticker-item' : 'news-ticker-item no-click';
84 ?>
85
86 <div <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() is properly escaped ?>>
87
88 <div class="news-ticker-wrapper">
89 <div class="news-ticker-label" style="background-color: rgba(0, 0, 0, 0.2); color: <?php echo esc_attr( $text_color ); ?>;">
90 <?php echo esc_html( $heading_text ); ?>
91 </div>
92 <div class="news-ticker-content">
93 <div class="news-ticker-items" style="--ticker-speed: <?php echo esc_attr( $speed ); ?>s;">
94 <?php
95 while ( $query->have_posts() ) {
96 $query->the_post();
97 ?>
98 <span class="<?php echo esc_attr( $item_class ); ?>" style="<?php echo esc_attr( $item_style ); ?>">
99 <?php if ( $enable_click ) : ?>
100 <a href="<?php echo esc_url( get_permalink() ); ?>">
101 <?php echo esc_html( get_the_title() ); ?>
102 </a>
103 <?php else : ?>
104 <?php echo esc_html( get_the_title() ); ?>
105 <?php endif; ?>
106 </span>
107 <?php
108 }
109 wp_reset_postdata();
110 ?>
111 </div>
112 </div>
113 </div>
114 </div>
115