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

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

190 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\AliceGrid;
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 // Register AJAX actions for load more
18 add_action( 'wp_ajax_nopriv_upk_alice_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 add_action( 'wp_ajax_upk_alice_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
20 }
21
22 public function get_name() {
23 return 'alice-grid';
24 }
25
26 public function get_widgets() {
27
28 $widgets = [
29 'Alice_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 $settings = array_merge(
44 [
45 'posts_source' => 'post',
46 'posts_orderby' => 'date',
47 'posts_order' => 'DESC',
48 'posts_ignore_sticky_posts' => 'no',
49 'posts_only_with_featured_image' => 'no',
50 'posts_select_date' => '',
51 'posts_exclude_by' => [],
52 'posts_include_by' => [],
53 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
54 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
55 ],
56 $settings
57 );
58
59 $ajaxposts = $this->query_args($settings);
60
61 ob_start();
62 $found_posts = false;
63
64 if ( $ajaxposts->have_posts() ) {
65
66 while ( $ajaxposts->have_posts() ) :
67
68 $ajaxposts->the_post();
69 $found_posts = true;
70
71 $title = get_the_title();
72 $post_link = esc_url( get_permalink() );
73 $author_url = get_author_posts_url( get_the_author_meta( 'ID' ) );
74 $author_name = get_the_author();
75 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
76
77 $placeholder_image_src = \Elementor\Utils::get_placeholder_image_src();
78 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
79 $image_src = $image_src ? $image_src[0] : $placeholder_image_src;
80
81 $onclick = '';
82
83 if (!empty($settings['global_link']) && $settings['global_link'] === 'yes') {
84 $onclick = ' onclick="window.open(\'' . $post_link . '\', \'_self\')"';
85 }
86
87 ?>
88 <div <?php echo $onclick; ?> class="upk-item">
89 <div class="upk-item-box">
90
91 <div class="upk-img-wrap">
92 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>">
93 </div>
94
95 <?php if ( isset( $settings['show_category'] ) && 'yes' === $settings['show_category'] ) : ?>
96 <div class="upk-category">
97 <?php echo upk_get_category( $settings['post_source'] ); ?>
98 </div>
99 <?php endif; ?>
100
101 <div class="upk-content">
102
103 <?php if ( ! isset( $settings['show_title'] ) || 'yes' === $settings['show_title'] ) : ?>
104 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
105 <a
106 href="<?php echo esc_url( $post_link ); ?>"
107 title="<?php echo esc_attr( $title ); ?>"
108 class="title-animation-<?php echo esc_attr( $settings['title_style'] ); ?>"
109 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
110 >
111 <?php echo esc_html( $title ); ?>
112 </a>
113 </<?php echo esc_attr( $title_tag ); ?>>
114 <?php endif; ?>
115
116 <?php if (
117 ( isset( $settings['show_author'] ) && 'yes' === $settings['show_author'] ) ||
118 ( isset( $settings['show_date'] ) && 'yes' === $settings['show_date'] ) ||
119 ( isset( $settings['show_reading_time'] ) && 'yes' === $settings['show_reading_time'] )
120 ) : ?>
121 <div class="upk-meta">
122
123 <?php if ( isset( $settings['show_author'] ) && 'yes' === $settings['show_author'] ) : ?>
124 <div class="upk-author">
125 <span><?php echo esc_html_x( 'by', 'Frontend', 'ultimate-post-kit' ); ?></span>
126 <a href="<?php echo esc_url( $author_url ); ?>">
127 <?php echo esc_html( $author_name ); ?>
128 </a>
129 </div>
130 <?php endif; ?>
131
132 <?php if ( isset( $settings['show_date'] ) && 'yes' === $settings['show_date'] ) : ?>
133 <div data-separator="<?php echo esc_attr( $settings['meta_separator'] ); ?>">
134 <div class="upk-date">
135 <?php
136 if ( 'yes' === $settings['human_diff_time'] ) {
137 echo esc_html(
138 ultimate_post_kit_post_time_diff(
139 ( 'yes' === $settings['human_diff_time_short'] ) ? 'short' : ''
140 )
141 );
142 } else {
143 echo esc_html( get_the_date() );
144 }
145 ?>
146 </div>
147
148 <?php if ( 'yes' === $settings['show_time'] && 'yes' !== $settings['human_diff_time'] ) : ?>
149 <div class="upk-post-time">
150 <i class="upk-icon-clock" aria-hidden="true"></i>
151 <?php echo esc_html( get_the_time() ); ?>
152 </div>
153 <?php endif; ?>
154 </div>
155 <?php endif; ?>
156
157 <?php
158 if (
159 function_exists( 'ultimate_post_kit_reading_time' ) &&
160 isset( $settings['show_reading_time'] ) &&
161 'yes' === $settings['show_reading_time']
162 ) :
163 $speed = isset( $settings['avg_reading_speed'] ) ? (int) $settings['avg_reading_speed'] : 200;
164 ?>
165 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $settings['meta_separator'] ); ?>">
166 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
167 </div>
168 <?php endif; ?>
169 </div>
170 <?php endif; ?>
171 </div>
172 </div>
173 </div>
174 <?php
175 endwhile;
176 }
177
178 wp_reset_postdata();
179
180 $markup = ob_get_clean();
181
182 wp_send_json(
183 [
184 'success' => $found_posts,
185 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
186 ]
187 );
188 }
189 }
190