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

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

174 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UltimatePostKit\Modules\AmoxGrid;
3 use UltimatePostKit\Traits\Global_Widget_Functions;
4
5 use UltimatePostKit\Base\Ultimate_Post_Kit_Module_Base;
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
16 parent::__construct();
17
18 add_action( 'wp_ajax_nopriv_upk_amox_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
19 add_action( 'wp_ajax_upk_amox_grid_loadmore_posts', [ $this, 'callback_ajax_loadmore_posts' ] );
20 }
21
22 public function get_name() {
23 return 'amox-grid';
24 }
25
26 public function get_widgets() {
27
28 $widgets = [
29 'Amox_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 $post_type = $settings['posts_source'] ?? 'post';
44
45 $settings = array_merge(
46 [
47 'posts_source' => 'post',
48 'posts_orderby' => 'date',
49 'posts_order' => 'DESC',
50 'posts_ignore_sticky_posts' => 'no',
51 'posts_only_with_featured_image' => 'no',
52 'posts_select_date' => '',
53 'posts_exclude_by' => [],
54 'posts_include_by' => [],
55 'posts_per_page' => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : 0,
56 'posts_offset' => isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0,
57 ],
58 $settings
59 );
60
61 $ajaxposts = $this->query_args( $settings );
62
63 ob_start();
64 $found_posts = false;
65
66 if ( $ajaxposts->have_posts() ) {
67
68 $i = 0;
69 while ( $ajaxposts->have_posts() ) {
70 $ajaxposts->the_post();
71 $found_posts = true;
72 $i++;
73
74 $title = get_the_title();
75 $post_link = esc_url( get_permalink() );
76 $meta_sep = $settings['meta_separator'] ?? '.';
77 $title_tag = Utils::get_valid_html_tag($settings['title_tags']);
78
79 $onclick = '';
80 if ( ! empty( $settings['global_link'] ) && $settings['global_link'] === 'yes' ) {
81 $onclick = 'onclick="window.open(\'' . esc_url( $post_link ) . '\', \'_self\')"';
82 }
83
84 ?>
85 <div <?php echo $onclick; ?> class="upk-item">
86 <div class="upk-img-wrap">
87 <?php $this->render_image( get_post_thumbnail_id(), 'large' ); ?>
88 </div>
89
90 <div class="upk-content">
91 <?php if ( $settings['show_category'] === 'yes' ) : ?>
92 <div class="upk-category">
93 <?php echo wp_kses_post( upk_get_category( $post_type ) ); ?>
94 </div>
95 <?php endif; ?>
96
97 <?php if ( $settings['show_title'] === 'yes' ) : ?>
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'] ?? 'underline' ); ?>"
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 $settings['show_comments'] === 'yes' ||
112 $settings['show_date'] === 'yes' ||
113 $settings['show_reading_time'] === 'yes'
114 ) : ?>
115 <div class="upk-meta upk-flex-inline upk-flex-middle">
116 <?php if ( $settings['show_date'] === 'yes' ) : ?>
117 <div class="upk-date">
118 <?php
119 if ( $settings['show_date'] === 'yes' && $settings['human_diff_time'] !== 'yes' ) {
120 echo esc_html( get_the_date() );
121 }
122 if ( $settings['human_diff_time'] === 'yes' ) {
123 echo esc_html( ultimate_post_kit_post_time_diff( $settings['human_diff_time_short'] !== 'yes' ? 'short' : '' ) );
124 }
125 ?>
126 </div>
127
128 <?php if ( $settings['show_time'] === 'yes' ) : ?>
129 <div class="upk-post-time">
130 <i class="upk-icon-clock" aria-hidden="true"></i>
131 <?php echo esc_html( get_the_time() ); ?>
132 </div>
133 <?php endif; ?>
134 <?php endif; ?>
135
136 <?php if (
137 function_exists( '_is_upk_pro_activated' ) &&
138 _is_upk_pro_activated() &&
139 function_exists( 'ultimate_post_kit_reading_time' ) &&
140 ( $settings['show_reading_time'] ?? '' ) === 'yes'
141 ) : ?>
142 <div class="upk-reading-time" data-separator="<?php echo esc_html( $meta_sep ); ?>">
143 <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?>
144 </div>
145 <?php endif; ?>
146
147 <?php if ( $settings['show_comments'] === 'yes' ) : ?>
148 <div data-separator="<?php echo esc_html( $meta_sep ); ?>">
149 <div class="upk-comments upk-flex upk-flex-middle">
150 <i class="upk-icon-post-comments" aria-hidden="true"></i>
151 <span><?php echo esc_html( $this->upk_get_localized_comment_count( get_the_ID() ) ); ?></span>
152 </div>
153 </div>
154 <?php endif; ?>
155 </div>
156 <?php endif; ?>
157 </div>
158 </div>
159 <?php
160 }
161 }
162
163 wp_reset_postdata();
164 $markup = ob_get_clean();
165
166 wp_send_json(
167 [
168 'success' => $found_posts,
169 'markup' => $found_posts ? $markup : esc_html__( 'No more found', 'ultimate-post-kit' ),
170 ]
171 );
172 }
173 }
174