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

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

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