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

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