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 / alter-grid / module.php

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

256 lines 9.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\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 $ajaxposts = $this->query_args($settings);
68
69 ob_start();
70 $found_posts = false;
71
72 if ( $ajaxposts->have_posts() ) {
73
74 $placeholder = \Elementor\Utils::get_placeholder_image_src();
75 $meta_sep = $settings['meta_separator'] ?? '|';
76 $readmore_text = $settings['readmore_text'] ?? 'Read More';
77
78 while ( $ajaxposts->have_posts() ) {
79
80 $ajaxposts->the_post();
81 $found_posts = true;
82
83 $title = get_the_title();
84 $post_link = esc_url( get_permalink() );
85 $author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
86 $author_name = esc_html( get_the_author() );
87 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
88
89 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
90 $image_src = $image_src ? $image_src[0] : $placeholder;
91
92 ?>
93 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
94 <div class="upk-item-box">
95 <div class="upk-img-wrap">
96 <div class="upk-main-img">
97 <img
98 class="upk-img"
99 src="<?php echo esc_url( $image_src ); ?>"
100 alt="<?php echo esc_attr( $title ); ?>"
101 >
102 <?php if ( $settings['readmore_type'] === 'on_image' ) : ?>
103 <a href="<?php echo esc_url( $post_link ); ?>" class="upk-readmore-on-image">
104 <span class="upk-readmore-icon"><span></span></span>
105 </a>
106 <?php endif; ?>
107
108 <?php if ( $settings['show_post_format'] === 'yes' ) : ?>
109 <div class="upk-post-format">
110 <a href="<?php echo esc_url( $post_link ); ?>">
111 <?php
112 if ( has_post_format( 'aside' ) ) :
113 echo '<i class="upk-icon-aside" aria-hidden="true"></i>';
114 elseif ( has_post_format( 'gallery' ) ) :
115 echo '<i class="upk-icon-gallery" aria-hidden="true"></i>';
116 elseif ( has_post_format( 'link' ) ) :
117 echo '<i class="upk-icon-link" aria-hidden="true"></i>';
118 elseif ( has_post_format( 'image' ) ) :
119 echo '<i class="upk-icon-image" aria-hidden="true"></i>';
120 elseif ( has_post_format( 'quote' ) ) :
121 echo '<i class="upk-icon-quote" aria-hidden="true"></i>';
122 elseif ( has_post_format( 'status' ) ) :
123 echo '<i class="upk-icon-status" aria-hidden="true"></i>';
124 elseif ( has_post_format( 'video' ) ) :
125 echo '<i class="upk-icon-video" aria-hidden="true"></i>';
126 elseif ( has_post_format( 'audio' ) ) :
127 echo '<i class="upk-icon-music" aria-hidden="true"></i>';
128 elseif ( has_post_format( 'chat' ) ) :
129 echo '<i class="upk-icon-chat" aria-hidden="true"></i>';
130 else :
131 echo '<i class="upk-icon-post" aria-hidden="true"></i>';
132 endif;
133 ?>
134 </a>
135 </div>
136 <?php endif; ?>
137 </div>
138 </div>
139
140 <div class="upk-content">
141 <div>
142 <?php if ( $settings['show_category'] === 'yes' ) : ?>
143 <div class="upk-category">
144 <?php echo wp_kses_post( upk_get_category( $post_type ) ); ?>
145 </div>
146 <?php endif; ?>
147
148 <?php if ( ! isset( $settings['show_title'] ) || $settings['show_title'] === 'yes' ) : ?>
149 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
150 <a
151 href="<?php echo esc_url( $post_link ); ?>"
152 title="<?php echo esc_attr( $title ); ?>"
153 class="title-animation-<?php echo esc_attr( $settings['title_style'] ); ?>"
154 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
155 >
156 <?php echo esc_html( $title ); ?>
157 </a>
158 </<?php echo esc_attr( $title_tag ); ?>>
159 <?php endif; ?>
160
161 <?php if ( $settings['show_excerpt'] === 'yes' ) : ?>
162 <div class="upk-text-wrap">
163 <div class="upk-text">
164 <?php
165 echo esc_html(
166 wp_trim_words(
167 get_the_excerpt(),
168 ultimate_post_kit_clamp_excerpt_length( $settings['excerpt_length'] ?? 20, 20 ),
169 '...'
170 )
171 );
172 ?>
173 </div>
174
175 <?php if ( $settings['readmore_type'] === 'classic' ) : ?>
176 <a href="<?php echo esc_url( $post_link ); ?>" class="upk-readmore upk-display-inline-block">
177 <?php echo esc_html( $readmore_text ); ?>
178 <?php $upk_readmore_icon = ultimate_post_kit_sanitize_request_icon( $settings['readmore_icon'] ?? null ); ?>
179 <?php if ( $upk_readmore_icon ) : ?>
180 <span class="upk-button-icon-align-<?php echo esc_attr( $settings['readmore_icon_align'] ); ?>">
181 <?php Icons_Manager::render_icon( $upk_readmore_icon, [ 'aria-hidden' => 'true', 'class' => 'fa-fw' ] ); ?>
182 </span>
183 <?php endif; ?>
184 </a>
185 <?php endif; ?>
186 </div>
187 <?php endif; ?>
188
189 <?php if (
190 $settings['show_author'] === 'yes' ||
191 $settings['show_date'] === 'yes' ||
192 $settings['show_reading_time'] === 'yes'
193 ) : ?>
194 <div class="upk-meta">
195
196 <?php if ( $settings['show_author'] === 'yes' ) : ?>
197 <div class="upk-blog-author" data-separator="<?php echo esc_attr( $meta_sep ); ?>">
198 <a class="author-name" href="<?php echo esc_url( $author_url ); ?>">
199 <?php echo esc_html( $author_name ); ?>
200 </a>
201 </div>
202 <?php endif; ?>
203
204 <?php if ( $settings['show_date'] === 'yes' ) : ?>
205 <div data-separator="<?php echo esc_attr( $meta_sep ); ?>">
206 <div class="upk-date">
207 <?php
208 if ( $settings['human_diff_time'] === 'yes' ) {
209 echo esc_html(
210 ultimate_post_kit_post_time_diff(
211 ( $settings['human_diff_time_short'] == 'yes' ) ? 'short' : ''
212 )
213 );
214 } else {
215 echo get_the_date();
216 }
217 ?>
218 </div>
219
220 <?php if ( $settings['show_time'] === 'yes' && $settings['human_diff_time'] !== 'yes' ) : ?>
221 <div class="upk-post-time">
222 <i class="upk-icon-clock" aria-hidden="true"></i>
223 <?php echo esc_html( get_the_time() ); ?>
224 </div>
225 <?php endif; ?>
226 </div>
227 <?php endif; ?>
228
229 <?php if ( function_exists( 'ultimate_post_kit_reading_time' ) && $settings['show_reading_time'] === 'yes' ) : ?>
230 <?php $speed = (int) ( $settings['avg_reading_speed'] ?? 200 ); ?>
231 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $meta_sep ); ?>">
232 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
233 </div>
234 <?php endif; ?>
235 </div>
236 <?php endif; ?>
237 </div>
238 </div>
239 </div>
240 </div>
241 <?php
242 }
243 }
244
245 wp_reset_postdata();
246 $markup = ob_get_clean();
247
248 wp_send_json(
249 [
250 'success' => $found_posts,
251 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
252 ]
253 );
254 }
255 }
256