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

244 lines 8.4 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
36 $settings = [];
37
38 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
39 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
40 }
41
42 $post_type = $settings['posts_source'] ?? 'post';
43
44 $settings = array_merge(
45 [
46 'posts_source' => 'post',
47 'posts_orderby' => 'date',
48 'posts_order' => 'DESC',
49 'posts_ignore_sticky_posts' => 'no',
50 'posts_only_with_featured_image' => 'no',
51 'posts_select_date' => '',
52 'posts_exclude_by' => [],
53 'posts_include_by' => [],
54 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
55 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
56 ],
57 $settings
58 );
59
60 $ajaxposts = $this->query_args($settings);
61
62 ob_start();
63 $found_posts = false;
64
65 if ( $ajaxposts->have_posts() ) {
66
67 $placeholder = \Elementor\Utils::get_placeholder_image_src();
68 $meta_sep = $settings['meta_separator'] ?? '|';
69
70 while ( $ajaxposts->have_posts() ) {
71
72 $ajaxposts->the_post();
73 $found_posts = true;
74
75 $title = get_the_title();
76 $post_link = esc_url( get_permalink() );
77 $author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
78 $author_name = esc_html( get_the_author() );
79 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
80
81 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
82 $image_src = $image_src ? $image_src[0] : $placeholder;
83
84 ?>
85 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
86 <div class="upk-item-box">
87 <div class="upk-image-wrap">
88 <div class="upk-main-image">
89 <img class="upk-img" src="<?php echo esc_url($image_src); ?>" alt="<?php echo esc_attr($title); ?>">
90 </div>
91
92 <?php if ($settings['show_author'] === 'yes') : ?>
93 <div class="upk-author-wrap">
94 <div class="upk-author-img-wrap">
95 <?php echo get_avatar(get_the_author_meta('ID'), 48); ?>
96 </div>
97 <div class="upk-author-info-warp">
98 <span class="author-name">
99 <a class="name" href="<?php echo esc_url( $author_url ); ?>">
100 <?php echo esc_html( $author_name ); ?>
101 </a>
102 </span>
103 <span class="author-depertment">
104 <?php
105 $aid = get_the_author_meta('ID');
106 echo esc_html( get_user_role( $aid ) );
107 ?>
108 </span>
109 </div>
110 </div>
111 <?php endif; ?>
112
113 <?php if ($settings['show_category'] === 'yes' || $settings['show_date'] === 'yes') : ?>
114 <div class="upk-meta-wrap">
115 <?php if ($settings['show_date'] === 'yes' || $settings['show_reading_time'] === 'yes') : ?>
116 <div class="upk-flex upk-flex-middle upk-date-reading-wrap">
117 <?php if ($settings['show_date'] === 'yes') : ?>
118 <div class="upk-date">
119 <?php
120 if ($settings['human_diff_time'] === 'yes') {
121 echo esc_html(
122 ultimate_post_kit_post_time_diff(
123 ($settings['human_diff_time_short'] == 'yes') ? 'short' : ''
124 )
125 );
126 } else {
127 echo esc_html(get_the_date());
128 }
129 ?>
130 </div>
131 <?php if ($settings['show_time'] === 'yes' && $settings['human_diff_time'] !== 'yes') : ?>
132 <div class="upk-post-time">
133 <i class="upk-icon-clock" aria-hidden="true"></i>
134 <?php echo esc_html(get_the_time()); ?>
135 </div>
136 <?php endif; ?>
137 <?php endif; ?>
138
139 <?php if (function_exists('ultimate_post_kit_reading_time') && $settings['show_reading_time'] === 'yes') : ?>
140 <?php $speed = (int)($settings['avg_reading_speed'] ?? 200); ?>
141 <div class="upk-reading-time" data-separator="<?php echo esc_attr($meta_sep); ?>">
142 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
143 </div>
144 <?php endif; ?>
145 </div>
146 <?php endif; ?>
147
148 <?php if ($settings['show_category'] === 'yes') : ?>
149 <div class="upk-category"><?php echo wp_kses_post( upk_get_category($post_type) ); ?></div>
150 <?php endif; ?>
151 </div>
152 <?php endif; ?>
153 </div>
154
155 <div class="upk-content">
156 <div>
157 <?php if (!isset($settings['show_title']) || $settings['show_title'] === 'yes') : ?>
158 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
159 <a
160 href="<?php echo esc_url( $post_link ); ?>"
161 title="<?php echo esc_attr($title); ?>"
162 class="title-animation-<?php echo esc_attr($settings['title_style']); ?>"
163 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
164 >
165 <?php echo esc_html($title); ?>
166 </a>
167 </<?php echo esc_attr( $title_tag ); ?>>
168 <?php endif; ?>
169
170 <?php if ($settings['show_excerpt'] === 'yes') : ?>
171 <div class="upk-text-wrap">
172 <div class="upk-text">
173 <?php
174 echo esc_html(
175 wp_trim_words(
176 get_the_excerpt(),
177 absint($settings['excerpt_length'] ?? 20)
178 )
179 );
180 ?>
181 </div>
182 </div>
183 <?php endif; ?>
184
185 <?php if (
186 $settings['show_category'] === 'yes' ||
187 $settings['show_date'] === 'yes' ||
188 $settings['show_reading_time'] === 'yes'
189 ) : ?>
190 <div class="upk-meta-list upk-flex upk-flex-middle">
191 <?php if ($settings['show_category'] === 'yes') : ?>
192 <div class="upk-category"><?php echo wp_kses_post( upk_get_category($post_type) ); ?></div>
193 <?php endif; ?>
194
195 <?php if ($settings['show_date'] === 'yes') : ?>
196 <div class="upk-date">
197 <?php
198 if ($settings['human_diff_time'] === 'yes') {
199 echo esc_html(
200 ultimate_post_kit_post_time_diff(
201 ($settings['human_diff_time_short'] == 'yes') ? 'short' : ''
202 )
203 );
204 } else {
205 echo esc_html(get_the_date());
206 }
207 ?>
208 </div>
209 <?php if ($settings['show_time'] === 'yes' && $settings['human_diff_time'] !== 'yes') : ?>
210 <div class="upk-post-time">
211 <i class="upk-icon-clock" aria-hidden="true"></i>
212 <?php echo esc_html(get_the_time()); ?>
213 </div>
214 <?php endif; ?>
215 <?php endif; ?>
216
217 <?php if (function_exists('ultimate_post_kit_reading_time') && $settings['show_reading_time'] === 'yes') : ?>
218 <?php $speed = (int)($settings['avg_reading_speed'] ?? 200); ?>
219 <div class="upk-reading-time" data-separator="<?php echo esc_attr($meta_sep); ?>">
220 <?php echo esc_html(ultimate_post_kit_reading_time(get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
221 </div>
222 <?php endif; ?>
223 </div>
224 <?php endif; ?>
225 </div>
226 </div>
227 </div>
228 </div>
229 <?php
230 }
231 }
232
233 wp_reset_postdata();
234 $markup = ob_get_clean();
235
236 wp_send_json(
237 [
238 'success' => $found_posts,
239 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
240 ]
241 );
242 }
243 }
244