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

193 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\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 // Verify the front-end nonce (sent by UltimatePostKitConfig.nonce) before
37 // processing this public load-more request.
38 if ( ! check_ajax_referer( 'upk-site', 'nonce', false ) ) {
39 wp_send_json_error( array( 'message' => esc_html__( 'Security check failed.', 'ultimate-post-kit' ) ), 403 );
40 }
41
42
43 $settings = [];
44
45 if ( isset( $_POST['settings'] ) && is_array( $_POST['settings'] ) ) {
46 $settings = map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' );
47 }
48
49 $settings = array_merge(
50 [
51 'posts_source' => 'post',
52 'posts_orderby' => 'date',
53 'posts_order' => 'DESC',
54 'posts_ignore_sticky_posts' => 'no',
55 'posts_only_with_featured_image' => 'no',
56 'posts_select_date' => '',
57 'posts_exclude_by' => [],
58 'posts_include_by' => [],
59 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
60 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
61 ],
62 $settings
63 );
64
65 // Fill display flags the request may have omitted (see trait) before the render loop reads them.
66 $settings = array_merge( $this->loadmore_display_defaults(), $settings );
67
68 $ajaxposts = $this->query_args($settings);
69
70 ob_start();
71 $found_posts = false;
72
73 if ( $ajaxposts->have_posts() ) {
74
75 while ( $ajaxposts->have_posts() ) :
76
77 $ajaxposts->the_post();
78 $found_posts = true;
79
80 $title = get_the_title();
81 $post_link = esc_url( get_permalink() );
82 $author_url = get_author_posts_url( get_the_author_meta( 'ID' ) );
83 $author_name = get_the_author();
84 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
85
86 $placeholder_image_src = \Elementor\Utils::get_placeholder_image_src();
87 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
88 $image_src = $image_src ? $image_src[0] : $placeholder_image_src;
89
90 ?>
91 <div <?php if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) { printf( 'onclick="window.open(\'%s\', \'_self\')"', esc_url( $post_link ) ); } ?> class="upk-item">
92 <div class="upk-item-box">
93
94 <div class="upk-img-wrap">
95 <img class="upk-img" src="<?php echo esc_url( $image_src ); ?>" alt="<?php echo esc_attr( $title ); ?>">
96 </div>
97
98 <?php if ( isset( $settings['show_category'] ) && 'yes' === $settings['show_category'] ) : ?>
99 <div class="upk-category">
100 <?php echo wp_kses_post( upk_get_category( $settings['posts_source'] ?? 'post' ) ); ?>
101 </div>
102 <?php endif; ?>
103
104 <div class="upk-content">
105
106 <?php if ( ! isset( $settings['show_title'] ) || 'yes' === $settings['show_title'] ) : ?>
107 <<?php echo esc_attr( $title_tag ); ?> class="upk-title">
108 <a
109 href="<?php echo esc_url( $post_link ); ?>"
110 title="<?php echo esc_attr( $title ); ?>"
111 class="title-animation-<?php echo esc_attr( $settings['title_style'] ); ?>"
112 <?php echo $settings['upk_link_new_tab'] === 'yes' ? 'target="_blank"' : ''; ?>
113 >
114 <?php echo esc_html( $title ); ?>
115 </a>
116 </<?php echo esc_attr( $title_tag ); ?>>
117 <?php endif; ?>
118
119 <?php if (
120 ( isset( $settings['show_author'] ) && 'yes' === $settings['show_author'] ) ||
121 ( isset( $settings['show_date'] ) && 'yes' === $settings['show_date'] ) ||
122 ( isset( $settings['show_reading_time'] ) && 'yes' === $settings['show_reading_time'] )
123 ) : ?>
124 <div class="upk-meta">
125
126 <?php if ( isset( $settings['show_author'] ) && 'yes' === $settings['show_author'] ) : ?>
127 <div class="upk-author">
128 <span><?php echo esc_html_x( 'by', 'Frontend', 'ultimate-post-kit' ); ?></span>
129 <a href="<?php echo esc_url( $author_url ); ?>">
130 <?php echo esc_html( $author_name ); ?>
131 </a>
132 </div>
133 <?php endif; ?>
134
135 <?php if ( isset( $settings['show_date'] ) && 'yes' === $settings['show_date'] ) : ?>
136 <div data-separator="<?php echo esc_attr( $settings['meta_separator'] ); ?>">
137 <div class="upk-date">
138 <?php
139 if ( 'yes' === $settings['human_diff_time'] ) {
140 echo esc_html(
141 ultimate_post_kit_post_time_diff(
142 ( 'yes' === $settings['human_diff_time_short'] ) ? 'short' : ''
143 )
144 );
145 } else {
146 echo esc_html( get_the_date() );
147 }
148 ?>
149 </div>
150
151 <?php if ( 'yes' === $settings['show_time'] && 'yes' !== $settings['human_diff_time'] ) : ?>
152 <div class="upk-post-time">
153 <i class="upk-icon-clock" aria-hidden="true"></i>
154 <?php echo esc_html( get_the_time() ); ?>
155 </div>
156 <?php endif; ?>
157 </div>
158 <?php endif; ?>
159
160 <?php
161 if (
162 function_exists( 'ultimate_post_kit_reading_time' ) &&
163 isset( $settings['show_reading_time'] ) &&
164 'yes' === $settings['show_reading_time']
165 ) :
166 $speed = isset( $settings['avg_reading_speed'] ) ? (int) $settings['avg_reading_speed'] : 200;
167 ?>
168 <div class="upk-reading-time" data-separator="<?php echo esc_attr( $settings['meta_separator'] ); ?>">
169 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $speed, $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
170 </div>
171 <?php endif; ?>
172 </div>
173 <?php endif; ?>
174 </div>
175 </div>
176 </div>
177 <?php
178 endwhile;
179 }
180
181 wp_reset_postdata();
182
183 $markup = ob_get_clean();
184
185 wp_send_json(
186 [
187 'success' => $found_posts,
188 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
189 ]
190 );
191 }
192 }
193