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

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

184 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 ?>
82 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
83 <div class="upk-item-box">
84
85 <div class="upk-img-wrap">
86 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>">
87 </div>
88
89 <?php if ( isset( $settings['show_category'] ) && 'yes' === $settings['show_category'] ) : ?>
90 <div class="upk-category">
91 <?php echo wp_kses_post( upk_get_category( $settings['post_source'] ) ); ?>
92 </div>
93 <?php endif; ?>
94
95 <div class="upk-content">
96
97 <?php if ( ! isset( $settings['show_title'] ) || 'yes' === $settings['show_title'] ) : ?>
98 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
99 <a
100 href="<?php echo esc_url( $post_link ); ?>"
101 title="<?php echo esc_attr( $title ); ?>"
102 class="title-animation-<?php echo esc_attr( $settings['title_style'] ); ?>"
103 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
104 >
105 <?php echo esc_html( $title ); ?>
106 </a>
107 </<?php echo esc_attr( $title_tag ); ?>>
108 <?php endif; ?>
109
110 <?php if (
111 ( isset( $settings['show_author'] ) && 'yes' === $settings['show_author'] ) ||
112 ( isset( $settings['show_date'] ) && 'yes' === $settings['show_date'] ) ||
113 ( isset( $settings['show_reading_time'] ) && 'yes' === $settings['show_reading_time'] )
114 ) : ?>
115 <div class="upk-meta">
116
117 <?php if ( isset( $settings['show_author'] ) && 'yes' === $settings['show_author'] ) : ?>
118 <div class="upk-author">
119 <span><?php echo esc_html_x( 'by', 'Frontend', 'ultimate-post-kit' ); ?></span>
120 <a href="<?php echo esc_url( $author_url ); ?>">
121 <?php echo esc_html( $author_name ); ?>
122 </a>
123 </div>
124 <?php endif; ?>
125
126 <?php if ( isset( $settings['show_date'] ) && 'yes' === $settings['show_date'] ) : ?>
127 <div data-separator="<?php echo esc_attr( $settings['meta_separator'] ); ?>">
128 <div class="upk-date">
129 <?php
130 if ( 'yes' === $settings['human_diff_time'] ) {
131 echo esc_html(
132 ultimate_post_kit_post_time_diff(
133 ( 'yes' === $settings['human_diff_time_short'] ) ? 'short' : ''
134 )
135 );
136 } else {
137 echo esc_html( get_the_date() );
138 }
139 ?>
140 </div>
141
142 <?php if ( 'yes' === $settings['show_time'] && 'yes' !== $settings['human_diff_time'] ) : ?>
143 <div class="upk-post-time">
144 <i class="upk-icon-clock" aria-hidden="true"></i>
145 <?php echo esc_html( get_the_time() ); ?>
146 </div>
147 <?php endif; ?>
148 </div>
149 <?php endif; ?>
150
151 <?php
152 if (
153 function_exists( 'ultimate_post_kit_reading_time' ) &&
154 isset( $settings['show_reading_time'] ) &&
155 'yes' === $settings['show_reading_time']
156 ) :
157 $speed = isset( $settings['avg_reading_speed'] ) ? (int) $settings['avg_reading_speed'] : 200;
158 ?>
159 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $settings['meta_separator'] ); ?>">
160 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
161 </div>
162 <?php endif; ?>
163 </div>
164 <?php endif; ?>
165 </div>
166 </div>
167 </div>
168 <?php
169 endwhile;
170 }
171
172 wp_reset_postdata();
173
174 $markup = ob_get_clean();
175
176 wp_send_json(
177 [
178 'success' => $found_posts,
179 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
180 ]
181 );
182 }
183 }
184