PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 3.2.0
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v3.2.0
3.2.0 3.1.0 3.0.0 2.13.2 2.13.1 2.13.0 trunk 1.0.0 2.1.0 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.1 2.5.3 2.5.4 2.5.5 All 57 releases
← All changes | build/blocks/post-slider/render.php +10 -308 2.5.1 → 3.2.0 View file →
@@ -1,314 +1,16 @@
1 1 <?php
2 2 /**
3 - * Render the post slider block.
4 - *
3 + * Render the Blog Post block.
4 + *
5 + * The work (query, cache, markup, schema) lives in \GutSlider\Blocks\PostSlider, which
6 + * the "Load more" endpoint uses too.
7 + *
8 + * @param array $attributes The block attributes.
5 9 */
6 10
7 11 // Exit if accessed directly.
8 -if( ! defined( 'ABSPATH' ) ) exit;
12 +if ( ! defined( 'ABSPATH' ) ) {
13 + exit;
14 +}
9 15
10 - if( ! function_exists( 'gutslider_post_slider' ) ) {
11 -
12 - function gutslider_post_slider( $attributes ) {
13 -
14 - // block attributes: Post Query
15 - $queryPosts = isset( $attributes['queryPosts'] ) ? $attributes['queryPosts'] : [];
16 -
17 - // block attributes
18 - $showTitle = isset( $attributes['showTitle'] ) ? $attributes['showTitle'] : true;
19 - $showCat = isset( $attributes['showCat'] ) ? $attributes['showCat'] : true;
20 - $showExcerpt = isset( $attributes['showExcerpt'] ) ? $attributes['showExcerpt'] : true;
21 - $showBtn = isset( $attributes['showBtn'] ) ? $attributes['showBtn'] : true;
22 - $linkTitle = isset( $attributes['linkTitle'] ) ? $attributes['linkTitle'] : true;
23 - $titleTag = isset( $attributes['titleTag'] ) ? $attributes['titleTag'] : 'h2';
24 - $btnLabel = isset( $attributes['btnLabel'] ) ? $attributes['btnLabel'] : 'Read More';
25 - $enableOverlay = isset( $attributes['enableOverlay'] ) ? $attributes['enableOverlay'] : true;
26 - $sliderType = isset( $attributes['sliderType'] ) ? $attributes['sliderType'] : 'slider';
27 - $uniqueId = isset( $attributes['uniqueId'] ) ? $attributes['uniqueId'] : '';
28 - $navContainerPosition = isset( $attributes['navContainerPosition'] ) ? $attributes['navContainerPosition'] : 'nav_inside';
29 - $navPosition = isset( $attributes['navPosition'] ) ? $attributes['navPosition'] : 'nav_cc';
30 -
31 - // animation
32 - $catAnimation = isset( $attributes['catAnimation'] ) ? $attributes['catAnimation'] : '';
33 - $titleAnimation = isset( $attributes['titleAnimation'] ) ? $attributes['titleAnimation'] : '';
34 - $exptAnimation = isset( $attributes['exptAnimation'] ) ? $attributes['exptAnimation'] : '';
35 - $btnAnimation = isset( $attributes['btnAnimation'] ) ? $attributes['btnAnimation'] : '';
36 -
37 - // slider options
38 - $sliderOptions = isset( $attributes['sliderOptions'] ) ? $attributes['sliderOptions'] : [];
39 - $showNavigation = isset( $attributes['showNavigation'] ) ? $attributes['showNavigation'] : true;
40 - $showPagination = isset( $attributes['showPagination'] ) ? $attributes['showPagination'] : true;
41 - $customNavIcon = isset( $attributes['customNavIcon'] ) ? $attributes['customNavIcon'] : false;
42 - $navIconSource = isset( $attributes['navIconSource'] ) ? $attributes['navIconSource'] : 'library';
43 - $navPrevIcon = isset( $attributes['navPrevIcon'] ) ? $attributes['navPrevIcon'] : 'arrowLeft';
44 - $navNextIcon = isset( $attributes['navNextIcon'] ) ? $attributes['navNextIcon'] : 'arrowRight';
45 - $customPrevSVG = isset( $attributes['customPrevSVG'] ) ? $attributes['customPrevSVG'] : '';
46 - $customNextSVG = isset( $attributes['customNextSVG'] ) ? $attributes['customNextSVG'] : '';
47 - $excerptLength = isset( $attributes['excerptLength'] ) ? $attributes['excerptLength'] : 20;
48 -
49 - // block classes
50 - $blockClasses = [ $uniqueId, $navContainerPosition, $navPosition ];
51 - // block wrapper attributes
52 - $blockProps = get_block_wrapper_attributes([
53 - 'class' => implode( ' ', $blockClasses )
54 - ]);
55 -
56 - // single block classes
57 - $swiperClasses = implode( ' ', [
58 - 'swiper-slide',
59 - $sliderType === 'slider' ? 'slide-mode' : ''
60 - ]);
61 -
62 - // block inner html sliderOptions
63 - ?>
64 - <div <?php echo $blockProps; ?> data-swiper-options="<?php echo esc_attr( wp_json_encode( $sliderOptions ) ); ?>">
65 - <div class="swiper">
66 - <div class="swiper-wrapper">
67 - <?php
68 - if( is_array( $queryPosts ) && ! empty( $queryPosts ) ) {
69 -
70 - foreach ($queryPosts as $post ) {
71 -
72 - $postTitle = isset( $post['title']['rendered'] ) ? $post['title']['rendered'] : '';
73 - $postExcerpt = isset( $post['excerpt']['rendered'] ) ? $post['excerpt']['rendered'] : '';
74 - $postLink = isset( $post['link'] ) ? $post['link'] : '';
75 - $postImageId = isset( $post['featured_media'] ) ? $post['featured_media'] : '';
76 - $postImage = wp_get_attachment_image_url( $postImageId, 'full', false );
77 - $bgStyle = !empty( $postImage ) ? 'background-image: url(' . esc_url( $postImage ) . ');' : '';
78 - $postCategories = isset( $post['categories'] ) ? $post['categories'] : [];
79 -
80 - ?>
81 -
82 - <div class="<?php echo esc_attr( $swiperClasses ); ?>">
83 - <div class="swiper-container-outer" style="<?php echo $bgStyle; ?>">
84 - <?php
85 - if( $enableOverlay ) {
86 - ?>
87 - <div class="gutslider-overlay"></div>
88 - <?php
89 - }
90 - ?>
91 - <div class="gutslider-content-wrapper">
92 - <div class="gutslider-content-inner">
93 - <?php
94 - // post categories
95 - if( $showCat ) {
96 - ?>
97 - <div class="post-categories <?php echo esc_attr( $catAnimation ); ?>">
98 - <?php
99 - if( is_array( $postCategories ) && ! empty( $postCategories ) ) {
100 - foreach ($postCategories as $category ) {
101 - $catId = isset( $category ) ? $category : '';
102 - $category = get_category( $catId );
103 - ?>
104 - <span class="post-category">
105 - <?php
106 - echo esc_html( $category->name );
107 - ?>
108 - </span>
109 - <?php
110 - }
111 - }
112 - ?>
113 - </div>
114 - <?php
115 - }
116 -
117 - // post title
118 - if( $showTitle ) {
119 - if( $linkTitle ) {
120 - ?>
121 - <a href="<?php echo esc_url( $postLink ); ?>" class="post-title">
122 - <<?php echo esc_attr( $titleTag ); ?> class="post-title <?php echo esc_attr( $titleAnimation ); ?>">
123 - <?php
124 - echo esc_html( $postTitle );
125 - ?>
126 - </<?php echo esc_attr( $titleTag ); ?>>
127 - </a>
128 - <?php
129 - } else {
130 - ?>
131 - <<?php echo esc_attr( $titleTag ); ?> class="post-title <?php echo esc_attr( $titleAnimation ); ?>">
132 - <?php
133 - echo esc_html( $postTitle );
134 - ?>
135 - </<?php echo esc_attr( $titleTag ); ?>>
136 - <?php
137 - }
138 - }
139 -
140 - // post excerpt
141 - if( $showExcerpt ) {
142 - ?>
143 - <div class="post-excerpt <?php echo esc_attr( $exptAnimation ); ?>">
144 - <?php
145 - if( $excerptLength > 0 ) {
146 - $postExcerpt = wp_trim_words( $postExcerpt, $excerptLength, '...' );
147 - }
148 - echo wp_kses( $postExcerpt, wp_kses_allowed_html( 'post' ) );
149 - ?>
150 - </div>
151 - <?php
152 - }
153 -
154 - // post button
155 - if( $showBtn ) {
156 - ?>
157 - <div class="post-cta-wrapper <?php echo esc_attr( $btnAnimation ); ?>">
158 - <a href="<?php echo esc_url( $postLink ); ?>" class="post-cta">
159 - <?php
160 - echo esc_html( $btnLabel );
161 - ?>
162 - </a>
163 - </div>
164 - <?php
165 - }
166 - ?>
167 - </div>
168 - </div>
169 - </div>
170 - </div>
171 - <?php
172 - }
173 -
174 - }
175 - ?>
176 - </div>
177 - <?php
178 - if( $showNavigation === true && $navContainerPosition === 'nav_inside' ) {
179 - ?>
180 - <div class="gutslider-nav nav_inside <?php echo esc_attr( $navPosition ); ?>">
181 - <?php
182 - if( $customNavIcon ) {
183 - ?>
184 - <div class="gutslider-prev">
185 - <?php
186 - if( $navIconSource === 'library' ) {
187 - ?>
188 - <div class="gutslider-prev-icon">
189 - <?php
190 - echo gutslider_display_icon( $navPrevIcon );
191 - ?>
192 - </div>
193 - <?php
194 - } else {
195 - ?>
196 - <div class="gutslider-prev-icon">
197 - <?php
198 - echo $customPrevSVG;
199 - ?>
200 - </div>
201 - <?php
202 - }
203 - ?>
204 - </div>
205 - <div class="gutslider-next">
206 - <?php
207 - if( $navIconSource === 'library' ) {
208 - ?>
209 - <div class="gutslider-next-icon">
210 - <?php
211 - echo gutslider_display_icon( $navNextIcon );
212 - ?>
213 - </div>
214 - <?php
215 - } else {
216 - ?>
217 - <div class="gutslider-next-icon">
218 - <?php
219 - echo $customNextSVG;
220 - ?>
221 - </div>
222 - <?php
223 - }
224 - ?>
225 - </div>
226 - <?php
227 - }else {
228 - ?>
229 - <div class="swiper-button-prev"></div>
230 - <div class="swiper-button-next"></div>
231 - <?php
232 - }
233 - ?>
234 - </div>
235 - <?php
236 - }
237 - ?>
238 - <?php
239 - if( $showPagination ) {
240 - ?>
241 - <div class="swiper-pagination"></div>
242 - <?php
243 - }
244 - ?>
245 - </div>
246 - <?php
247 - if( $showNavigation === true && $navContainerPosition === 'nav_outside' ) {
248 - ?>
249 - <div class="gutslider-nav nav_outside <?php echo esc_attr( $navPosition ); ?>">
250 - <?php
251 - if( $customNavIcon ) {
252 - ?>
253 - <div class="gutslider-prev">
254 - <?php
255 - if( $navIconSource === 'library' ) {
256 - ?>
257 - <div class="gutslider-prev-icon">
258 - <?php
259 - echo gutslider_display_icon( $navPrevIcon );
260 - ?>
261 - </div>
262 - <?php
263 - } else {
264 - ?>
265 - <div class="gutslider-prev-icon">
266 - <?php
267 - echo $customPrevSVG;
268 - ?>
269 - </div>
270 - <?php
271 - }
272 - ?>
273 - </div>
274 - <div class="gutslider-next">
275 - <?php
276 - if( $navIconSource === 'library' ) {
277 - ?>
278 - <div class="gutslider-next-icon">
279 - <?php
280 - echo gutslider_display_icon( $navNextIcon );
281 - ?>
282 - </div>
283 - <?php
284 - } else {
285 - ?>
286 - <div class="gutslider-next-icon">
287 - <?php
288 - echo $customNextSVG;
289 - ?>
290 - </div>
291 - <?php
292 - }
293 - ?>
294 - </div>
295 - <?php
296 - }else {
297 - ?>
298 - <div class="swiper-button-prev"></div>
299 - <div class="swiper-button-next"></div>
300 - <?php
301 - }
302 - ?>
303 - </div>
304 - <?php
305 - }
306 - ?>
307 - </div>
308 - <?php
309 - }
310 -
311 - }
312 -
313 - // call the render callback function
314 - gutslider_post_slider( $attributes );
16 +echo \GutSlider\Blocks\PostSlider::render( $attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped