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

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

201 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\GratisGrid;
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_gratis_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
18 add_action( 'wp_ajax_upk_gratis_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 }
20
21 public function get_name() {
22 return 'gratis-grid';
23 }
24
25 public function get_widgets() {
26
27 $widgets = [
28 'Gratis_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 $meta_sep = $settings['meta_separator'] ?? '/';
69
70 while ( $ajaxposts->have_posts() ) {
71
72 $ajaxposts->the_post();
73 $found_posts = true;
74 $title = get_the_title();
75 $post_link = get_permalink();
76 $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
77 $image_src = $image_src ? $image_src[0] : $placeholder;
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(\'' . esc_url( $post_link ) . '\', \'_self\')"';
83 }
84
85 ?>
86 <div <?php echo $onclick; ?> class="upk-item">
87 <div class="upk-img-wrap">
88 <img
89 class="upk-img"
90 src="<?php echo esc_url( $image_src ); ?>"
91 alt="<?php echo esc_attr( $title ); ?>"
92 >
93 </div>
94
95 <div class="upk-content-wrap">
96 <?php if ( $settings['show_category'] === 'yes' ) : ?>
97 <div class="upk-category">
98 <?php echo upk_get_category( $post_type ); ?>
99 </div>
100 <?php endif; ?>
101
102 <?php if ( ! isset( $settings['show_title'] ) || $settings['show_title'] === 'yes' ) : ?>
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 <?php endif; ?>
114
115 <?php if ( $settings['show_meta'] === 'yes' ) : ?>
116 <div class="upk-meta">
117 <div class="upk-author">
118 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
119 class="bi bi-person-circle" viewBox="0 0 16 16">
120 <path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z" />
121 <path fill-rule="evenodd"
122 d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z" />
123 </svg>
124 <span><?php echo esc_html__( 'by', 'ultimate-post-kit' ); ?></span>
125 <a class="upk-author-name" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
126 <span><?php echo esc_html( get_the_author() ); ?></span>
127 </a>
128 </div>
129
130 <?php if ( $settings['show_date'] || $settings['show_reading_time'] ) : ?>
131 <div class="upk-date-reading-time upk-flex upk-flex-middle">
132 <?php if ( $settings['show_date'] ) : ?>
133 <div class="upk-date">
134 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
135 class="bi bi-calendar" viewBox="0 0 16 16">
136 <path
137 d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z" />
138 </svg>
139 <?php
140 if ( $settings['human_diff_time'] == 'yes' ) {
141 echo esc_html(
142 ultimate_post_kit_post_time_diff(
143 ( $settings['human_diff_time_short'] == 'yes' ) ? 'short' : ''
144 )
145 );
146 } else {
147 echo esc_html( get_the_date() );
148 }
149 ?>
150 </div>
151
152 <?php if ( $settings['show_time'] ) : ?>
153 <div class="upk-post-time">
154 <i class="upk-icon-clock" aria-hidden="true"></i>
155 <?php echo esc_html( get_the_time() ); ?>
156 </div>
157 <?php endif; ?>
158 <?php endif; ?>
159
160 <?php if ( function_exists( 'ultimate_post_kit_reading_time' ) && $settings['show_reading_time'] === 'yes' ) : ?>
161 <div class="upk-reading-time">
162 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
163 </div>
164 <?php endif; ?>
165 </div>
166 <?php endif; ?>
167 </div>
168 <?php endif; ?>
169
170 <div class="upk-gratis-line"></div>
171
172 <?php if ( $settings['show_readmore'] === 'yes' ) : ?>
173 <div class="upk-link-button">
174 <a href="<?php echo esc_url( $post_link ); ?>">
175 <span><?php echo esc_html( $settings['readmore_text'] ); ?></span>
176 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
177 class="bi bi-arrow-right" viewBox="0 0 16 16">
178 <path fill-rule="evenodd"
179 d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z" />
180 </svg>
181 </a>
182 </div>
183 <?php endif; ?>
184 </div>
185 </div>
186 <?php
187 }
188 }
189
190 wp_reset_postdata();
191 $markup = ob_get_clean();
192
193 wp_send_json(
194 [
195 'success' => $found_posts,
196 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
197 ]
198 );
199 }
200 }
201