PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.5.3
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.5.3
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 / elite-grid / module.php

module.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.5.3, at modules/elite-grid/module.php

250 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\EliteGrid;
3
4 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
5 use UltimatePostKit\Traits\Global_Widget_Functions;
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_elite_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
18 add_action( 'wp_ajax_upk_elite_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 }
20
21 public function get_name() {
22 return 'elite-grid';
23 }
24
25 public function get_widgets() {
26
27 $widgets = [
28 'Elite_Grid',
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
73 $placeholder = \Elementor\Utils::get_placeholder_image_src();
74 $meta_sep = $settings['meta_separator'] ?? '|';
75
76 while ( $ajaxposts->have_posts() ) {
77
78 $ajaxposts->the_post();
79 $found_posts = true;
80
81 $title = get_the_title();
82 $post_link = esc_url( get_permalink() );
83 $author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
84 $author_name = esc_html( get_the_author() );
85 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
86
87 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
88 $image_src = $image_src ? $image_src[0] : $placeholder;
89
90 ?>
91 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
92 <div class="upk-item-box">
93 <div class="upk-image-wrap">
94 <div class="upk-main-image">
95 <img class="upk-img" src="<?php echo esc_url($image_src); ?>" alt="<?php echo esc_attr($title); ?>">
96 </div>
97
98 <?php if ($settings['show_author'] === 'yes') : ?>
99 <div class="upk-author-wrap">
100 <div class="upk-author-img-wrap">
101 <?php echo get_avatar(get_the_author_meta('ID'), 48); ?>
102 </div>
103 <div class="upk-author-info-warp">
104 <span class="author-name">
105 <a class="name" href="<?php echo esc_url( $author_url ); ?>">
106 <?php echo esc_html( $author_name ); ?>
107 </a>
108 </span>
109 <span class="author-depertment">
110 <?php
111 $aid = get_the_author_meta('ID');
112 echo esc_html( get_user_role( $aid ) );
113 ?>
114 </span>
115 </div>
116 </div>
117 <?php endif; ?>
118
119 <?php if ($settings['show_category'] === 'yes' || $settings['show_date'] === 'yes') : ?>
120 <div class="upk-meta-wrap">
121 <?php if ($settings['show_date'] === 'yes' || $settings['show_reading_time'] === 'yes') : ?>
122 <div class="upk-flex upk-flex-middle upk-date-reading-wrap">
123 <?php if ($settings['show_date'] === 'yes') : ?>
124 <div class="upk-date">
125 <?php
126 if ($settings['human_diff_time'] === 'yes') {
127 echo esc_html(
128 ultimate_post_kit_post_time_diff(
129 ($settings['human_diff_time_short'] == 'yes') ? 'short' : ''
130 )
131 );
132 } else {
133 echo esc_html(get_the_date());
134 }
135 ?>
136 </div>
137 <?php if ($settings['show_time'] === 'yes' && $settings['human_diff_time'] !== 'yes') : ?>
138 <div class="upk-post-time">
139 <i class="upk-icon-clock" aria-hidden="true"></i>
140 <?php echo esc_html(get_the_time()); ?>
141 </div>
142 <?php endif; ?>
143 <?php endif; ?>
144
145 <?php if (function_exists('ultimate_post_kit_reading_time') && $settings['show_reading_time'] === 'yes') : ?>
146 <?php $speed = (int)($settings['avg_reading_speed'] ?? 200); ?>
147 <div class="upk-reading-time" data-separator="<?php echo esc_attr($meta_sep); ?>">
148 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
149 </div>
150 <?php endif; ?>
151 </div>
152 <?php endif; ?>
153
154 <?php if ($settings['show_category'] === 'yes') : ?>
155 <div class="upk-category"><?php echo wp_kses_post( upk_get_category($post_type) ); ?></div>
156 <?php endif; ?>
157 </div>
158 <?php endif; ?>
159 </div>
160
161 <div class="upk-content">
162 <div>
163 <?php if (!isset($settings['show_title']) || $settings['show_title'] === 'yes') : ?>
164 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
165 <a
166 href="<?php echo esc_url( $post_link ); ?>"
167 title="<?php echo esc_attr($title); ?>"
168 class="title-animation-<?php echo esc_attr($settings['title_style']); ?>"
169 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
170 >
171 <?php echo esc_html($title); ?>
172 </a>
173 </<?php echo esc_attr( $title_tag ); ?>>
174 <?php endif; ?>
175
176 <?php if ($settings['show_excerpt'] === 'yes') : ?>
177 <div class="upk-text-wrap">
178 <div class="upk-text">
179 <?php
180 echo esc_html(
181 wp_trim_words(
182 get_the_excerpt(),
183 ultimate_post_kit_clamp_excerpt_length($settings['excerpt_length'] ?? 20, 20)
184 )
185 );
186 ?>
187 </div>
188 </div>
189 <?php endif; ?>
190
191 <?php if (
192 $settings['show_category'] === 'yes' ||
193 $settings['show_date'] === 'yes' ||
194 $settings['show_reading_time'] === 'yes'
195 ) : ?>
196 <div class="upk-meta-list upk-flex upk-flex-middle">
197 <?php if ($settings['show_category'] === 'yes') : ?>
198 <div class="upk-category"><?php echo wp_kses_post( upk_get_category($post_type) ); ?></div>
199 <?php endif; ?>
200
201 <?php if ($settings['show_date'] === 'yes') : ?>
202 <div class="upk-date">
203 <?php
204 if ($settings['human_diff_time'] === 'yes') {
205 echo esc_html(
206 ultimate_post_kit_post_time_diff(
207 ($settings['human_diff_time_short'] == 'yes') ? 'short' : ''
208 )
209 );
210 } else {
211 echo esc_html(get_the_date());
212 }
213 ?>
214 </div>
215 <?php if ($settings['show_time'] === 'yes' && $settings['human_diff_time'] !== 'yes') : ?>
216 <div class="upk-post-time">
217 <i class="upk-icon-clock" aria-hidden="true"></i>
218 <?php echo esc_html(get_the_time()); ?>
219 </div>
220 <?php endif; ?>
221 <?php endif; ?>
222
223 <?php if (function_exists('ultimate_post_kit_reading_time') && $settings['show_reading_time'] === 'yes') : ?>
224 <?php $speed = (int)($settings['avg_reading_speed'] ?? 200); ?>
225 <div class="upk-reading-time" data-separator="<?php echo esc_attr($meta_sep); ?>">
226 <?php echo esc_html(ultimate_post_kit_reading_time(get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
227 </div>
228 <?php endif; ?>
229 </div>
230 <?php endif; ?>
231 </div>
232 </div>
233 </div>
234 </div>
235 <?php
236 }
237 }
238
239 wp_reset_postdata();
240 $markup = ob_get_clean();
241
242 wp_send_json(
243 [
244 'success' => $found_posts,
245 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
246 ]
247 );
248 }
249 }
250