PluginProbe
Advanced Posts Listing – Show Post List Easily / trunk
Advanced Posts Listing – Show Post List Easily vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8
advanced-posts-listing / advanced-posts-listing.php

advanced-posts-listing.php in Advanced Posts Listing – Show Post List Easily trunk, at advanced-posts-listing.php

1,758 lines 88.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Advanced Posts Listing
5 * Plugin URI: https://wordpress.org/plugins/advanced-posts-listing
6 * Description: A Gutenberg block that enables site admins to add & display beautiful blog posts listing / custom post type listing on frontend with live preview in editor.
7 * Requires at least: 6.2
8 * Requires PHP: 7.0
9 * Version: 1.0.8
10 * Author: flippercode
11 * Author URI: https://weplugins.com/
12 * License: GPLv2 or later
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 * Text Domain: advanced-posts-listing
15 * Domain Path: /lang/
16 */
17
18 if (!defined('ABSPATH')) {
19 die('You are not allowed to call this page directly.');
20 }
21
22 if (!class_exists('Advanced_Post_Listing_Block')) {
23
24 class Advanced_Post_Listing_Block
25 {
26
27 public function __construct()
28 {
29 $this->aplb_register_plugin_hooks();
30 }
31
32 function aplb_register_plugin_hooks()
33 {
34 add_action('init', [$this, 'aplb_advance_posts_listing_block_callback']);
35 add_action('rest_api_init', [$this, 'aplb_register_custom_endpoints']);
36 add_action('rest_api_init', [$this, 'aplb_register_custom_rest_fields']);
37 add_action('plugins_loaded', [$this, 'aplb_load_plugin_languages']);
38 add_action('enqueue_block_editor_assets', [$this, 'aplb_get_server_side_pass']);
39 }
40
41 function aplb_load_plugin_languages()
42 {
43
44 load_plugin_textdomain('advanced-posts-listing', false, dirname(plugin_basename(__FILE__)) . '/lang');
45 }
46
47 function aplb_advance_posts_listing_block_callback()
48 {
49 register_block_type(__DIR__ . '/build', array(
50 'render_callback' => array($this, 'aplb_advance_post_listing_block'),
51 ));
52 }
53 function aplb_advance_post_listing_block($attributes)
54 {
55 $post_type_names = strtolower($attributes['selectedCustomPostType']);
56
57 if (strpos($post_type_names, 'pages') !== false || strpos($post_type_names, 'posts') !== false) {
58 if (substr($post_type_names, -1) === 's') {
59 $post_type_names = substr($post_type_names, 0, -1);
60 }
61 }
62
63
64 if (isset($attributes['sortBy'])) {
65
66 switch ($attributes['sortBy']) {
67 case 'new-to-old':
68 $order = 'DESC';
69 $orderby = 'date';
70 break;
71 case 'old-to-new':
72 $order = 'ASC';
73 $orderby = 'date';
74 break;
75 case 'A-Z':
76 $order = 'ASC';
77 $orderby = 'title';
78 break;
79 case 'Z-A':
80 $order = 'DESC';
81 $orderby = 'title';
82 break;
83 default:
84 $order = 'DESC';
85 $orderby = 'date';
86 break;
87 }
88 } else {
89 $orderby = 'date';
90 $order = 'DESC';
91 }
92
93 $post_ids_to_remove = $attributes['RemoveCommaSeparatedIds'] ?? [];
94 $post_ids_to_show = $attributes['commaSeparatedIds'] ?? [];
95
96 $args = array(
97 'posts_per_page' => $attributes['numPostsToShow'] ?? 10,
98 'post_status' => 'publish',
99 // 'post_type' => $post_type_names,
100 // 'ignore_sticky_posts' => true,
101 'order' => $order,
102 'orderby' => $orderby,
103 );
104 if (!empty($post_ids_to_remove) && !empty($post_ids_to_show)) {
105 $post_ids_to_show = array_diff($post_ids_to_show, $post_ids_to_remove);
106 $args['post__in'] = $post_ids_to_show;
107 } elseif (!empty($post_ids_to_show)) {
108 $args['post__in'] = $post_ids_to_show;
109 } elseif (!empty($post_ids_to_remove)) {
110 $args['post__not_in'] = $post_ids_to_remove;
111 }
112 if (!empty($post_ids_to_show)) {
113 $args['post_type'] = 'any';
114 } else {
115 $args['post_type'] = $post_type_names;
116 }
117
118 if (isset($attributes['customTaxonomyPosts']) && !empty($attributes['customTaxonomyPosts'])) {
119
120 $tax_query = array(
121 'relation' => 'AND',
122 );
123
124 foreach ($attributes['customTaxonomyPosts'] as $key => $terms) {
125 if ($key === 'tags') {
126 $taxonomy = 'post_tag';
127 } elseif ($key === 'categories') {
128 $taxonomy = 'category';
129 } else {
130 $taxonomy = $key;
131 }
132 foreach ($terms as $slug) {
133 $tax_query[] = array(
134 'taxonomy' => $taxonomy,
135 'field' => 'slug',
136 'terms' => $slug,
137 );
138 }
139 }
140
141 $args['tax_query'] = $tax_query;
142 }
143
144 if (isset($tax_query)) {
145 $args['tax_query'] = $tax_query;
146 }
147
148 $args = apply_filters('aplb_frontend_query_args', $args);
149 $selectedLayout = $attributes['selectedLayout'];
150 $plugin_url = plugin_dir_url(__FILE__);
151 if (isset($selectedLayout) && !empty($selectedLayout)) {
152 $list_items_markup = null;
153 switch ($selectedLayout) {
154 case 'listing-layout':
155 $list_items_markup = $this->aplb_listing_layout($args, $attributes);
156 break;
157 case 'listing-layout-two':
158 $list_items_markup = $this->aplb_listing_layout_two($args, $attributes);
159 break;
160 case 'grid-layout':
161 $list_items_markup = $this->aplb_grid_layout($args, $attributes);
162 break;
163 case 'overlay-layout':
164 $list_items_markup = $this->aplb_overlay_layout($args, $attributes);
165 break;
166 case 'slider-layout':
167 $list_items_markup = $this->aplb_slider_layout($args, $attributes);
168 break;
169 case 'masonry-layout':
170 $list_items_markup = $this->aplb_masonry_layout($args, $attributes);
171 break;
172 default:
173 $list_items_markup = "Invalid layout selected.";
174 break;
175 }
176 }
177
178 $classes = array('wp-block-latest-posts__list');
179
180 $wrapper_attributes = get_block_wrapper_attributes(array('class' => implode(' ', $classes)));
181
182 return sprintf(
183 '<div %1$s>%2$s</div>',
184 $wrapper_attributes,
185 $list_items_markup
186 );
187 }
188
189
190 function aplb_listing_layout($args, $attributes)
191 {
192
193
194 $title_Manage_styling = !empty($attributes['title_Manage_styling']) ? 'true' : 'false';
195 $title_font_size = !empty($attributes['title_font_size']) ? $attributes['title_font_size'] : '1.5rem';
196
197 $Meta_Manage_styling = !empty($attributes['Meta_Manage_styling']) ? 'true' : 'false';
198 $Meta_font_size = !empty($attributes['Meta_font_size']) ? $attributes['Meta_font_size'] : '0.875rem';
199
200 $Content_Manage_styling = !empty($attributes['Content_Manage_styling']) ? 'true' : 'false';
201 $Content_font_size = !empty($attributes['Content_font_size']) ? $attributes['Content_font_size'] : '1.5rem';
202
203
204 $showReadMoreToggler = !empty($attributes['showReadMoreToggler']) ? 'true' : 'false';
205 $css = '';
206
207 if ($showReadMoreToggler === 'true') {
208 $button_Top_bottom_Padding = !empty($attributes['button_Top_bottom_Padding']) ? $attributes['button_Top_bottom_Padding'] : '8px';
209 $button_Right_Left_Padding = !empty($attributes['button_Right_Left_Padding']) ? $attributes['button_Right_Left_Padding'] : '16px';
210 $ReadMoreTextColor = !empty($attributes['ReadMoreTextColor']) ? $attributes['ReadMoreTextColor'] : '#FFFFFF';
211 $ReadMoreBgColor = !empty($attributes['ReadMoreBgColor']) ? $attributes['ReadMoreBgColor'] : '#000000';
212
213 $css .= '
214 .read-more-button {
215 background-color: ' . $ReadMoreBgColor . '!important;
216 color: ' . $ReadMoreTextColor . ' !important;
217 padding: ' . $button_Top_bottom_Padding . ' ' . $button_Right_Left_Padding . ' !important;
218 }
219 .pagination .page-numbers:hover, .pagination .page-numbers.current {
220 background-color:' . $ReadMoreBgColor . '!important;
221 color: ' . $ReadMoreTextColor . '!important;
222 border-color: ' . $ReadMoreBgColor . '!important;
223 }';
224 }
225 $customCSS = !empty($attributes['customCSS']) ? $attributes['customCSS'] : '';
226
227
228 $row_gap = isset($attributes['rowGap']) && !empty($attributes['rowGap']) ? $attributes['rowGap'] : '30px';
229 $row_gap = str_replace("px", "", $row_gap);
230 $row_gap .= 'px';
231 if (!empty($customCSS)) {
232 $css .= $customCSS;
233 }
234 $css .= '
235 .post-container {
236 margin-bottom: ' . $row_gap . ' !important;
237 }';
238 $css = apply_filters('apl_listing_style', $css, $attributes);
239 $custom_css = "<style>" . $css . "</style>";
240
241 $list_items_markup = '';
242 $list_items_markup .= $custom_css;
243 $list_items_markup .= '<div class="listing-layout">';
244 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
245 $args['paged'] = get_query_var('paged') ? get_query_var('paged') : 1;
246 }
247 $query = new WP_Query($args);
248
249
250 if ($query->have_posts()) :
251 while ($query->have_posts()) : $query->the_post();
252 $post_title = get_the_title();
253 $post_date = get_the_date();
254 $post_permalink = get_permalink();
255 $post_author = get_the_author();
256 $post_categories = get_the_category();
257 $category_names = array();
258
259 if (empty($post_categories)) {
260 $taxonomies = get_object_taxonomies(get_post(), 'names');
261 foreach ($taxonomies as $taxonomy) {
262 $terms = get_the_terms(get_the_ID(), $taxonomy);
263 if ($terms && !is_wp_error($terms)) {
264 foreach ($terms as $term) {
265 $category_names[] = $term->name;
266 }
267 }
268 }
269 } else {
270 foreach ($post_categories as $category) {
271 $category_names[] = $category->name;
272 }
273 }
274
275 $category_list = implode(', ', $category_names);
276 $list_items_markup .= '<div class="post-container">';
277 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'large');
278 if (!empty($image_url)) {
279
280 if (isset($attributes['showImgToggler']) && $attributes['showImgToggler'] == 1) {
281 if (isset($attributes['imageUrl'])) {
282 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'large');
283
284 if (empty($attributes['selectedImageTogggler']) && empty($attributes['widthPercentageState'])) {
285 $custom_width = isset($attributes['ImgWidth']) ? $attributes['ImgWidth'] : '';
286 $custom_height = isset($attributes['height']) ? $attributes['height'] : '';
287 } elseif (isset($attributes['widthPercentageState']) && $attributes['widthPercentageState'] == true && empty($attributes['selectedImageTogggler'])) {
288 $custom_width = $attributes['widthPercentage'];
289 $custom_height = $attributes['widthPercentage'];
290 }
291 }
292 $list_items_markup .= ' <div class="image-container">';
293 if (!empty($custom_width) && !empty($custom_height)) {
294 if (wp_is_mobile()) {
295 $list_items_markup .= '<img class="block-image" src="' . esc_url($image_url) . '" >';
296 } else {
297 $list_items_markup .= '<img class="block-image" src="' . esc_url($image_url) . '" style="max-width: ' . esc_attr($custom_width) . '; max-height: ' . esc_attr($custom_height) . ';">';
298 }
299 } else {
300 $list_items_markup .= '<img class="block-image" src="' . esc_url($image_url) . '">';
301 }
302 $list_items_markup .= ' </div>';
303 }
304 }
305
306 if (isset($attributes['showPostTitle']) && $attributes['showPostTitle'] == 1) {
307 $list_items_markup .= ' <div class="post-title" ';
308 if ($title_Manage_styling === 'true') {
309 $list_items_markup .= ' style="font-size:' . esc_html($title_font_size) . '"';
310 }
311 $list_items_markup .= '>';
312 $list_items_markup .= '<a href="' . esc_url($post_permalink) . '" class="title">' . esc_html($post_title) . '</a>';
313 $list_items_markup .= ' </div>';
314 }
315
316 if (isset($attributes['showMeta']) && $attributes['showMeta'] == 1) {
317 $list_items_markup .= ' <div class="meta-data" ';
318 if ($Meta_Manage_styling === 'true') {
319 $list_items_markup .= ' style="font-size:' . esc_html($Meta_font_size) . '"';
320 }
321 $list_items_markup .= '>';
322 $list_items_markup .= '<p>' . esc_html($post_date) . ' | Author : ' . esc_html($post_author) . ' | Categories: ' . esc_html($category_list) . '</p>';
323 $list_items_markup .= ' </div>';
324 }
325
326 if (isset($attributes['showContent']) && $attributes['showContent'] == 1) {
327 if (isset($attributes['contentType'])) {
328 if ($attributes['contentType'] == 'Excerpt') {
329 $words_limit = isset($attributes['wordsLimit']) ? intval($attributes['wordsLimit']) : 100;
330 $excerpt = get_the_excerpt();
331 $words = explode(' ', $excerpt);
332 $post_content = implode(' ', array_slice($words, 0, $words_limit));
333 } elseif ($attributes['contentType'] == 'Full-Post') {
334 $post_content = get_the_content();
335 }
336 }
337 $list_items_markup .= ' <div class="post-content"';
338 if ($Content_Manage_styling === 'true') {
339 $list_items_markup .= ' style="font-size: ' . esc_html($Content_font_size) . ';"';
340 }
341 $list_items_markup .= ' ><p>';
342 $list_items_markup .= apply_filters('adv_post_content', $post_content);
343 $list_items_markup .= ' </p></div>';
344 }
345
346 $list_items_markup .= ' <div class="read-more-btn">';
347 $list_items_markup .= ' <a target="_blank" href="' . esc_url($post_permalink) . '" class="read-more-button"';
348 $Read_more_font_size = !empty($attributes['Read_more_font_size']) ? $attributes['Read_more_font_size'] : '1rem';
349
350 if ($showReadMoreToggler === 'true') {
351
352 $list_items_markup .= ' style="font-size:' . esc_html($Read_more_font_size) . '"';
353 }
354 $ReadMoreText = !empty($attributes['ReadMoreText']) ? $attributes['ReadMoreText'] : 'Read More';
355 $list_items_markup .= '>' . $ReadMoreText . '</a>';
356 $list_items_markup .= ' </div>';
357 $list_items_markup .= '</div>';
358
359 endwhile;
360
361 // Pagination
362
363 wp_reset_postdata();
364
365 endif;
366
367 $list_items_markup .= '</div>';
368
369 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
370 $pagination_args = array(
371 'total' => $query->max_num_pages,
372 'current' => $args['paged'],
373 'mid_size' => 2,
374 'prev_text' => isset($attributes['prevName']) ? __($attributes['prevName']) : __('Prev'),
375 'next_text' => isset($attributes['nextName']) ? __($attributes['nextName']) : __('Next'),
376 'type' => 'array',
377 );
378
379 $pagination_links = paginate_links($pagination_args);
380
381 if ($pagination_links) {
382 $alignment_class = isset($attributes['paginationAline']) ? $attributes['paginationAline'] : 'center';
383 $list_items_markup .= '<nav class="pagination wep-pagination ' . esc_attr($alignment_class) . '">';
384
385 // Output the pagination links
386 foreach ($pagination_links as $link) {
387 $list_items_markup .= str_replace(
388 array('<a', '</a>', 'page-numbers'),
389 array('<a class="page-numbers"', '</a>', 'page-numbers'),
390 $link
391 );
392 }
393
394 $list_items_markup .= '</nav>';
395 }
396 }
397
398 return $list_items_markup;
399 }
400
401
402 function aplb_listing_layout_two($args, $attributes)
403 {
404
405
406 $title_Manage_styling = !empty($attributes['title_Manage_styling']) ? 'true' : 'false';
407 $title_font_size = !empty($attributes['title_font_size']) ? $attributes['title_font_size'] : '1.5rem';
408
409 $Meta_Manage_styling = !empty($attributes['Meta_Manage_styling']) ? 'true' : 'false';
410 $Meta_font_size = !empty($attributes['Meta_font_size']) ? $attributes['Meta_font_size'] : '0.875rem';
411
412 $Content_Manage_styling = !empty($attributes['Content_Manage_styling']) ? 'true' : 'false';
413 $Content_font_size = !empty($attributes['Content_font_size']) ? $attributes['Content_font_size'] : '1.5rem';
414
415
416 $showReadMoreToggler = !empty($attributes['showReadMoreToggler']) ? 'true' : 'false';
417 $css = '';
418
419 if ($showReadMoreToggler === 'true') {
420 $button_Top_bottom_Padding = !empty($attributes['button_Top_bottom_Padding']) ? $attributes['button_Top_bottom_Padding'] : '8px';
421 $button_Right_Left_Padding = !empty($attributes['button_Right_Left_Padding']) ? $attributes['button_Right_Left_Padding'] : '16px';
422 $ReadMoreTextColor = !empty($attributes['ReadMoreTextColor']) ? $attributes['ReadMoreTextColor'] : '#FFFFFF';
423 $ReadMoreBgColor = !empty($attributes['ReadMoreBgColor']) ? $attributes['ReadMoreBgColor'] : '#000000';
424
425 $css .= '
426 .wep-btn {
427 background-color: ' . $ReadMoreBgColor . '!important;
428 color: ' . $ReadMoreTextColor . ' !important;
429 padding: ' . $button_Top_bottom_Padding . ' ' . $button_Right_Left_Padding . ' !important;
430 }
431 .pagination .page-numbers:hover, .pagination .page-numbers.current {
432 background-color:' . $ReadMoreBgColor . '!important;
433 color: ' . $ReadMoreTextColor . '!important;
434 border-color: ' . $ReadMoreBgColor . '!important;
435 }';
436 }
437 $customCSS = !empty($attributes['customCSS']) ? $attributes['customCSS'] : '';
438
439
440 $row_gap = isset($attributes['rowGap']) && !empty($attributes['rowGap']) ? $attributes['rowGap'] : '30px';
441 $row_gap = str_replace("px", "", $row_gap);
442 $row_gap .= 'px';
443 if (!empty($customCSS)) {
444 $css .= $customCSS;
445 }
446 $css .= '
447 .wep-card-text {
448 margin-bottom: ' . $row_gap . ' !important;
449 }
450 .listing-layout {
451 gap: ' . $row_gap . ' !important;
452 }';
453 $css = apply_filters('apl_listing_style', $css, $attributes);
454 $custom_css = "<style>" . $css . "</style>";
455
456 $list_items_markup = '';
457 $list_items_markup .= $custom_css;
458 $list_items_markup .= '<div class="wep-root"><div class="listing-layout" style="gap: 30px;">';
459 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
460 $args['paged'] = get_query_var('paged') ? get_query_var('paged') : 1;
461 }
462 $query = new WP_Query($args);
463
464
465 if ($query->have_posts()) :
466 while ($query->have_posts()) : $query->the_post();
467 $post_title = get_the_title();
468 $post_date = get_the_date();
469 $post_permalink = get_permalink();
470 $post_author = get_the_author();
471 $post_categories = get_the_category();
472 $category_names = array();
473
474 if (empty($post_categories)) {
475 $taxonomies = get_object_taxonomies(get_post(), 'names');
476 foreach ($taxonomies as $taxonomy) {
477 $terms = get_the_terms(get_the_ID(), $taxonomy);
478 if ($terms && !is_wp_error($terms)) {
479 foreach ($terms as $term) {
480 $category_names[] = $term->name;
481 }
482 }
483 }
484 } else {
485 foreach ($post_categories as $category) {
486 $category_names[] = $category->name;
487 }
488 }
489
490 $category_list = implode(', ', $category_names);
491 $list_items_markup .= '<div class="wep-card wep-card-horizontal">';
492 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'large');
493 if (!empty($image_url)) {
494
495 if (isset($attributes['showImgToggler']) && $attributes['showImgToggler'] == 1) {
496 if (isset($attributes['imageUrl'])) {
497 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'large');
498
499 if (empty($attributes['selectedImageTogggler']) && empty($attributes['widthPercentageState'])) {
500 $custom_width = isset($attributes['ImgWidth']) ? $attributes['ImgWidth'] : '';
501 $custom_height = isset($attributes['height']) ? $attributes['height'] : '';
502 } elseif (isset($attributes['widthPercentageState']) && $attributes['widthPercentageState'] == true && empty($attributes['selectedImageTogggler'])) {
503 $custom_width = $attributes['widthPercentage'];
504 $custom_height = $attributes['widthPercentage'];
505 }
506 }
507 $list_items_markup .= ' <div class="wep-card-img">';
508 if (!empty($custom_width) && !empty($custom_height)) {
509 $list_items_markup .= '<img src="' . esc_url($image_url) . '" style="max-width: ' . esc_attr($custom_width) . '; max-height: ' . esc_attr($custom_height) . ';">';
510 } else {
511 $list_items_markup .= '<img src="' . esc_url($image_url) . '">';
512 }
513 $list_items_markup .= ' </div>';
514 }
515 }
516 $list_items_markup .= '<div class="wep-card-body"><div class="wep-card-heading">';
517 if (isset($attributes['showPostTitle']) && $attributes['showPostTitle'] == 1) {
518 $list_items_markup .= ' <h4 class="wep-card-title" ';
519 if ($title_Manage_styling === 'true') {
520 $list_items_markup .= ' style="font-size:' . esc_html($title_font_size) . '"';
521 }
522 $list_items_markup .= '>';
523 $list_items_markup .= '<a href="' . esc_url($post_permalink) . '" >' . esc_html($post_title) . '</a>';
524 $list_items_markup .= ' </h4>';
525 }
526
527 if (isset($attributes['showMeta']) && $attributes['showMeta'] == 1) {
528 $list_items_markup .= ' <div class="meta-data" ';
529 if ($Meta_Manage_styling === 'true') {
530 $list_items_markup .= ' style="font-size:' . esc_html($Meta_font_size) . '"';
531 }
532 $list_items_markup .= '>';
533 $list_items_markup .= esc_html($post_date) . ' | Author : ' . esc_html($post_author) . ' | Categories: ' . esc_html($category_list);
534 $list_items_markup .= ' </div>';
535 }
536 $list_items_markup .= '</div>';
537 if (isset($attributes['showContent']) && $attributes['showContent'] == 1) {
538 if (isset($attributes['contentType'])) {
539 if ($attributes['contentType'] == 'Excerpt') {
540 $words_limit = isset($attributes['wordsLimit']) ? intval($attributes['wordsLimit']) : 100;
541 $excerpt = get_the_excerpt();
542 $words = explode(' ', $excerpt);
543 $post_content = implode(' ', array_slice($words, 0, $words_limit));
544 } elseif ($attributes['contentType'] == 'Full-Post') {
545 $post_content = get_the_content();
546 }
547 }
548 $list_items_markup .= ' <div class="wep-card-text"';
549 if ($Content_Manage_styling === 'true') {
550 $list_items_markup .= ' style="font-size: ' . esc_html($Content_font_size) . ';"';
551 }
552 $list_items_markup .= ' ><p>';
553 $list_items_markup .= apply_filters('adv_post_content', $post_content);
554 $list_items_markup .= ' </p></div>';
555 }
556 $list_items_markup .= '</div>';
557
558 $list_items_markup .= ' <div class="wep-card-footer">';
559 $list_items_markup .= ' <a target="_blank" href="' . esc_url($post_permalink) . '" class="wep-btn wep-btn-primary"';
560 $Read_more_font_size = !empty($attributes['Read_more_font_size']) ? $attributes['Read_more_font_size'] : '1rem';
561
562 if ($showReadMoreToggler === 'true') {
563
564 $list_items_markup .= ' style="font-size:' . esc_html($Read_more_font_size) . '"';
565 }
566 $ReadMoreText = !empty($attributes['ReadMoreText']) ? $attributes['ReadMoreText'] : 'Read More';
567 $list_items_markup .= '>' . $ReadMoreText . '</a>';
568 $list_items_markup .= ' </div>';
569 $list_items_markup .= '</div>';
570
571 endwhile;
572
573 // Pagination
574
575 wp_reset_postdata();
576
577 endif;
578
579 $list_items_markup .= '</div></div>';
580
581 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
582 $pagination_args = array(
583 'total' => $query->max_num_pages,
584 'current' => $args['paged'],
585 'mid_size' => 2,
586 'prev_text' => isset($attributes['prevName']) ? __($attributes['prevName']) : __('Prev'),
587 'next_text' => isset($attributes['nextName']) ? __($attributes['nextName']) : __('Next'),
588 'type' => 'array',
589 );
590
591 $pagination_links = paginate_links($pagination_args);
592
593 if ($pagination_links) {
594 $alignment_class = isset($attributes['paginationAline']) ? $attributes['paginationAline'] : 'center';
595 $list_items_markup .= '<nav class="pagination wep-pagination ' . esc_attr($alignment_class) . '">';
596
597 // Output the pagination links
598 foreach ($pagination_links as $link) {
599 $list_items_markup .= str_replace(
600 array('<a', '</a>', 'page-numbers'),
601 array('<a class="page-numbers"', '</a>', 'page-numbers'),
602 $link
603 );
604 }
605
606 $list_items_markup .= '</nav>';
607 }
608 }
609
610 return $list_items_markup;
611 }
612
613 function aplb_grid_layout($args, $attributes)
614 {
615
616 $title_Manage_styling = !empty($attributes['title_Manage_styling']) ? 'true' : 'false';
617 $title_font_size = !empty($attributes['title_font_size']) ? $attributes['title_font_size'] : '1.5rem';
618
619 $Meta_Manage_styling = !empty($attributes['Meta_Manage_styling']) ? 'true' : 'false';
620 $Meta_font_size = !empty($attributes['Meta_font_size']) ? $attributes['Meta_font_size'] : '8px';
621
622 $Content_Manage_styling = !empty($attributes['Content_Manage_styling']) ? 'true' : 'false';
623 $Content_font_size = !empty($attributes['Content_font_size']) ? $attributes['Content_font_size'] : '8px';
624
625 $Read_more_font_size = !empty($attributes['Read_more_font_size']) ? $attributes['Read_more_font_size'] : '1rem';
626
627 $showReadMoreToggler = !empty($attributes['showReadMoreToggler']) ? 'true' : 'false';
628 $css = '';
629
630 if ($showReadMoreToggler === 'true') {
631 $button_Top_bottom_Padding = !empty($attributes['button_Top_bottom_Padding']) ? $attributes['button_Top_bottom_Padding'] : '8px';
632 $button_Right_Left_Padding = !empty($attributes['button_Right_Left_Padding']) ? $attributes['button_Right_Left_Padding'] : '16px';
633 $ReadMoreTextColor = !empty($attributes['ReadMoreTextColor']) ? $attributes['ReadMoreTextColor'] : '#FFFFFF';
634 $ReadMoreBgColor = !empty($attributes['ReadMoreBgColor']) ? $attributes['ReadMoreBgColor'] : '#000000';
635
636 $css .= '
637
638 .grid-layout .wep-btn {
639 padding: ' . $button_Top_bottom_Padding . ' ' . $button_Right_Left_Padding . ' !important;
640 background-color:' . $ReadMoreBgColor . '!important;
641 color: ' . $ReadMoreTextColor . '!important;
642 }
643 .pagination .page-numbers:hover, .pagination .page-numbers.current {
644 background-color:' . $ReadMoreBgColor . '!important;
645 color: ' . $ReadMoreTextColor . '!important;
646 border-color: ' . $ReadMoreBgColor . '!important;
647 }
648
649 ';
650 }
651
652
653 $columns = !empty($attributes['totalColoms']) ? $attributes['totalColoms'] : 3;
654 $column_gap = isset($attributes['columnGap']) && !empty($attributes['columnGap']) ? $attributes['columnGap'] : '20px';
655 $row_gap = isset($attributes['rowGap']) && !empty($attributes['rowGap']) ? $attributes['rowGap'] : '30px';
656 $row_gap = str_replace("px", "", $row_gap);
657 $row_gap .= 'px';
658 $column_gap = str_replace("px", "", $column_gap);
659 $column_gap .= 'px';
660
661 $customCSS = !empty($attributes['customCSS']) ? $attributes['customCSS'] : '';
662 if (!empty($customCSS)) {
663 $css .= $customCSS;
664 }
665
666
667 $css .= '
668 .grid-layout {
669 gap: ' . $row_gap . ' ' . $column_gap . ' !important;
670 }
671
672 @media (min-width: 992px) {
673 .grid-layout {
674 grid-template-columns: repeat(' . $columns . ', 1fr) !important;
675 }
676 }
677
678 /* For very large screens */
679 @media (min-width: 1200px) {
680 .grid-layout {
681 grid-template-columns: repeat(' . $columns . ', 1fr) !important;
682 }
683 }
684 ';
685
686
687
688 $css = apply_filters('apl_grid_style', $css, $attributes);
689 $custom_css = "<style>" . $css . "</style>";
690
691 $list_items_markup = '';
692 $list_items_markup .= $custom_css;
693 $list_items_markup .= '<div class="wep-root" ><div class="grid-layout" >';
694 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
695 $args['paged'] = get_query_var('paged') ? get_query_var('paged') : 1;
696 }
697 $query = new WP_Query($args);
698
699 if ($query->have_posts()) :
700 while ($query->have_posts()) : $query->the_post();
701 $post_title = get_the_title();
702 $post_date = get_the_date();
703 $post_permalink = get_permalink();
704 $post_author = get_the_author();
705 $post_categories = get_the_category();
706 $category_names = array();
707
708 if (empty($post_categories)) {
709 $taxonomies = get_object_taxonomies(get_post(), 'names');
710 foreach ($taxonomies as $taxonomy) {
711 $terms = get_the_terms(get_the_ID(), $taxonomy);
712 if ($terms && !is_wp_error($terms)) {
713 foreach ($terms as $term) {
714 $category_names[] = $term->name;
715 }
716 }
717 }
718 } else {
719 foreach ($post_categories as $category) {
720 $category_names[] = $category->name;
721 }
722 }
723
724 $category_list = implode(', ', $category_names);
725 $list_items_markup .= '<div class="wep-card">';
726 if (isset($attributes['showImgToggler']) && $attributes['showImgToggler'] == 1) {
727 if (isset($attributes['imageUrl'])) {
728 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'medium');
729
730 if (empty($attributes['selectedImageTogggler']) && empty($attributes['widthPercentageState'])) {
731 $custom_width = isset($attributes['ImgWidth']) ? $attributes['ImgWidth'] : '';
732 $custom_height = isset($attributes['height']) ? $attributes['height'] : '';
733 } elseif (isset($attributes['widthPercentageState']) && $attributes['widthPercentageState'] == true && empty($attributes['selectedImageTogggler'])) {
734 $custom_width = $attributes['widthPercentage'];
735 $custom_height = $attributes['widthPercentage'];
736 }
737 }
738 if (isset($image_url) && !empty($image_url)) {
739 $list_items_markup .= ' <div class="wep-card-img">';
740 if (!empty($custom_width) && !empty($custom_height)) {
741 $list_items_markup .= '<img src="' . esc_url($image_url) . '">';
742 } else {
743 $list_items_markup .= '<img src="' . esc_url($image_url) . '">';
744 }
745 $list_items_markup .= ' <span class="wep-chip">' . esc_html($category_list) . '</span>';
746 $list_items_markup .= ' </div>';
747 }
748 }
749
750 $list_items_markup .= '<div class="wep-card-body"><div class="wep-card-heading">';
751 if (isset($attributes['showPostTitle']) && $attributes['showPostTitle'] == 1) {
752 $list_items_markup .= ' <h4 class="wep-card-title" ';
753 if ($title_Manage_styling === 'true') {
754 $list_items_markup .= ' style="font-size:' . esc_html($title_font_size) . '"';
755 }
756 $list_items_markup .= '>';
757 $list_items_markup .= ' <a href="' . esc_url($post_permalink) . '">' . esc_html($post_title) . '</a>';
758 $list_items_markup .= ' </h4>';
759 }
760
761 if (isset($attributes['showMeta']) && $attributes['showMeta'] == 1) {
762 $list_items_markup .= ' <div class="meta-data" ';
763 if ($Meta_Manage_styling === 'true') {
764 $list_items_markup .= ' style="font-size:' . esc_html($Meta_font_size) . '"';
765 }
766 $list_items_markup .= '>';
767 $list_items_markup .= '<p>' . esc_html($post_date) . ' | Author : ' . esc_html($post_author) . '</p>';
768 $list_items_markup .= ' </div>';
769 }
770 $list_items_markup .= '</div>';
771 if (isset($attributes['showContent']) && $attributes['showContent'] == 1) {
772 if (isset($attributes['contentType'])) {
773 if ($attributes['contentType'] == 'Excerpt') {
774 $words_limit = isset($attributes['wordsLimit']) ? intval($attributes['wordsLimit']) : 100;
775 $excerpt = get_the_excerpt();
776 $words = explode(' ', $excerpt);
777 $post_content = implode(' ', array_slice($words, 0, $words_limit));
778 } elseif ($attributes['contentType'] == 'Full-Post') {
779 $post_content = get_the_content();
780 }
781 }
782 $list_items_markup .= ' <div class="wep-card-text"';
783 if ($Content_Manage_styling === 'true') {
784 $list_items_markup .= ' style="font-size: ' . esc_html($Content_font_size) . ';"';
785 }
786 $list_items_markup .= ' ><p>';
787 $list_items_markup .= apply_filters('adv_post_content', $post_content);
788 $list_items_markup .= ' </p></div>';
789 }
790 $list_items_markup .= '</div>';
791
792 $list_items_markup .= ' <div class="wep-card-footer">';
793 $list_items_markup .= ' <a target="_blank" href="' . esc_url($post_permalink) . '" class="wep-btn wep-btn-primary"';
794 if ($showReadMoreToggler === 'true') {
795 $list_items_markup .= ' style="font-size:' . esc_html($Read_more_font_size) . '"';
796 }
797 $ReadMoreText = !empty($attributes['ReadMoreText']) ? $attributes['ReadMoreText'] : 'Read More';
798 $list_items_markup .= '>' . $ReadMoreText . '</a>';
799 $list_items_markup .= ' </div>';
800 $list_items_markup .= '</div>';
801
802 endwhile;
803
804
805 wp_reset_postdata();
806
807 endif;
808
809 $list_items_markup .= '</div></div>';
810 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
811 $pagination_args = array(
812 'total' => $query->max_num_pages,
813 'current' => $args['paged'],
814 'mid_size' => 2,
815 'prev_text' => isset($attributes['prevName']) ? __($attributes['prevName']) : __('Prev'),
816 'next_text' => isset($attributes['nextName']) ? __($attributes['nextName']) : __('Next'),
817 'type' => 'array',
818 );
819
820 $pagination_links = paginate_links($pagination_args);
821 if ($pagination_links) {
822 $alignment_class = isset($attributes['paginationAline']) ? $attributes['paginationAline'] : 'center';
823 $list_items_markup .= '<nav class="pagination wep-pagination ' . esc_attr($alignment_class) . '">';
824
825 // Output the pagination links
826 foreach ($pagination_links as $link) {
827 $list_items_markup .= str_replace(
828 array('<a', '</a>', 'page-numbers'),
829 array('<a class="page-numbers"', '</a>', 'page-numbers'),
830 $link
831 );
832 }
833
834 $list_items_markup .= '</nav>';
835 }
836 }
837 return $list_items_markup;
838 }
839
840 function aplb_overlay_layout($args, $attributes)
841 {
842
843 $title_Manage_styling = !empty($attributes['title_Manage_styling']) ? 'true' : 'false';
844 $title_font_size = !empty($attributes['title_font_size']) ? $attributes['title_font_size'] : '1.5rem';
845
846 $Meta_Manage_styling = !empty($attributes['Meta_Manage_styling']) ? 'true' : 'false';
847 $Meta_font_size = !empty($attributes['Meta_font_size']) ? $attributes['Meta_font_size'] : '8px';
848
849 $Content_Manage_styling = !empty($attributes['Content_Manage_styling']) ? 'true' : 'false';
850 $Content_font_size = !empty($attributes['Content_font_size']) ? $attributes['Content_font_size'] : '8px';
851
852 $Read_more_font_size = !empty($attributes['Read_more_font_size']) ? $attributes['Read_more_font_size'] : '1rem';
853
854 $showReadMoreToggler = !empty($attributes['showReadMoreToggler']) ? 'true' : 'false';
855 $css = '';
856
857 if ($showReadMoreToggler === 'true') {
858 $button_Top_bottom_Padding = !empty($attributes['button_Top_bottom_Padding']) ? $attributes['button_Top_bottom_Padding'] : '8px';
859 $button_Right_Left_Padding = !empty($attributes['button_Right_Left_Padding']) ? $attributes['button_Right_Left_Padding'] : '16px';
860 $ReadMoreTextColor = !empty($attributes['ReadMoreTextColor']) ? $attributes['ReadMoreTextColor'] : '#FFFFFF';
861 $ReadMoreBgColor = !empty($attributes['ReadMoreBgColor']) ? $attributes['ReadMoreBgColor'] : '#000000';
862
863 $css .= '
864 .overlay-layout .wep-btn {
865 padding: ' . $button_Top_bottom_Padding . ' ' . $button_Right_Left_Padding . ' !important;
866
867 background-color:' . $ReadMoreBgColor . '!important;
868 color: ' . $ReadMoreTextColor . '!important;
869
870 }
871 .pagination .page-numbers:hover, .pagination .page-numbers.current {
872 background-color:' . $ReadMoreBgColor . '!important;
873 color: ' . $ReadMoreTextColor . '!important;
874 border-color:' . $ReadMoreBgColor . '!important;
875 }
876 ';
877 }
878
879
880 $columns = !empty($attributes['totalColoms']) ? $attributes['totalColoms'] : 3;
881 $width_percentage = 100 / $columns;
882 $column_gap = isset($attributes['columnGap']) && !empty($attributes['columnGap']) ? $attributes['columnGap'] : '20px';
883 $row_gap = isset($attributes['rowGap']) && !empty($attributes['rowGap']) ? $attributes['rowGap'] : '30px';
884 $row_gap = str_replace("px", "", $row_gap);
885 $row_gap .= 'px';
886 $column_gap = str_replace("px", "", $column_gap);
887 $column_gap .= 'px';
888 $customCSS = !empty($attributes['customCSS']) ? $attributes['customCSS'] : '';
889 if (!empty($customCSS)) {
890 $css .= $customCSS;
891 }
892
893 if (wp_is_mobile()) {
894 $css .= '
895 .overlay-layout{
896 gap: ' . $row_gap . ' ' . $column_gap . ' !important;
897 grid-template-columns: repeat(1, 1fr);
898 }';
899 } else {
900 $css .= '
901 .overlay-layout{
902 gap: ' . $row_gap . ' ' . $column_gap . ' !important;
903 grid-template-columns: repeat(' . $attributes["totalColoms"] . ', 1fr);
904 }';
905 }
906
907
908 $css = apply_filters('wpl_overlay_style', $css, $attributes);
909 $custom_css = "<style>" . $css . "</style>";
910
911
912 $list_items_markup = '';
913 $list_items_markup .= $custom_css;
914
915 $list_items_markup .= '<div class="wep-root"><div class="overlay-layout">';
916 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
917 $args['paged'] = get_query_var('paged') ? get_query_var('paged') : 1;
918 }
919
920 $query = new WP_Query($args);
921
922 if ($query->have_posts()) :
923 while ($query->have_posts()) : $query->the_post();
924 $post_title = get_the_title();
925 $post_date = get_the_date();
926 $post_permalink = get_permalink();
927 $post_author = get_the_author();
928 $post_categories = get_the_category();
929 $category_names = array();
930
931 if (empty($post_categories)) {
932 $taxonomies = get_object_taxonomies(get_post(), 'names');
933 foreach ($taxonomies as $taxonomy) {
934 $terms = get_the_terms(get_the_ID(), $taxonomy);
935 if ($terms && !is_wp_error($terms)) {
936 foreach ($terms as $term) {
937 $category_names[] = $term->name;
938 }
939 }
940 }
941 } else {
942 foreach ($post_categories as $category) {
943 $category_names[] = $category->name;
944 }
945 }
946
947 $category_list = implode(', ', $category_names);
948 if (isset($attributes['showImgToggler']) && $attributes['showImgToggler'] == 1) {
949 if (isset($attributes['imageUrl'])) {
950 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'medium');
951
952 if (empty($attributes['selectedImageTogggler']) && empty($attributes['widthPercentageState'])) {
953 $custom_width = isset($attributes['ImgWidth']) ? $attributes['ImgWidth'] : '';
954 $custom_height = isset($attributes['height']) ? $attributes['height'] : '';
955 } elseif (isset($attributes['widthPercentageState']) && $attributes['widthPercentageState'] == true && empty($attributes['selectedImageTogggler'])) {
956 $custom_width = $attributes['widthPercentage'];
957 $custom_height = $attributes['widthPercentage'];
958 }
959 }
960 if (!empty($custom_width) && !empty($custom_height)) {
961 $list_items_markup .= ' <div class="wep-card" style = "background-image:url(' . esc_url($image_url) . ');background-repeat: no-repeat;
962 background-size: cover;">';
963 } else {
964 $list_items_markup .= ' <div class="wep-card" style = "background-image:url(' . esc_url($image_url) . ');background-repeat: no-repeat; background-size: cover;">';
965 }
966 $list_items_markup .= ' <div class="wep-card-img-overlay">';
967 $list_items_markup .= ' <div class="wep-card-body"><div class="wep-card-heading">';
968 }
969
970 if (isset($attributes['showPostTitle']) && $attributes['showPostTitle'] == 1) {
971 $list_items_markup .= ' <h4 class="wep-card-title" ';
972 if ($title_Manage_styling === 'true') {
973 $list_items_markup .= ' style="font-size:' . esc_html($title_font_size) . '"';
974 }
975 $list_items_markup .= '>';
976 $list_items_markup .= '<a href="' . esc_url($post_permalink) . '" class="title">' . esc_html($post_title) . '</a>';
977 $list_items_markup .= ' </h4>';
978 }
979
980 if (isset($attributes['showMeta']) && $attributes['showMeta'] == 1) {
981 $list_items_markup .= ' <div class="meta-data" ';
982 if ($Meta_Manage_styling === 'true') {
983 $list_items_markup .= ' style="font-size:' . esc_html($Meta_font_size) . '"';
984 }
985 $list_items_markup .= '>';
986 $list_items_markup .= '<p>' . esc_html($post_date) . ' | Author : ' . esc_html($post_author) . ' | Categories: ' . esc_html($category_list) . '</p>';
987 $list_items_markup .= ' </div>';
988 }
989 $list_items_markup .= ' </div>';
990 if (isset($attributes['showContent']) && $attributes['showContent'] == 1) {
991 if (isset($attributes['contentType'])) {
992 if ($attributes['contentType'] == 'Excerpt') {
993 $words_limit = isset($attributes['wordsLimit']) ? intval($attributes['wordsLimit']) : 100;
994 $excerpt = get_the_excerpt();
995 $words = explode(' ', $excerpt);
996 $post_content = implode(' ', array_slice($words, 0, $words_limit)) . '...';
997 } elseif ($attributes['contentType'] == 'Full-Post') {
998 $post_content = get_the_content();
999 }
1000 }
1001 $list_items_markup .= ' <div class="wep-card-text"';
1002 if ($Content_Manage_styling === 'true') {
1003 $list_items_markup .= ' style="font-size: ' . esc_html($Content_font_size) . ';"';
1004 }
1005 $list_items_markup .= ' ><p>';
1006 $list_items_markup .= apply_filters('adv_post_content', $post_content);
1007 $list_items_markup .= ' </p></div>';
1008 }
1009 $list_items_markup .= '</div>';
1010 $list_items_markup .= ' <div class="wep-card-footer">';
1011 $list_items_markup .= ' <a target="_blank" href="' . esc_url($post_permalink) . '" class="wep-btn wep-btn-primary"';
1012 if ($showReadMoreToggler === 'true') {
1013 $list_items_markup .= ' style="font-size:' . esc_html($Read_more_font_size) . '"';
1014 }
1015 $ReadMoreText = !empty($attributes['ReadMoreText']) ? $attributes['ReadMoreText'] : 'Read More';
1016 $list_items_markup .= '>' . $ReadMoreText . '</a>';
1017 $list_items_markup .= ' </div>';
1018 $list_items_markup .= ' </div>';
1019 $list_items_markup .= ' </div>';
1020
1021 endwhile;
1022 wp_reset_postdata();
1023
1024 endif;
1025
1026 $list_items_markup .= '</div></div>';
1027
1028 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
1029
1030 $pagination_args = array(
1031 'total' => $query->max_num_pages,
1032 'current' => $args['paged'],
1033 'mid_size' => 2,
1034 'prev_text' => isset($attributes['prevName']) ? __($attributes['prevName']) : __('Prev'),
1035 'next_text' => isset($attributes['nextName']) ? __($attributes['nextName']) : __('Next'),
1036 'type' => 'array',
1037 );
1038
1039 $pagination_links = paginate_links($pagination_args);
1040
1041 if ($pagination_links) {
1042 $alignment_class = isset($attributes['paginationAline']) ? $attributes['paginationAline'] : 'center';
1043 $list_items_markup .= '<nav class="pagination wep-pagination ' . esc_attr($alignment_class) . '">';
1044
1045 // Output the pagination links
1046 foreach ($pagination_links as $link) {
1047 $list_items_markup .= str_replace(
1048 array('<a', '</a>', 'page-numbers'),
1049 array('<a class="page-numbers"', '</a>', 'page-numbers'),
1050 $link
1051 );
1052 }
1053
1054 $list_items_markup .= '</nav>';
1055 }
1056 }
1057
1058 return $list_items_markup;
1059 }
1060
1061 function aplb_slider_layout($args, $attributes)
1062 {
1063
1064 $title_Manage_styling = !empty($attributes['title_Manage_styling']) ? 'true' : 'false';
1065 $title_font_size = !empty($attributes['title_font_size']) ? $attributes['title_font_size'] : '1.5rem';
1066
1067 $Meta_Manage_styling = !empty($attributes['Meta_Manage_styling']) ? 'true' : 'false';
1068 $Meta_font_size = !empty($attributes['Meta_font_size']) ? $attributes['Meta_font_size'] : '8px';
1069
1070 $Content_Manage_styling = !empty($attributes['Content_Manage_styling']) ? 'true' : 'false';
1071 $Content_font_size = !empty($attributes['Content_font_size']) ? $attributes['Content_font_size'] : '8px';
1072
1073 $Read_more_font_size = !empty($attributes['Read_more_font_size']) ? $attributes['Read_more_font_size'] : '1rem';
1074
1075 $showReadMoreToggler = !empty($attributes['showReadMoreToggler']) ? 'true' : 'false';
1076 $css = '';
1077
1078 if ($showReadMoreToggler === 'true') {
1079 $button_Top_bottom_Padding = !empty($attributes['button_Top_bottom_Padding']) ? $attributes['button_Top_bottom_Padding'] : '8px';
1080 $button_Right_Left_Padding = !empty($attributes['button_Right_Left_Padding']) ? $attributes['button_Right_Left_Padding'] : '16px';
1081 $ReadMoreTextColor = !empty($attributes['ReadMoreTextColor']) ? $attributes['ReadMoreTextColor'] : '#FFFFFF';
1082 $ReadMoreBgColor = !empty($attributes['ReadMoreBgColor']) ? $attributes['ReadMoreBgColor'] : '#000000';
1083 $css .= '
1084 .slider-container .wep-btn {
1085 padding: ' . $button_Top_bottom_Padding . ' ' . $button_Right_Left_Padding . ' !important;
1086
1087 background-color:' . $ReadMoreBgColor . '!important;
1088 color: ' . $ReadMoreTextColor . '!important;
1089
1090 }
1091 ';
1092 }
1093 $customCSS = !empty($attributes['customCSS']) ? $attributes['customCSS'] : '';
1094
1095 if (!empty($customCSS)) {
1096 $css .= $customCSS;
1097 }
1098
1099 $css = apply_filters('apl_slider_style', $css, $attributes);
1100 $custom_css = "<style>" . $css . "</style>";
1101 $list_items_markup = '';
1102 $list_items_markup .= $custom_css;
1103 $list_items_markup .= '<div class="wep-root"><div class="slider-container">';
1104 $list_items_markup .= '<div class="slider">';
1105 $query = new WP_Query($args);
1106 if ($query->have_posts()) :
1107 while ($query->have_posts()) : $query->the_post();
1108 $post_title = get_the_title();
1109 $post_date = get_the_date();
1110 $post_permalink = get_permalink();
1111 $post_author = get_the_author();
1112 $post_categories = get_the_category();
1113 $category_names = array();
1114 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'large');
1115 if (empty($post_categories)) {
1116 $taxonomies = get_object_taxonomies(get_post(), 'names');
1117 foreach ($taxonomies as $taxonomy) {
1118 $terms = get_the_terms(get_the_ID(), $taxonomy);
1119 if ($terms && !is_wp_error($terms)) {
1120 foreach ($terms as $term) {
1121 $category_names[] = $term->name;
1122 }
1123 }
1124 }
1125 } else {
1126 foreach ($post_categories as $category) {
1127 $category_names[] = $category->name;
1128 }
1129 }
1130
1131 $category_list = implode(', ', $category_names);
1132 $list_items_markup .= '<div class="slide">';
1133 $list_items_markup .= '<div class="wep-card">';
1134 if (isset($attributes['showImgToggler']) && $attributes['showImgToggler'] == 1) {
1135 if ($image_url) {
1136
1137 if (isset($attributes['imageUrl'])) {
1138 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'large');
1139
1140 if (empty($attributes['selectedImageTogggler']) && empty($attributes['widthPercentageState'])) {
1141 $custom_width = isset($attributes['ImgWidth']) ? $attributes['ImgWidth'] : '';
1142 $custom_height = isset($attributes['height']) ? $attributes['height'] : '';
1143 } elseif (isset($attributes['widthPercentageState']) && $attributes['widthPercentageState'] == true && empty($attributes['selectedImageTogggler'])) {
1144 $custom_width = $attributes['widthPercentage'];
1145 $custom_height = $attributes['widthPercentage'];
1146 }
1147 $list_items_markup .= ' <div class="wep-card-img">';
1148 if (!empty($custom_width) && !empty($custom_height)) {
1149 $list_items_markup .= '<img src="' . esc_url($image_url) . '">';
1150 } else {
1151 $list_items_markup .= '<img src="' . esc_url($image_url) . '">';
1152 }
1153 $list_items_markup .= ' </div>';
1154 }
1155 }
1156 }
1157
1158 $list_items_markup .= '<div class="wep-card-body"><div class="wep-card-heading">';
1159 if (isset($attributes['showPostTitle']) && $attributes['showPostTitle'] == 1) {
1160 $list_items_markup .= ' <h4 class="wep-card-title" ';
1161 if ($title_Manage_styling === 'true') {
1162 $list_items_markup .= ' style="font-size:' . esc_html($title_font_size) . '"';
1163 }
1164 $list_items_markup .= '>';
1165 $list_items_markup .= '<a href="' . esc_url($post_permalink) . '">' . esc_html($post_title) . '</a>';
1166 $list_items_markup .= ' </h4>';
1167 }
1168
1169 if (isset($attributes['showMeta']) && $attributes['showMeta'] == 1) {
1170 $list_items_markup .= ' <div class="meta-data" ';
1171 if ($Meta_Manage_styling === 'true') {
1172 $list_items_markup .= ' style="font-size:' . esc_html($Meta_font_size) . '"';
1173 }
1174 $list_items_markup .= '>';
1175 $list_items_markup .= '<p>' . esc_html($post_date) . ' | Author : ' . esc_html($post_author) . ' | Categories: ' . esc_html($category_list) . '</p>';
1176 $list_items_markup .= ' </div>';
1177 }
1178
1179 $list_items_markup .= '</div>';
1180 if (isset($attributes['showContent']) && $attributes['showContent'] == 1) {
1181 if (isset($attributes['contentType'])) {
1182 if ($attributes['contentType'] == 'Excerpt') {
1183 $words_limit = isset($attributes['wordsLimit']) ? intval($attributes['wordsLimit']) : 100;
1184 $excerpt = get_the_excerpt();
1185 $words = explode(' ', $excerpt);
1186 $post_content = implode(' ', array_slice($words, 0, $words_limit));
1187 } elseif ($attributes['contentType'] == 'Full-Post') {
1188 $post_content = get_the_content();
1189 }
1190 }
1191 $list_items_markup .= ' <div class="wep-card-text"';
1192 if ($Content_Manage_styling === 'true') {
1193 $list_items_markup .= ' style="font-size: ' . esc_html($Content_font_size) . ';"';
1194 }
1195 $list_items_markup .= ' ><p>';
1196 $list_items_markup .= apply_filters('adv_post_content', $post_content);
1197 $list_items_markup .= ' </p></div>';
1198 }
1199 $list_items_markup .= '</div>';
1200
1201 $list_items_markup .= ' <div class="wep-card-footer">';
1202 $list_items_markup .= ' <a target="_blank" href="' . esc_url($post_permalink) . '" class="wep-btn wep-btn-primary"';
1203 if ($showReadMoreToggler === 'true') {
1204 $list_items_markup .= ' style="font-size:' . esc_html($Read_more_font_size) . '"';
1205 }
1206 $ReadMoreText = !empty($attributes['ReadMoreText']) ? $attributes['ReadMoreText'] : 'Read More';
1207 $list_items_markup .= '>' . $ReadMoreText . '</a>';
1208 $list_items_markup .= ' </div>';
1209 $list_items_markup .= '</div>';
1210 $list_items_markup .= '</div>';
1211 endwhile;
1212 wp_reset_postdata();
1213
1214 endif;
1215
1216 $list_items_markup .= '</div>';
1217 $list_items_markup .= ' <button class="slider-button prev">❮</button>';
1218 $list_items_markup .= ' <button class="slider-button next">❯</button>';
1219 $list_items_markup .= '</div>';
1220 $list_items_markup .= '</div></div>';
1221
1222 $js = "document.addEventListener('DOMContentLoaded', function() {
1223 let currentIndex = 0;
1224 const slides = document.querySelectorAll('.slide');
1225
1226 function showSlide(index) {
1227 slides.forEach((slide, i) => {
1228 slide.style.display = i === index ? 'block' : 'none';
1229 });
1230 }
1231
1232 function nextSlide() {
1233 currentIndex = (currentIndex + 1) % slides.length;
1234 showSlide(currentIndex);
1235 }
1236
1237 function prevSlide() {
1238 currentIndex = (currentIndex - 1 + slides.length) % slides.length;
1239 showSlide(currentIndex);
1240 }
1241
1242 document.querySelector('.next').addEventListener('click', nextSlide);
1243 document.querySelector('.prev').addEventListener('click', prevSlide);
1244
1245 setInterval(nextSlide, 3000);
1246
1247 showSlide(currentIndex);
1248 });";
1249
1250 $js = apply_filters('apl_slider_script', $js, $attributes);
1251 $custom_js = "<script>" . $js . "</script>";
1252 $list_items_markup .= $custom_js;
1253
1254
1255 return $list_items_markup;
1256 }
1257
1258 function aplb_masonry_layout($args, $attributes)
1259 {
1260
1261 $title_Manage_styling = !empty($attributes['title_Manage_styling']) ? 'true' : 'false';
1262 $title_font_size = !empty($attributes['title_font_size']) ? $attributes['title_font_size'] : '1.5rem';
1263
1264 $Meta_Manage_styling = !empty($attributes['Meta_Manage_styling']) ? 'true' : 'false';
1265 $Meta_font_size = !empty($attributes['Meta_font_size']) ? $attributes['Meta_font_size'] : '8px';
1266
1267 $Content_Manage_styling = !empty($attributes['Content_Manage_styling']) ? 'true' : 'false';
1268 $Content_font_size = !empty($attributes['Content_font_size']) ? $attributes['Content_font_size'] : '8px';
1269
1270 $Read_more_font_size = !empty($attributes['Read_more_font_size']) ? $attributes['Read_more_font_size'] : '1rem';
1271
1272 $showReadMoreToggler = !empty($attributes['showReadMoreToggler']) ? 'true' : 'false';
1273 $css = '';
1274
1275 if ($showReadMoreToggler === 'true') {
1276 $button_Top_bottom_Padding = !empty($attributes['button_Top_bottom_Padding']) ? $attributes['button_Top_bottom_Padding'] : '8px';
1277 $button_Right_Left_Padding = !empty($attributes['button_Right_Left_Padding']) ? $attributes['button_Right_Left_Padding'] : '16px';
1278 $ReadMoreTextColor = !empty($attributes['ReadMoreTextColor']) ? $attributes['ReadMoreTextColor'] : '#FFFFFF';
1279 $ReadMoreBgColor = !empty($attributes['ReadMoreBgColor']) ? $attributes['ReadMoreBgColor'] : '#000000';
1280
1281 $css .= '
1282 .masonry-layout .wep-btn {
1283 padding: ' . $button_Top_bottom_Padding . ' ' . $button_Right_Left_Padding . ' !important;
1284
1285 background-color:' . $ReadMoreBgColor . '!important;
1286 color: ' . $ReadMoreTextColor . '!important ;
1287
1288 }
1289 .pagination .page-numbers:hover, .pagination .page-numbers.current {
1290 background-color:' . $ReadMoreBgColor . '!important;
1291 color: ' . $ReadMoreTextColor . '!important;
1292 border-color: ' . $ReadMoreBgColor . '!important;
1293 }
1294
1295 ';
1296 }
1297
1298 $customCSS = !empty($attributes['customCSS']) ? $attributes['customCSS'] : '';
1299
1300 $columns = !empty($attributes['totalColoms']) ? $attributes['totalColoms'] : 3;
1301 $column_gap = isset($attributes['columnGap']) && !empty($attributes['columnGap']) ? $attributes['columnGap'] : '20px';
1302 $row_gap = isset($attributes['rowGap']) && !empty($attributes['rowGap']) ? $attributes['rowGap'] : '30px';
1303 $row_gap = str_replace("px", "", $row_gap);
1304 $row_gap .= 'px';
1305 $column_gap = str_replace("px", "", $column_gap);
1306 $column_gap .= 'px';
1307 if (!empty($customCSS)) {
1308 $css .= $customCSS;
1309 }
1310
1311 if (wp_is_mobile()) {
1312 $css .= '.masonry-layout {
1313 column-gap: ' . $column_gap . ' !important;
1314 column-count: 1;
1315 }';
1316 } else {
1317 $css .= '.masonry-layout {
1318 column-gap: ' . $column_gap . ' !important;
1319 column-count: ' . $attributes["totalColoms"] . ';
1320 }';
1321 }
1322
1323 $css .= '
1324 .masonry-layout .wep-card-text {
1325 margin-bottom: ' . $row_gap . ' !important;
1326 }
1327 @media (min-width: 992px) {
1328 .masonry-layout {
1329 column-count: ' . $columns . ' !important;
1330 }
1331 }
1332
1333 .pagination{
1334 margin-top: ' . $row_gap . ' !important;
1335 }
1336 /* Extra large screens (large desktops, 1200px and up) */
1337 @media (min-width: 1200px) {
1338 .masonry-layout {
1339 column-count: ' . $columns . ' !important;
1340 }
1341 }
1342
1343 ';
1344
1345 $css = apply_filters('apl_masanory_style', $css, $attributes);
1346 $custom_css = "<style> " . $css . " </style>";
1347 $list_items_markup = '';
1348 $list_items_markup .= $custom_css;
1349 $list_items_markup .= '<div class="wep-root" ><div class="masonry-layout">';
1350 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
1351 $args['paged'] = get_query_var('paged') ? get_query_var('paged') : 1;
1352 }
1353 $query = new WP_Query($args);
1354
1355 if ($query->have_posts()) :
1356 while ($query->have_posts()) : $query->the_post();
1357 $post_title = get_the_title();
1358 $post_date = get_the_date();
1359 $post_permalink = get_permalink();
1360 $post_author = get_the_author();
1361 $post_categories = get_the_category();
1362 $category_names = array();
1363
1364 if (empty($post_categories)) {
1365 $taxonomies = get_object_taxonomies(get_post(), 'names');
1366 foreach ($taxonomies as $taxonomy) {
1367 $terms = get_the_terms(get_the_ID(), $taxonomy);
1368 if ($terms && !is_wp_error($terms)) {
1369 foreach ($terms as $term) {
1370 $category_names[] = $term->name;
1371 }
1372 }
1373 }
1374 } else {
1375 foreach ($post_categories as $category) {
1376 $category_names[] = $category->name;
1377 }
1378 }
1379
1380 $category_list = implode(', ', $category_names);
1381 $list_items_markup .= '<div class="wep-card" style="margin-bottom: 30px;">';
1382 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'medium');
1383 if (!empty($image_url)) {
1384 if (isset($attributes['showImgToggler']) && $attributes['showImgToggler'] == 1) {
1385 if (isset($attributes['imageUrl'])) {
1386 $image_url = get_the_post_thumbnail_url(get_the_ID(), 'medium');
1387
1388 if (empty($attributes['selectedImageTogggler']) && empty($attributes['widthPercentageState'])) {
1389 $custom_width = isset($attributes['ImgWidth']) ? $attributes['ImgWidth'] : '';
1390 $custom_height = isset($attributes['height']) ? $attributes['height'] : '';
1391 } elseif (isset($attributes['widthPercentageState']) && $attributes['widthPercentageState'] == true && empty($attributes['selectedImageTogggler'])) {
1392 $custom_width = $attributes['widthPercentage'];
1393 $custom_height = $attributes['widthPercentage'];
1394 }
1395 }
1396 $list_items_markup .= ' <div class="wep-card-img">';
1397 if (!empty($custom_width) && !empty($custom_height)) {
1398 $list_items_markup .= '<img src="' . esc_url($image_url) . '">';
1399 } else {
1400 $list_items_markup .= '<img src="' . esc_url($image_url) . '">';
1401 }
1402 $list_items_markup .= '<span class="wep-chip">' . $category_list . '</span> </div>';
1403 }
1404 }
1405 $list_items_markup .= '<div class="wep-card-body"><div class="wep-card-heading">';
1406 if (isset($attributes['showPostTitle']) && $attributes['showPostTitle'] == 1) {
1407 $list_items_markup .= ' <h4 class="wep-card-title" ';
1408 if ($title_Manage_styling === 'true') {
1409 $list_items_markup .= ' style="font-size:' . esc_html($title_font_size) . '"';
1410 }
1411 $list_items_markup .= '>';
1412 $list_items_markup .= '<a href="' . esc_url($post_permalink) . '" >' . esc_html($post_title) . '</a>';
1413 $list_items_markup .= ' </h4>';
1414 }
1415
1416
1417 if (isset($attributes['showMeta']) && $attributes['showMeta'] == 1) {
1418 $list_items_markup .= ' <div class="meta-data" ';
1419 if ($Meta_Manage_styling === 'true') {
1420 $list_items_markup .= ' style="font-size:' . esc_html($Meta_font_size) . '"';
1421 }
1422 $list_items_markup .= '>';
1423 $list_items_markup .= '<p>' . esc_html($post_date) . ' | Author : ' . esc_html($post_author) . ' | Categories: ' . esc_html($category_list) . '</p>';
1424 $list_items_markup .= ' </div>';
1425 }
1426 $list_items_markup .= '</div>';
1427 if (isset($attributes['showContent']) && $attributes['showContent'] == 1) {
1428 if (isset($attributes['contentType'])) {
1429 if ($attributes['contentType'] == 'Excerpt') {
1430 $words_limit = isset($attributes['wordsLimit']) ? intval($attributes['wordsLimit']) : 100;
1431 $excerpt = get_the_excerpt();
1432 $words = explode(' ', $excerpt);
1433 $post_content = implode(' ', array_slice($words, 0, $words_limit));
1434 } elseif ($attributes['contentType'] == 'Full-Post') {
1435 $post_content = get_the_content();
1436 }
1437 }
1438 $list_items_markup .= ' <div class="wep-card-text"';
1439 if ($Content_Manage_styling === 'true') {
1440 $list_items_markup .= ' style="font-size: ' . esc_html($Content_font_size) . ';"';
1441 }
1442 $list_items_markup .= ' ><p>';
1443 $list_items_markup .= apply_filters('adv_post_content', $post_content);
1444 $list_items_markup .= ' </p></div>';
1445 }
1446 $list_items_markup .= '</div>';
1447
1448 $list_items_markup .= ' <div class="wep-card-footer">';
1449 $list_items_markup .= ' <a target="_blank" class="wep-btn wep-btn-primary" href="' . esc_url($post_permalink) . '"';
1450 if ($showReadMoreToggler === 'true') {
1451 $list_items_markup .= ' style="font-size:' . esc_html($Read_more_font_size) . '"';
1452 }
1453 $ReadMoreText = !empty($attributes['ReadMoreText']) ? $attributes['ReadMoreText'] : 'Read More';
1454 $list_items_markup .= '>' . $ReadMoreText . '</a>';
1455 $list_items_markup .= ' </div>';
1456 $list_items_markup .= '</div>';
1457
1458 endwhile;
1459 wp_reset_postdata();
1460
1461 endif;
1462
1463 $list_items_markup .= '</div></div>';
1464 if (isset($attributes['PaginationOnToggler']) && !empty($attributes['PaginationOnToggler'])) {
1465
1466 $pagination_args = array(
1467 'total' => $query->max_num_pages,
1468 'current' => $args['paged'],
1469 'mid_size' => 2,
1470 'prev_text' => isset($attributes['prevName']) ? __($attributes['prevName']) : __('Prev'),
1471 'next_text' => isset($attributes['nextName']) ? __($attributes['nextName']) : __('Next'),
1472 'type' => 'array',
1473 );
1474
1475 $pagination_links = paginate_links($pagination_args);
1476
1477 if ($pagination_links) {
1478 $alignment_class = isset($attributes['paginationAline']) ? $attributes['paginationAline'] : 'center';
1479 $list_items_markup .= '<nav class="pagination wep-pagination ' . esc_attr($alignment_class) . '">';
1480
1481 // Output the pagination links
1482 foreach ($pagination_links as $link) {
1483 $list_items_markup .= str_replace(
1484 array('<a', '</a>', 'page-numbers'),
1485 array('<a class="page-numbers"', '</a>', 'page-numbers'),
1486 $link
1487 );
1488 }
1489
1490 $list_items_markup .= '</nav>';
1491 }
1492 }
1493
1494 return $list_items_markup;
1495 }
1496
1497 function aplb_register_custom_endpoints()
1498 {
1499 register_rest_route(
1500 'wpppro/v1',
1501 '/list-cpt/',
1502 array(
1503 'methods' => 'GET',
1504 'callback' => array($this, 'aplb_get_custom_post_types_and_tax'),
1505 'permission_callback' => '__return_true',
1506 )
1507 );
1508
1509 register_rest_route(
1510 'wpppro/v1',
1511 '/get-post-by-id/',
1512 array(
1513 'methods' => 'GET',
1514 'callback' => array($this, 'aplb_get_posts_type_by_id'),
1515 'permission_callback' => '__return_true',
1516 )
1517 );
1518 }
1519
1520 function aplb_get_posts_type_by_id($request)
1521 {
1522 $id = $request['id'];
1523 $id_array = explode(',', $id);
1524
1525 $args = array(
1526 'post_type' => 'any',
1527 'post__in' => $id_array,
1528 'orderby' => 'post__in',
1529 'posts_per_page' => -1,
1530 );
1531
1532
1533 $query = new WP_Query($args);
1534
1535 $posts_data = array();
1536
1537 if ($query->have_posts()) {
1538 while ($query->have_posts()) {
1539 $query->the_post();
1540 $post_id = get_the_ID();
1541
1542 // Prepare the post data array
1543 $post_data = array(
1544 'id' => $post_id,
1545 'date' => get_the_date('c'),
1546 'date_gmt' => get_gmt_from_date(get_the_date('Y-m-d H:i:s')),
1547 'guid' => array('rendered' => get_the_guid()),
1548 'modified' => get_the_modified_date('c'),
1549 'modified_gmt' => get_gmt_from_date(get_the_modified_date('Y-m-d H:i:s')),
1550 'slug' => get_post_field('post_name', $post_id),
1551 'status' => get_post_status($post_id),
1552 'type' => get_post_type($post_id),
1553 'link' => get_permalink($post_id),
1554 'title' => array('rendered' => get_the_title($post_id)),
1555 'content' => array('rendered' => apply_filters('the_content', get_the_content($post_id)), 'protected' => false),
1556 'featured_media' => get_post_thumbnail_id($post_id),
1557 'template' => get_page_template_slug($post_id),
1558 'meta' => get_post_meta($post_id),
1559 'featured_image_url' => array(
1560 'thumbnail' => get_the_post_thumbnail_url($post_id, 'thumbnail'),
1561 'medium' => get_the_post_thumbnail_url($post_id, 'medium'),
1562 'medium_large' => get_the_post_thumbnail_url($post_id, 'medium_large'),
1563 'large' => get_the_post_thumbnail_url($post_id, 'large'),
1564 '1536x1536' => get_the_post_thumbnail_url($post_id, '1536x1536'),
1565 '2048x2048' => get_the_post_thumbnail_url($post_id, '2048x2048')
1566 ),
1567 'post_author' => get_the_author_meta('display_name', get_post_field('post_author', $post_id)),
1568 'assigned_categories' => wp_get_post_categories($post_id, array('fields' => 'names')),
1569 );
1570
1571 $posts_data[] = $post_data;
1572 }
1573 }
1574
1575 wp_reset_postdata();
1576
1577 return new WP_REST_Response($posts_data, 200);
1578 }
1579
1580
1581 function aplb_get_custom_post_types_and_tax()
1582 {
1583 $args = array('public' => true, '_builtin' => false);
1584
1585 $custom_post_types = get_post_types($args, 'objects');
1586
1587 $cpt_minial_info = [];
1588
1589 if ($custom_post_types) {
1590
1591 foreach ($custom_post_types as $post_type) {
1592 $cpt_minial_info[$post_type->name] = $post_type->label;
1593 }
1594 }
1595
1596 $custom_post_types = $cpt_minial_info;
1597
1598 $post_type_taxonomies = array();
1599
1600 $all_cpts = array_merge(array('post' => 'Posts', 'page' => 'Pages'), $custom_post_types);
1601
1602 foreach ($all_cpts as $post_type => $postName) {
1603
1604 $taxonomies = get_object_taxonomies($post_type, 'objects');
1605
1606 $taxonomy_info = array();
1607
1608 foreach ($taxonomies as $taxonomy) {
1609
1610 $taxonomy_info[] = array(
1611 'slug' => $taxonomy->name,
1612 'label' => $taxonomy->label,
1613 );
1614 }
1615
1616
1617 $post_type_taxonomies[$post_type] = $taxonomy_info;
1618 }
1619
1620 $response = array('cpt_list' => $custom_post_types, 'post_type_and_taxonomies' => $post_type_taxonomies);
1621
1622 return rest_ensure_response($response);
1623 }
1624
1625 // Register REST fields for various post types
1626
1627 function aplb_register_custom_rest_fields()
1628 {
1629
1630 $post_types = get_post_types(array('public' => true, '_builtin' => false), 'names', 'and');
1631 $post_types = array_merge($post_types, array('post', 'page'));
1632
1633 foreach ($post_types as $post_type) {
1634
1635 $this->aplb_register_featured_image_rest_field($post_type);
1636 $this->aplb_register_author_rest_field($post_type);
1637 $this->aplb_register_assigned_categories_rest_field($post_type);
1638 }
1639 }
1640
1641 // Register 'featured_image_url' REST field
1642 function aplb_register_featured_image_rest_field($post_type)
1643 {
1644
1645 register_rest_field($post_type, 'featured_image_url', array(
1646 'get_callback' => array($this, 'aplb_get_featured_image_callback'),
1647 'schema' => array(
1648 'description' => esc_html__('Featured Image', 'advanced-posts-listing'),
1649 'type' => 'string'
1650 ),
1651 ));
1652 }
1653
1654 function aplb_get_featured_image_callback($post)
1655 {
1656
1657 $featured_image_id = get_post_thumbnail_id($post['id']);
1658 $image_sizes = get_intermediate_image_sizes();
1659 $all_sizes = array();
1660
1661 if (!empty($image_sizes)) {
1662 foreach ($image_sizes as $size) {
1663 $image_url = wp_get_attachment_image_src($featured_image_id, $size);
1664 if (isset($image_url[0])) {
1665 $all_sizes[$size] = $image_url[0];
1666 }
1667 }
1668 }
1669
1670 return $all_sizes;
1671 }
1672
1673 function aplb_register_author_rest_field($post_type)
1674 {
1675
1676 register_rest_field($post_type, 'post_author', array(
1677 'get_callback' => array($this, 'aplb_get_author_callback'),
1678 'schema' => array(
1679 'description' => esc_html__('Author Name', 'advanced-posts-listing'),
1680 'type' => 'string'
1681 ),
1682 ));
1683 }
1684
1685 function aplb_get_author_callback($post)
1686 {
1687
1688 $author_name = '';
1689
1690 if (isset($post['author']) && !empty($post['author'])) {
1691 $author = get_userdata($post['author']);
1692
1693 if ($author && !is_wp_error($author)) {
1694 if ($author->first_name && $author->last_name) {
1695 $author_name = $author->first_name . ' ' . $author->last_name;
1696 } elseif ($author->display_name) {
1697 $author_name = $author->display_name;
1698 } else {
1699 $author_name = $author->user_login;
1700 }
1701 }
1702 }
1703
1704 return $author_name;
1705 }
1706
1707 function aplb_register_assigned_categories_rest_field($post_type)
1708 {
1709
1710 register_rest_field($post_type, 'assigned_categories', array(
1711 'get_callback' => array($this, 'aplb_get_assigned_categories_callback'),
1712 'schema' => array(
1713 'description' => esc_html__('Assigned Categories', 'advanced-posts-listing'),
1714 'type' => 'string'
1715 ),
1716 ));
1717 }
1718
1719 function aplb_get_assigned_categories_callback($post)
1720 {
1721
1722 $categories = get_the_category($post['id']);
1723 $category_names = array();
1724
1725 if (empty($categories)) {
1726 $post_id = $post['id'];
1727 $post_type = $post['type'];
1728 $taxonomies = get_object_taxonomies($post_type);
1729
1730 foreach ($taxonomies as $taxonomy) {
1731 $terms = wp_get_post_terms($post_id, $taxonomy);
1732 if (!empty($terms)) {
1733 foreach ($terms as $term) {
1734 $category_names[] = $term->name;
1735 }
1736 }
1737 }
1738 $category_names = array_unique($category_names);
1739 } else {
1740 foreach ($categories as $category) {
1741 $category_names[] = $category->name;
1742 }
1743 }
1744
1745 return implode(', ', $category_names);
1746 }
1747
1748 function aplb_get_server_side_pass()
1749 {
1750 wp_localize_script('advanced-posts-listing-advanced-posts-listing-block-editor-script', 'aplb_server_data', array(
1751 'rest_url' => esc_url(get_rest_url(null)),
1752 ));
1753 }
1754 }
1755
1756 return new Advanced_Post_Listing_Block();
1757 }
1758