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

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

205 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\AlexGrid;
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_alex_grid_loadmore_posts', [$this, 'callback_ajax_loadmore_posts']);
19 add_action('wp_ajax_upk_alex_grid_loadmore_posts', [$this, 'callback_ajax_loadmore_posts']);
20 }
21
22 public function get_name() {
23 return 'alex-grid';
24 }
25
26 public function get_widgets() {
27
28 $widgets = [
29 'Alex_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['post_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 while ($ajaxposts->have_posts()) :
68 $ajaxposts->the_post();
69 $found_posts = true;
70
71 $title = get_the_title();
72 $post_link = esc_url(get_permalink());
73 $image_src = wp_get_attachment_image_url(get_post_thumbnail_id(), 'large');
74 $image_src = $image_src ? esc_url($image_src) : esc_url(\Elementor\Utils::get_placeholder_image_src());
75 $category = wp_kses_post(upk_get_category($post_type));
76 $author_url = esc_url(get_author_posts_url(get_the_author_meta('ID')));
77 $author_name = esc_html(get_the_author());
78 $title_tag = Utils::get_valid_html_tag($settings['title_tags'] );
79
80 $onclick = '';
81 if (!empty($settings['global_link']) && $settings['global_link'] === 'yes') {
82 $onclick = ' onclick="window.open(\'' . $post_link . '\', \'_self\')"';
83 }
84
85 $date = '';
86 if (!empty($settings['human_diff_time']) && $settings['human_diff_time'] === 'yes') {
87 $date = ultimate_post_kit_post_time_diff(($settings['human_diff_time_short'] === 'yes') ? 'short' : '');
88 } else {
89 $date = esc_html(get_the_date());
90 }
91
92 $format_icons = [
93 'aside' => 'upk-icon-aside',
94 'gallery' => 'upk-icon-gallery',
95 'link' => 'upk-icon-link',
96 'image' => 'upk-icon-image',
97 'quote' => 'upk-icon-quote',
98 'status' => 'upk-icon-status',
99 'video' => 'upk-icon-video',
100 'audio' => 'upk-icon-music',
101 'chat' => 'upk-icon-chat',
102 ];
103
104 $post_format_icon = isset($format_icons[get_post_format()]) ? $format_icons[get_post_format()] : 'upk-icon-post';
105
106 ?>
107 <div <?php echo $onclick; ?> class="upk-item">
108 <div class="upk-image-wrap">
109 <img class="upk-img" src="<?php echo $image_src; ?>" alt="<?php echo esc_attr($title); ?>">
110
111 <?php if (
112 $settings['show_author'] === 'yes' ||
113 $settings['show_date'] === 'yes' ||
114 $settings['show_time'] === 'yes' ||
115 $settings['show_reading_time'] === 'yes'
116 ) : ?>
117 <div class="upk-meta">
118 <?php if ($settings['show_author'] === 'yes') : ?>
119 <div class="upk-author-img"><?php echo wp_kses_post(get_avatar(get_the_author_meta('ID'), 48)); ?></div>
120 <?php endif; ?>
121
122 <div>
123 <?php if ($settings['show_author'] === 'yes') : ?>
124 <div class="upk-author-name">
125 <a href="<?php echo $author_url; ?>"><?php echo $author_name; ?></a>
126 </div>
127 <?php endif; ?>
128
129 <div class="upk-flex upk-flex-middle upk-date-reading-wrap">
130 <?php if ($settings['show_date'] === 'yes') : ?>
131 <div data-separator="<?php echo esc_attr($settings['meta_separator']); ?>">
132 <div class="upk-date"><?php echo $date; ?></div>
133 <?php if ($settings['show_time'] === 'yes') : ?>
134 <div class="upk-post-time">
135 <i class="upk-icon-clock" aria-hidden="true"></i><?php echo esc_html(get_the_time()); ?>
136 </div>
137 <?php endif; ?>
138 </div>
139 <?php endif; ?>
140
141 <?php if (function_exists('_is_upk_pro_activated') && _is_upk_pro_activated() && $settings['show_reading_time'] === 'yes') : ?>
142 <div class="upk-reading-time" data-separator="<?php echo esc_attr($settings['meta_separator']); ?>">
143 <?php echo ultimate_post_kit_reading_time(get_the_content(), $settings['avg_reading_speed']); ?>
144 </div>
145 <?php endif; ?>
146 </div>
147 </div>
148 </div>
149 <?php endif; ?>
150
151 <?php if ($settings['show_post_format'] === 'yes') : ?>
152 <div class="upk-post-format">
153 <a href="<?php echo $post_link; ?>">
154 <i class="<?php echo esc_attr($post_format_icon); ?>" aria-hidden="true"></i>
155 </a>
156 </div>
157 <?php endif; ?>
158 </div>
159
160 <div class="upk-content-wrap">
161 <div class="upk-content">
162 <?php if ($settings['show_category'] === 'yes') : ?>
163 <div class="upk-category"><?php echo $category; ?></div>
164 <?php endif; ?>
165
166 <?php if ($settings['show_title'] === 'yes') : ?>
167 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
168 <a class="title-animation-<?php echo esc_attr($settings['title_style']); ?>"
169 href="<?php echo $post_link; ?>"
170 title="<?php echo esc_attr($title); ?>"
171 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
172 >
173 <?php echo esc_html($title); ?>
174 </a>
175 </<?php echo esc_attr( $title_tag); ?>>
176 <?php endif; ?>
177 </div>
178
179 <?php if ($settings['show_readmore'] === 'yes') : ?>
180 <div class="upk-button-wrap">
181 <a href="<?php echo $post_link; ?>"
182 class="upk-readmore"
183 target="<?php echo ($settings['upk_link_new_tab'] === 'yes') ? '_blank' : '_self'; ?>">
184 <span class="upk-readmore-icon"><span></span></span>
185 </a>
186 </div>
187 <?php endif; ?>
188 </div>
189 </div>
190 <?php
191 endwhile;
192 endif;
193
194 wp_reset_postdata();
195 $markup = ob_get_clean();
196
197 wp_send_json(
198 [
199 'success' => $found_posts,
200 'markup' => $found_posts ? $markup : esc_html__('No more found', 'ultimate-post-kit'),
201 ]
202 );
203 }
204 }
205