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

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

199 lines 6.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\HazelGrid;
3
4 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
5 use UltimatePostKit\Traits\Global_Widget_Functions;
6 use UltimatePostKit\Utils;
7
8 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
9
10 class Module extends Ultimate_Post_Kit_Module_Base {
11
12 use Global_Widget_Functions;
13
14 public function __construct() {
15 parent::__construct();
16
17 add_action( 'wp_ajax_nopriv_upk_hazel_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
18 add_action( 'wp_ajax_upk_hazel_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 }
20
21 public function get_name() {
22 return 'hazel-grid';
23 }
24
25 public function get_widgets() {
26
27 $widgets = [
28 'Hazel_Grid',
29 ];
30
31 return $widgets;
32 }
33
34 public function callback_ajax_loadmore_posts() {
35
36 $settings = [];
37
38 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
39 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
40 }
41
42 $post_type = $settings['posts_source'] ?? 'post';
43
44 $settings = array_merge(
45 [
46 'posts_source' => 'post',
47 'posts_orderby' => 'date',
48 'posts_order' => 'DESC',
49 'posts_ignore_sticky_posts' => 'no',
50 'posts_only_with_featured_image' => 'no',
51 'posts_select_date' => '',
52 'posts_exclude_by' => [],
53 'posts_include_by' => [],
54 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
55 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
56 ],
57 $settings
58 );
59
60 $ajaxposts = $this->query_args($settings);
61
62 ob_start();
63 $found_posts = false;
64
65 if ( $ajaxposts->have_posts() ) {
66
67 $placeholder = \Elementor\Utils::get_placeholder_image_src();
68
69 while ( $ajaxposts->have_posts() ) {
70
71 $ajaxposts->the_post();
72 $found_posts = true;
73
74 $title = get_the_title();
75 $post_link = esc_url( get_permalink() );
76 $author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
77 $author_name = esc_html( get_the_author() );
78
79 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
80 $image_src = $image_src ? $image_src[0] : $placeholder;
81 $meta_sep = $settings['meta_separator'] ?? '-';
82 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
83
84 $onclick = '';
85 if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) {
86 $onclick = 'onclick="window.open(\'' . esc_url( $post_link ) . '\', \'_self\')"';
87 }
88
89 ?>
90 <div <?php echo $onclick; ?> class="upk-item">
91 <div class="upk-item-box">
92 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>">
93
94 <div class="upk-content">
95 <?php if ( $settings['show_category'] === 'yes' ) : ?>
96 <div class="upk-category">
97 <?php echo upk_get_category( $post_type ); ?>
98 </div>
99 <?php endif; ?>
100
101 <?php if ( ! isset( $settings['show_title'] ) || $settings['show_title'] === 'yes' ) : ?>
102 <div class="upk-title-wrap">
103 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
104 <a
105 href="<?php echo esc_url( $post_link ); ?>"
106 title="<?php echo esc_attr( $title ); ?>"
107 class="title-animation-<?php echo esc_attr( $settings['title_style'] ); ?>"
108 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
109 >
110 <?php echo esc_html( $title ); ?>
111 </a>
112 </<?php echo esc_attr( $title_tag ); ?>>
113 </div>
114 <?php endif; ?>
115
116 <?php if (
117 $settings['show_author'] === 'yes' ||
118 $settings['show_date'] === 'yes' ||
119 $settings['show_reading_time'] === 'yes'
120 ) : ?>
121 <div class="upk-meta">
122
123 <?php if ( $settings['show_author'] === 'yes' ) : ?>
124 <div class="upk-blog-author">
125 <span class="by">
126 <?php echo esc_html_x( 'by', 'Frontend', 'ultimate-post-kit' ); ?>
127 </span>
128 <span class="upk-post-grid-author">
129 <a href="<?php echo esc_url( $author_url ); ?>">
130 <?php echo esc_html( $author_name ); ?>
131 </a>
132 </span>
133 </div>
134 <?php endif; ?>
135
136 <?php if ( $settings['show_date'] === 'yes' ) : ?>
137 <div data-separator="<?php echo esc_html( $meta_sep ); ?>">
138 <div class="upk-date">
139 <i class="upk-icon-calendar" aria-hidden="true"></i>
140 <?php
141 if ( $settings['human_diff_time'] === 'yes' ) {
142 echo esc_html(
143 ultimate_post_kit_post_time_diff(
144 ( ( $settings['human_diff_time_short'] ?? 'no' ) === 'yes' ) ? 'short' : ''
145 )
146 );
147 } else {
148 echo esc_html( get_the_date() );
149 }
150 ?>
151 </div>
152
153 <?php if ( $settings['show_time'] === 'yes' ) : ?>
154 <div class="upk-post-time">
155 <i class="upk-icon-clock" aria-hidden="true"></i>
156 <?php echo esc_html( get_the_time() ); ?>
157 </div>
158 <?php endif; ?>
159 </div>
160 <?php endif; ?>
161
162 <?php if (
163 function_exists( '_is_upk_pro_activated' ) &&
164 _is_upk_pro_activated() &&
165 function_exists( 'ultimate_post_kit_reading_time' ) &&
166 $settings['show_reading_time'] === 'yes'
167 ) : ?>
168 <div class="upk-reading-time" data-separator="<?php echo esc_html( $meta_sep ); ?>">
169 <?php echo esc_html(
170 ultimate_post_kit_reading_time(
171 get_the_content(),
172 $settings['avg_reading_speed'],
173 $settings['hide_seconds'] ?? 'no',
174 $settings['hide_minutes'] ?? 'no'
175 )
176 ); ?>
177 </div>
178 <?php endif; ?>
179 </div>
180 <?php endif; ?>
181 </div>
182 </div>
183 </div>
184 <?php
185 }
186 }
187
188 wp_reset_postdata();
189 $markup = ob_get_clean();
190
191 wp_send_json(
192 [
193 'success' => $found_posts,
194 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
195 ]
196 );
197 }
198 }
199