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

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

259 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\AlterGrid;
3
4 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
5 use UltimatePostKit\Traits\Global_Widget_Functions;
6 use \Elementor\Icons_Manager;
7 use UltimatePostKit\Utils;
8
9 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
10
11 class Module extends Ultimate_Post_Kit_Module_Base {
12
13 use Global_Widget_Functions;
14
15 public function __construct() {
16 parent::__construct();
17
18 add_action( 'wp_ajax_nopriv_upk_alter_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 add_action( 'wp_ajax_upk_alter_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
20 }
21
22 public function get_name() {
23 return 'alter-grid';
24 }
25
26 public function get_widgets() {
27
28 $widgets = [
29 'Alter_Grid',
30 ];
31
32 return $widgets;
33 }
34
35 public function callback_ajax_loadmore_posts() {
36 // Verify the front-end nonce (sent by UltimatePostKitConfig.nonce) before
37 // processing this public load-more request.
38 if ( ! check_ajax_referer( 'upk-site', 'nonce', false ) ) {
39 wp_send_json_error( array( 'message' => esc_html__( 'Security check failed.', 'ultimate-post-kit' ) ), 403 );
40 }
41
42
43 $settings = [];
44
45 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
46 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
47 }
48
49 $post_type = $settings['posts_source'] ?? 'post';
50
51 $settings = array_merge(
52 [
53 'posts_source' => 'post',
54 'posts_orderby' => 'date',
55 'posts_order' => 'DESC',
56 'posts_ignore_sticky_posts' => 'no',
57 'posts_only_with_featured_image' => 'no',
58 'posts_select_date' => '',
59 'posts_exclude_by' => [],
60 'posts_include_by' => [],
61 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
62 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
63 ],
64 $settings
65 );
66
67 // Fill display flags the request may have omitted (see trait) before the render loop reads them.
68 $settings = array_merge( $this->loadmore_display_defaults(), $settings );
69
70 $ajaxposts = $this->query_args($settings);
71
72 ob_start();
73 $found_posts = false;
74
75 if ( $ajaxposts->have_posts() ) {
76
77 $placeholder = \Elementor\Utils::get_placeholder_image_src();
78 $meta_sep = $settings['meta_separator'] ?? '|';
79 $readmore_text = $settings['readmore_text'] ?? 'Read More';
80
81 while ( $ajaxposts->have_posts() ) {
82
83 $ajaxposts->the_post();
84 $found_posts = true;
85
86 $title = get_the_title();
87 $post_link = esc_url( get_permalink() );
88 $author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
89 $author_name = esc_html( get_the_author() );
90 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
91
92 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
93 $image_src = $image_src ? $image_src[0] : $placeholder;
94
95 ?>
96 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
97 <div class="upk-item-box">
98 <div class="upk-img-wrap">
99 <div class="upk-main-img">
100 <img
101 class="upk-img"
102 src="<?php echo esc_url( $image_src ); ?>"
103 alt="<?php echo esc_attr( $title ); ?>"
104 >
105 <?php if ( $settings['readmore_type'] === 'on_image' ) : ?>
106 <a href="<?php echo esc_url( $post_link ); ?>" class="upk-readmore-on-image">
107 <span class="upk-readmore-icon"><span></span></span>
108 </a>
109 <?php endif; ?>
110
111 <?php if ( $settings['show_post_format'] === 'yes' ) : ?>
112 <div class="upk-post-format">
113 <a href="<?php echo esc_url( $post_link ); ?>">
114 <?php
115 if ( has_post_format( 'aside' ) ) :
116 echo '<i class="upk-icon-aside" aria-hidden="true"></i>';
117 elseif ( has_post_format( 'gallery' ) ) :
118 echo '<i class="upk-icon-gallery" aria-hidden="true"></i>';
119 elseif ( has_post_format( 'link' ) ) :
120 echo '<i class="upk-icon-link" aria-hidden="true"></i>';
121 elseif ( has_post_format( 'image' ) ) :
122 echo '<i class="upk-icon-image" aria-hidden="true"></i>';
123 elseif ( has_post_format( 'quote' ) ) :
124 echo '<i class="upk-icon-quote" aria-hidden="true"></i>';
125 elseif ( has_post_format( 'status' ) ) :
126 echo '<i class="upk-icon-status" aria-hidden="true"></i>';
127 elseif ( has_post_format( 'video' ) ) :
128 echo '<i class="upk-icon-video" aria-hidden="true"></i>';
129 elseif ( has_post_format( 'audio' ) ) :
130 echo '<i class="upk-icon-music" aria-hidden="true"></i>';
131 elseif ( has_post_format( 'chat' ) ) :
132 echo '<i class="upk-icon-chat" aria-hidden="true"></i>';
133 else :
134 echo '<i class="upk-icon-post" aria-hidden="true"></i>';
135 endif;
136 ?>
137 </a>
138 </div>
139 <?php endif; ?>
140 </div>
141 </div>
142
143 <div class="upk-content">
144 <div>
145 <?php if ( $settings['show_category'] === 'yes' ) : ?>
146 <div class="upk-category">
147 <?php echo wp_kses_post( upk_get_category( $post_type ) ); ?>
148 </div>
149 <?php endif; ?>
150
151 <?php if ( ! isset( $settings['show_title'] ) || $settings['show_title'] === 'yes' ) : ?>
152 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
153 <a
154 href="<?php echo esc_url( $post_link ); ?>"
155 title="<?php echo esc_attr( $title ); ?>"
156 class="title-animation-<?php echo esc_attr( $settings['title_style'] ); ?>"
157 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
158 >
159 <?php echo esc_html( $title ); ?>
160 </a>
161 </<?php echo esc_attr( $title_tag ); ?>>
162 <?php endif; ?>
163
164 <?php if ( $settings['show_excerpt'] === 'yes' ) : ?>
165 <div class="upk-text-wrap">
166 <div class="upk-text">
167 <?php
168 echo esc_html(
169 wp_trim_words(
170 get_the_excerpt(),
171 ultimate_post_kit_clamp_excerpt_length( $settings['excerpt_length'] ?? 20, 20 ),
172 '...'
173 )
174 );
175 ?>
176 </div>
177
178 <?php if ( $settings['readmore_type'] === 'classic' ) : ?>
179 <a href="<?php echo esc_url( $post_link ); ?>" class="upk-readmore upk-display-inline-block">
180 <?php echo esc_html( $readmore_text ); ?>
181 <?php $upk_readmore_icon = ultimate_post_kit_sanitize_request_icon( $settings['readmore_icon'] ?? null ); ?>
182 <?php if ( $upk_readmore_icon ) : ?>
183 <span class="upk-button-icon-align-<?php echo esc_attr( $settings['readmore_icon_align'] ); ?>">
184 <?php Icons_Manager::render_icon( $upk_readmore_icon, [ 'aria-hidden' => 'true', 'class' => 'fa-fw' ] ); ?>
185 </span>
186 <?php endif; ?>
187 </a>
188 <?php endif; ?>
189 </div>
190 <?php endif; ?>
191
192 <?php if (
193 $settings['show_author'] === 'yes' ||
194 $settings['show_date'] === 'yes' ||
195 $settings['show_reading_time'] === 'yes'
196 ) : ?>
197 <div class="upk-meta">
198
199 <?php if ( $settings['show_author'] === 'yes' ) : ?>
200 <div class="upk-blog-author" data-separator="<?php echo esc_attr( $meta_sep ); ?>">
201 <a class="author-name" href="<?php echo esc_url( $author_url ); ?>">
202 <?php echo esc_html( $author_name ); ?>
203 </a>
204 </div>
205 <?php endif; ?>
206
207 <?php if ( $settings['show_date'] === 'yes' ) : ?>
208 <div data-separator="<?php echo esc_attr( $meta_sep ); ?>">
209 <div class="upk-date">
210 <?php
211 if ( $settings['human_diff_time'] === 'yes' ) {
212 echo esc_html(
213 ultimate_post_kit_post_time_diff(
214 ( $settings['human_diff_time_short'] == 'yes' ) ? 'short' : ''
215 )
216 );
217 } else {
218 echo get_the_date();
219 }
220 ?>
221 </div>
222
223 <?php if ( $settings['show_time'] === 'yes' && $settings['human_diff_time'] !== 'yes' ) : ?>
224 <div class="upk-post-time">
225 <i class="upk-icon-clock" aria-hidden="true"></i>
226 <?php echo esc_html( get_the_time() ); ?>
227 </div>
228 <?php endif; ?>
229 </div>
230 <?php endif; ?>
231
232 <?php if ( function_exists( 'ultimate_post_kit_reading_time' ) && $settings['show_reading_time'] === 'yes' ) : ?>
233 <?php $speed = (int) ( $settings['avg_reading_speed'] ?? 200 ); ?>
234 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $meta_sep ); ?>">
235 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
236 </div>
237 <?php endif; ?>
238 </div>
239 <?php endif; ?>
240 </div>
241 </div>
242 </div>
243 </div>
244 <?php
245 }
246 }
247
248 wp_reset_postdata();
249 $markup = ob_get_clean();
250
251 wp_send_json(
252 [
253 'success' => $found_posts,
254 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
255 ]
256 );
257 }
258 }
259