PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.5.2
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.5.2
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / modules / tiny-list / module.php

module.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.5.2, at modules/tiny-list/module.php

134 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\TinyList;
3 use UltimatePostKit\Traits\Global_Widget_Functions;
4
5 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
6 use UltimatePostKit\Utils;
7
8 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
9
10 class Module extends Ultimate_Post_Kit_Module_Base {
11
12 use Global_Widget_Functions;
13
14 public function __construct() {
15 parent::__construct();
16
17 add_action( 'wp_ajax_nopriv_upk_tiny_list_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
18 add_action( 'wp_ajax_upk_tiny_list_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 }
20
21 public function get_name() {
22 return 'tiny-list';
23 }
24
25 public function get_widgets() {
26
27 $widgets = [
28 'Tiny_List',
29 ];
30
31 return $widgets;
32 }
33
34 public function callback_ajax_loadmore_posts() {
35 // Verify the front-end nonce (sent by UltimatePostKitConfig.nonce) before
36 // processing this public load-more request.
37 if ( ! check_ajax_referer( 'upk-site', 'nonce', false ) ) {
38 wp_send_json_error( array( 'message' => esc_html__( 'Security check failed.', 'ultimate-post-kit' ) ), 403 );
39 }
40
41
42 $settings = [];
43
44 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
45 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
46 }
47
48 // $post_type = $settings['posts_source'] ?? 'post';
49
50 $settings = array_merge(
51 [
52 'posts_source' => 'post',
53 'posts_orderby' => 'date',
54 'posts_order' => 'DESC',
55 'posts_ignore_sticky_posts' => 'no',
56 'posts_only_with_featured_image' => 'no',
57 'posts_select_date' => '',
58 'posts_exclude_by' => [],
59 'posts_include_by' => [],
60 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
61 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
62 ],
63 $settings
64 );
65
66 $ajaxposts = $this->query_args( $settings );
67
68 ob_start();
69 $found_posts = false;
70
71 if ( $ajaxposts->have_posts() ) {
72 $placeholder = \Elementor\Utils::get_placeholder_image_src();
73
74 while ( $ajaxposts->have_posts() ) {
75 $ajaxposts->the_post();
76 $found_posts = true;
77
78 $title = get_the_title();
79 $post_link = esc_url( get_permalink() );
80
81 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), $settings['primary_thumbnail_size'] ?? 'thumbnail' );
82 $image_src = $image_src ? $image_src[0] : $placeholder;
83
84 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
85
86 ?>
87 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
88 <div class="upk-content upk-flex upk-flex-middle">
89
90 <?php if ( $settings['show_counter_number'] === 'yes' ) : ?>
91 <div class="upk-counter"></div>
92 <?php endif; ?>
93
94 <?php if ( $settings['show_image'] === 'yes' ) : ?>
95 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>">
96 <?php endif; ?>
97
98 <?php $upk_item_icon = ultimate_post_kit_sanitize_request_icon( $settings['show_item_icon'] ?? null ); ?>
99 <?php if ( $upk_item_icon ) : ?>
100 <div class="upk-title-icon">
101 <?php \Elementor\Icons_Manager::render_icon( $upk_item_icon, [ 'aria-hidden' => 'true', 'class' => 'fa-fw' ] ); ?>
102 </div>
103 <?php endif; ?>
104
105 <?php if ( ! isset( $settings['show_title'] ) || $settings['show_title'] === 'yes' ) : ?>
106 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
107 <a
108 href="<?php echo esc_url($post_link); ?>"
109 title="<?php echo esc_attr( $title ); ?>"
110 class="title-animation-<?php echo esc_attr( $settings['title_style'] ?? '' ); ?>"
111 >
112 <?php echo esc_html( $title ); ?>
113 </a>
114 </<?php echo esc_attr( $title_tag ); ?>>
115 <?php endif; ?>
116 </div>
117 </div>
118 <?php
119 }
120 }
121
122 wp_reset_postdata();
123 $markup = ob_get_clean();
124
125 wp_send_json(
126 [
127 'success' => $found_posts,
128 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
129 ]
130 );
131
132 }
133 }
134