PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.2.0
Forumax – AI Powered Advanced Community Forum Plugin v2.2.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
← All changes | includes/ajax_actions.php +611 -156 1.3.32.2.0 View file →
@@ -1,156 +1,611 @@
1 -<?php
2 -
3 -/**
4 - * All Search results
5 - */
6 -add_action( 'wp_ajax_bbpc_search_data_fetch', 'bbpc_search_data_fetch' );
7 -add_action( 'wp_ajax_nopriv_bbpc_search_data_fetch', 'bbpc_search_data_fetch' );
8 -function bbpc_search_data_fetch() {
9 -
10 - $opt = get_option( 'bbpc_opt' );
11 - $is_ajax_search_tab = $opt['is_ajax_search_tab'] ?? '';
12 - global $post;
13 -
14 - if ( class_exists( 'bbPress' ) ) {
15 - // All results query
16 - $all_results = new WP_Query( array(
17 - 'post_type' => ['forum', 'topic' ],
18 - 's' => $_POST['keyword'] ?? '',
19 - ) );
20 - $all_results_count = $all_results->found_posts;
21 - if ( $all_results_count > 0 ) {
22 - $all_nsoresult = 'data-result=';
23 - } else {
24 - $all_nsoresult = 'data-noresult=';
25 - }
26 -
27 - // Forum query
28 - $forum_query = new WP_Query( array(
29 - 'post_type' => ['forum', 'topic'],
30 - 's' => $_POST['keyword'] ?? '',
31 - ) );
32 - $forum_count = $forum_query->found_posts;
33 - if ( $forum_count > 0 ) {
34 - $forum_nsoresult = 'data-result=';
35 - } else {
36 - $forum_nsoresult = 'data-noresult=';
37 - }
38 -
39 - ?>
40 - <div class="tab-item active all-active" <?php echo esc_attr( $all_nsoresult. 'No-Results-Found' ); ?>></div>
41 - <?php
42 - if ( class_exists( 'bbPress' ) ) : ?>
43 - <div id="search-forum" <?php echo esc_attr( $forum_nsoresult. 'No-Results-Found' ); ?> class="tab-item" ></div>
44 - <?php
45 - endif;
46 - }
47 -
48 - echo '<div class="bbpc-search-results-wrapper">';
49 -
50 - // Forums query
51 - if ( class_exists( 'bbPress' ) ) :
52 -
53 - echo '<div class="search-results-tab forum show" id="search-forum-results">';
54 -
55 - $forum = new WP_Query( array(
56 - 'post_type' => 'forum',
57 - 's' => $_POST['keyword'] ?? '',
58 - 'posts_per_page' => 5,
59 - ) );
60 -
61 - if ( $forum->have_posts() ) :
62 - echo '<h2 class="bbpc-search-title">' . esc_html__( 'Forums', 'bbp-core' ) . '</h2>';
63 - while ( $forum->have_posts() ) : $forum->the_post();
64 - ?>
65 - <div class="search-result-item forum" onclick="document.location='<?php echo get_the_permalink(get_the_ID()); ?>'">
66 - <a href="<?php echo get_the_permalink(get_the_ID()); ?>">
67 - <?php the_title(); ?>
68 - </a>
69 - </div>
70 - <?php
71 - endwhile;
72 - wp_reset_postdata();
73 - endif;
74 -
75 - $topics = new WP_Query( array(
76 - 'post_type' => 'topic',
77 - 's' => $_POST['keyword'] ?? '',
78 - 'posts_per_page' => 5,
79 - ) );
80 -
81 - if ( $topics->have_posts() ) :
82 - echo '<h2 class="bbpc-search-title">' . esc_html__( 'Topics', 'bbp-core' ) . '</h2>';
83 - while ( $topics->have_posts() ) : $topics->the_post();
84 - ?>
85 - <div class="search-result-item forum" onclick="document.location='<?php echo get_the_permalink(get_the_ID()); ?>'">
86 - <a href="<?php echo get_the_permalink(get_the_ID()); ?>">
87 - <?php the_title(); ?>
88 - </a>
89 - </div>
90 - <?php
91 - endwhile;
92 - wp_reset_postdata();
93 - endif;
94 - echo '</div>';
95 - endif;
96 -
97 - echo '<h5 class="not-found-text">Not Found Result!</h5>';
98 - echo '</div>';
99 - die();
100 -}
101 -
102 -/**
103 - * Forum Search results
104 - */
105 -add_action( 'wp_ajax_bbpc_search_data_forum', 'bbpc_search_data_forum' );
106 -add_action( 'wp_ajax_nopriv_bbpc_search_data_forum', 'bbpc_search_data_forum' );
107 -function bbpc_search_data_forum() {
108 -
109 - // Forums query
110 - if ( class_exists( 'bbPress' ) ) :
111 -
112 - echo '<div class="search-results-tab show" id="search-forum-results">';
113 -
114 - $forum = new WP_Query( array(
115 - 'post_type' => 'forum',
116 - 's' => $_POST['keyword'] ?? '',
117 - 'posts_per_page' => 5,
118 - ) );
119 -
120 - if ( $forum->have_posts() ) :
121 - echo '<h2 class="bbpc-search-title">' . esc_html__( 'Forums', 'bbp-core' ) . '</h2>';
122 - while ( $forum->have_posts() ) : $forum->the_post();
123 - ?>
124 - <div class="search-result-item forum" onclick="document.location='<?php echo get_the_permalink(get_the_ID()); ?>'">
125 - <a href="<?php echo get_the_permalink(get_the_ID()); ?>">
126 - <?php the_title(); ?>
127 - </a>
128 - </div>
129 - <?php
130 - endwhile;
131 - wp_reset_postdata();
132 - endif;
133 -
134 - $topics = new WP_Query( array(
135 - 'post_type' => 'topic',
136 - 's' => $_POST['keyword'] ?? '',
137 - 'posts_per_page' => 5,
138 - ) );
139 -
140 - if ( $topics->have_posts() ) :
141 - echo '<h2 class="bbpc-search-title">' . esc_html__( 'Topics', 'bbp-core' ) . '</h2>';
142 - while ( $topics->have_posts() ) : $topics->the_post();
143 - ?>
144 - <div class="search-result-item forum" onclick="document.location='<?php echo get_the_permalink(get_the_ID()); ?>'">
145 - <a href="<?php echo get_the_permalink(get_the_ID()); ?>">
146 - <?php the_title(); ?>
147 - </a>
148 - </div>
149 - <?php
150 - endwhile;
151 - wp_reset_postdata();
152 - endif;
153 - echo '</div>';
154 - endif;
155 - die();
156 -}
1 +<?php
2 +/**
3 + * Ajax actions for Forumax
4 + *
5 + * @package Forumax
6 + */
7 +
8 +defined( 'ABSPATH' ) || exit;
9 +
10 +defined( 'ABSPATH' ) || exit;
11 +
12 +/**
13 + * All Search results
14 + */
15 +add_action( 'wp_ajax_forumax_search_data_fetch', 'forumax_search_data_fetch' );
16 +add_action( 'wp_ajax_nopriv_forumax_search_data_fetch', 'forumax_search_data_fetch' );
17 +
18 +/**
19 + * Fetch search data.
20 + */
21 +function forumax_search_data_fetch() {
22 +
23 + // Check nonce.
24 + check_ajax_referer( 'forumax-nonce', 'nonce' );
25 +
26 + $opt = get_option( 'bbpc_opt' );
27 + $is_ajax_search_tab = $opt['is_ajax_search_tab'] ?? '';
28 +
29 + // Sanitize keyword.
30 + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( $_POST['keyword'] ) : '';
31 + $post_type = isset( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : '';
32 +
33 + // Determine which post types to query.
34 + if ( ! empty( $post_type ) ) {
35 + $query_post_types = array( $post_type );
36 + } elseif ( class_exists( 'bbPress' ) ) {
37 + $query_post_types = array( 'forum', 'topic' );
38 + } else {
39 + $query_post_types = array( 'post' );
40 + }
41 +
42 + // Main results query.
43 + $results = new \WP_Query( array(
44 + 'post_type' => $query_post_types,
45 + 's' => $keyword,
46 + 'posts_per_page' => 10,
47 + ) );
48 +
49 + $results_count = $results->found_posts;
50 +
51 + if ( $results_count > 0 ) {
52 + $nsoresult = 'data-result=';
53 + } else {
54 + $nsoresult = 'data-noresult=';
55 + }
56 +
57 + ?>
58 + <div class="tab-item active all-active" <?php echo esc_attr( $nsoresult . 'No-Results-Found' ); ?>></div>
59 + <?php
60 +
61 + echo '<div class="bbpc-search-results-wrapper">';
62 + echo '<div class="search-results-tab forum show" id="search-forum-results">';
63 +
64 + if ( $results->have_posts() ) :
65 + // Group results by post type.
66 + $grouped = array();
67 + while ( $results->have_posts() ) :
68 + $results->the_post();
69 + $type = get_post_type();
70 + if ( ! isset( $grouped[ $type ] ) ) {
71 + $grouped[ $type ] = array();
72 + }
73 + $grouped[ $type ][] = array(
74 + 'id' => get_the_ID(),
75 + 'title' => get_the_title(),
76 + 'url' => get_the_permalink(),
77 + );
78 + endwhile;
79 + wp_reset_postdata();
80 +
81 + // Render grouped results.
82 + $type_labels = array(
83 + 'forum' => __( 'Forums', 'forumax' ),
84 + 'topic' => __( 'Topics', 'forumax' ),
85 + 'docs' => __( 'Documentation', 'forumax' ),
86 + 'post' => __( 'Posts', 'forumax' ),
87 + );
88 +
89 + foreach ( $grouped as $type => $posts ) :
90 + $label = isset( $type_labels[ $type ] ) ? $type_labels[ $type ] : ucfirst( $type );
91 + echo '<h2 class="bbpc-search-title">' . esc_html( $label ) . '</h2>';
92 + foreach ( $posts as $post_item ) :
93 + ?>
94 + <div class="search-result-item forum" onclick="document.location='<?php echo esc_url( $post_item['url'] ); ?>'">
95 + <a href="<?php echo esc_url( $post_item['url'] ); ?>">
96 + <?php echo esc_html( $post_item['title'] ); ?>
97 + </a>
98 + </div>
99 + <?php
100 + endforeach;
101 + endforeach;
102 + endif;
103 +
104 + echo '</div>';
105 + echo '<h5 class="not-found-text">' . esc_html__( 'Not Found Result!', 'forumax' ) . '</h5>';
106 + echo '</div>';
107 + wp_die();
108 +}
109 +
110 +/**
111 + * Forum Search results
112 + */
113 +add_action( 'wp_ajax_forumax_search_data_forum', 'forumax_search_data_forum' );
114 +add_action( 'wp_ajax_nopriv_forumax_search_data_forum', 'forumax_search_data_forum' );
115 +
116 +/**
117 + * Search data forum.
118 + */
119 +function forumax_search_data_forum() {
120 +
121 + // Check nonce
122 + check_ajax_referer( 'forumax-nonce', 'nonce' );
123 +
124 + // Sanitize keyword
125 + $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( $_POST['keyword'] ) : '';
126 +
127 + // Forums query
128 + if ( class_exists( 'bbPress' ) ) :
129 +
130 + echo '<div class="search-results-tab show" id="search-forum-results">';
131 +
132 + $forum = new WP_Query( [
133 + 'post_type' => 'forum',
134 + 's' => $keyword,
135 + 'posts_per_page' => 5,
136 + ] );
137 +
138 + if ( $forum->have_posts() ) :
139 + echo '<h2 class="bbpc-search-title">' . esc_html__( 'Forums', 'forumax' ) . '</h2>';
140 + while ( $forum->have_posts() ) : $forum->the_post();
141 + ?>
142 + <div class="search-result-item forum" onclick="document.location='<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>'">
143 + <a href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>">
144 + <?php the_title(); ?>
145 + </a>
146 + </div>
147 + <?php
148 + endwhile;
149 + wp_reset_postdata();
150 + endif;
151 +
152 + $topics = new WP_Query( [
153 + 'post_type' => 'topic',
154 + 's' => $keyword,
155 + 'posts_per_page' => 5,
156 + ] );
157 +
158 + if ( $topics->have_posts() ) :
159 + echo '<h2 class="bbpc-search-title">' . esc_html__( 'Topics', 'forumax' ) . '</h2>';
160 + while ( $topics->have_posts() ) : $topics->the_post();
161 + ?>
162 + <div class="search-result-item forum" onclick="document.location='<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>'">
163 + <a href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>">
164 + <?php the_title(); ?>
165 + </a>
166 + </div>
167 + <?php
168 + endwhile;
169 + wp_reset_postdata();
170 + endif;
171 + echo '</div>';
172 + endif;
173 + wp_die();
174 +}
175 +
176 +/**
177 + * AJAX handler to fetch forums for Gutenberg block editor
178 + * Used by the Single Forum block to populate the forum selector dropdown
179 + */
180 +add_action( 'wp_ajax_bbpc_get_forums', 'forumax_get_forums_ajax' );
181 +
182 +/**
183 + * Get forums ajax.
184 + */
185 +function forumax_get_forums_ajax() {
186 + // Verify nonce for security
187 + check_ajax_referer( 'forumax-nonce', 'nonce' );
188 +
189 + if ( ! current_user_can( 'edit_posts' ) ) {
190 + wp_send_json_error( 'Unauthorized' );
191 + }
192 +
193 + // Get all forums
194 + $forums = new \WP_Query( [
195 + 'post_type' => 'forum',
196 + 'posts_per_page' => -1,
197 + 'orderby' => 'title',
198 + 'order' => 'ASC',
199 + ] );
200 +
201 + $forum_list = [];
202 +
203 + if ( $forums->have_posts() ) {
204 + while ( $forums->have_posts() ) {
205 + $forums->the_post();
206 + $forum_list[] = [
207 + 'id' => get_the_ID(),
208 + 'title' => get_the_title(),
209 + ];
210 + }
211 + wp_reset_postdata();
212 + }
213 +
214 + wp_send_json_success( $forum_list );
215 +}
216 +
217 +
218 +/**
219 + * Loading Post
220 + */
221 +add_action( 'wp_ajax_forumax_loading_post', 'forumax_loading_post' );
222 +add_action( 'wp_ajax_nopriv_forumax_loading_post', 'forumax_loading_post' );
223 +
224 +/**
225 + * Loading forum posts
226 + *
227 + * @return void
228 + */
229 +function forumax_loading_post() {
230 + // Check nonce
231 + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) {
232 + wp_die( '-1' );
233 + }
234 +
235 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
236 + $post_in = isset( $_POST['a_t_id'] ) ? sanitize_text_field( wp_unslash( $_POST['a_t_id'] ) ) : '';
237 + $count = isset( $_POST['count'] ) ? sanitize_text_field( wp_unslash( $_POST['count'] ) ) : '';
238 + $parent = isset( $_POST['parent'] ) ? sanitize_text_field( wp_unslash( $_POST['parent'] ) ) : '';
239 +
240 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
241 + $q = [
242 + 'post_type' => 'topic',
243 + 'post_parent' => $parent,
244 + 'order' => 'DESC',
245 + 'orderby' => 'post_date',
246 + 'post_status' => 'publish',
247 + 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ),
248 + 'ignore_sticky_posts' => 1,
249 + ];
250 +
251 + if ( 'author' === $type ) {
252 + $auth_ids = [
253 + 'author' => $post_in,
254 + ];
255 + $q = array_merge( $q, $auth_ids );
256 + } elseif ( 'tag' === $type ) {
257 + $tax_query[] = [
258 + 'taxonomy' => 'topic-tag',
259 + 'field' => 'term_id',
260 + 'terms' => $post_in,
261 + ];
262 + }
263 +
264 + $tax_query[] = [
265 + 'taxonomy' => 'post_format',
266 + 'field' => 'slug',
267 + 'terms' => [ 'post-format-quote', 'post-format-link' ],
268 + 'operator' => 'NOT IN',
269 + ];
270 +
271 + if ( ! empty( $tax_query ) ) {
272 + $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query );
273 + $q = array_merge( $q, [ 'tax_query' => $tax_query ] );
274 + }
275 +
276 + $query = new WP_Query( $q );
277 +
278 + if ( $query->have_posts() ) :
279 + echo '<div class="community-posts-wrapper bb-radius">';
280 + while ( $query->have_posts() ) : $query->the_post();
281 + global $post;
282 + $author_id = $post->post_author;
283 + $parent_post_id = $parent;
284 + $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true );
285 + $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0';
286 + $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true );
287 + $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0;
288 + ?>
289 + <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>">
290 + <div class="post-content">
291 + <div class="author-avatar">
292 + <?php
293 + echo bbp_get_topic_author_link(
294 + [
295 + 'post_id' => get_the_ID(),
296 + 'type' => 'avatar',
297 + 'size' => 40,
298 + ]
299 + );
300 + ?>
301 + </div>
302 + <div class="entry-content">
303 + <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', esc_url( get_permalink() ) ), '</h3></a>' ); ?>
304 + <ul class="meta">
305 + <li>
306 + <?php echo get_the_post_thumbnail( bbp_get_topic_forum_id(), [ 40, 40 ] ); ?>
307 + <a href="<?php echo get_permalink( bbp_get_topic_forum_id() ); ?>">
308 + <?php echo get_the_title( bbp_get_topic_forum_id() ); ?>
309 + </a>
310 + </li>
311 + <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li>
312 + </ul>
313 + </div>
314 + </div>
315 + <div class="post-meta-wrapper">
316 + <ul class="post-meta-info">
317 + <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li>
318 + <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li>
319 + </ul>
320 + </div>
321 + </div>
322 + <?php
323 + endwhile;
324 + wp_reset_postdata();
325 +
326 + echo '</div>';
327 + else :
328 + echo '<div class="community-post-error bug">';
329 + echo '<div class="error-content">';
330 + echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>';
331 + echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>';
332 + echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>';
333 + echo '</div>';
334 + echo '</div>';
335 + endif;
336 +
337 + wp_die();
338 +}
339 +
340 +/**
341 + * Filter posts by status (open/closed)
342 + *
343 + * @return void
344 + */
345 +add_action( 'wp_ajax_forumax_open_post', 'forumax_open_post' );
346 +add_action( 'wp_ajax_nopriv_forumax_open_post', 'forumax_open_post' );
347 +
348 +/**
349 + * Open post.
350 + */
351 +function forumax_open_post() {
352 +
353 + // Check nonce
354 + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) {
355 + wp_die( '-1' );
356 + }
357 +
358 + $is_queried_obj = is_singular( 'forum' ) ? get_queried_object_id() : false;
359 + $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
360 + $post_in = isset( $_POST['a_t_id'] ) ? sanitize_text_field( wp_unslash( $_POST['a_t_id'] ) ) : '';
361 + $count = isset( $_POST['count'] ) ? sanitize_text_field( wp_unslash( $_POST['count'] ) ) : '';
362 + $parent = isset( $_POST['parent'] ) ? sanitize_text_field( wp_unslash( $_POST['parent'] ) ) : '';
363 + $userid = isset( $_POST['userid'] ) ? sanitize_text_field( wp_unslash( $_POST['userid'] ) ) : '';
364 +
365 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
366 + $q = [
367 + 'post_type' => 'topic',
368 + 'post_parent' => $parent,
369 + 'order' => 'DESC',
370 + 'orderby' => 'post_date',
371 + 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ),
372 + 'ignore_sticky_posts' => 1,
373 + 'author' => $userid,
374 + ];
375 +
376 + if ( 'open' === $type ) {
377 + $status = [
378 + 'post_status' => 'publish',
379 + ];
380 + $q = array_merge( $q, $status );
381 + } elseif ( 'closed' === $type ) {
382 + $status = [
383 + 'post_status' => 'closed',
384 + ];
385 + $q = array_merge( $q, $status );
386 + }
387 +
388 + $tax_query[] = [
389 + 'taxonomy' => 'post_format',
390 + 'field' => 'slug',
391 + 'terms' => [ 'post-format-quote', 'post-format-link' ],
392 + 'operator' => 'NOT IN',
393 + ];
394 +
395 + if ( ! empty( $tax_query ) ) {
396 + $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query );
397 + $q = array_merge( $q, [ 'tax_query' => $tax_query ] );
398 + }
399 +
400 + $query = new WP_Query( $q );
401 + if ( $query->have_posts() ) :
402 + echo '<div class="community-posts-wrapper bb-radius">';
403 + while ( $query->have_posts() ) : $query->the_post();
404 + global $post;
405 + $author_id = $post->post_author;
406 + //$parent_post_id = get_post_meta( get_the_ID(), '_bbp_topic_id', true );
407 + $parent_post_id = $parent;
408 + $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true );
409 + $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0';
410 + $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true );
411 + $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0;
412 + ?>
413 +
414 + <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>">
415 + <div class="post-content">
416 + <div class="author-avatar">
417 + <?php
418 + echo bbp_get_topic_author_link(
419 + [
420 + 'post_id' => get_the_ID(),
421 + 'type' => 'avatar',
422 + 'size' => 40,
423 + ]
424 + );
425 + ?>
426 + </div>
427 + <div class="entry-content">
428 + <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', get_permalink() ), '</h3></a>' ); ?>
429 + <ul class="meta">
430 + <li>
431 + <?php echo get_the_post_thumbnail( bbp_get_topic_forum_id(), [ 40, 40 ] ); ?>
432 + <a href="<?php echo get_permalink( bbp_get_topic_forum_id() ); ?>">
433 + <?php echo get_the_title( bbp_get_topic_forum_id() ); ?>
434 + </a>
435 + </li>
436 + <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li>
437 + </ul>
438 + </div>
439 + </div>
440 + <div class="post-meta-wrapper">
441 + <ul class="post-meta-info">
442 + <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li>
443 + <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li>
444 + </ul>
445 + </div>
446 + </div>
447 + <?php
448 + endwhile;
449 + wp_reset_postdata();
450 +
451 + echo '</div>';
452 + else :
453 + echo '<div class="community-post-error bug">';
454 + echo '<div class="error-content">';
455 + echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>';
456 + echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>';
457 + echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>';
458 + echo '</div>';
459 + echo '</div>';
460 + endif;
461 + wp_die();
462 +}
463 +
464 +/**
465 + * Sort posts
466 + *
467 + * @return void
468 + */
469 +add_action( 'wp_ajax_forumax_loading_sort_post', 'forumax_loading_sort_post' );
470 +add_action( 'wp_ajax_nopriv_forumax_loading_sort_post', 'forumax_loading_sort_post' );
471 +
472 +/**
473 + * Loading sort post.
474 + */
475 +function forumax_loading_sort_post() {
476 +
477 + // Check nonce
478 + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) {
479 + wp_die( '-1' );
480 + }
481 +
482 + $sort = isset( $_POST['sort'] ) ? sanitize_text_field( wp_unslash( $_POST['sort'] ) ) : '';
483 + $parent = isset( $_POST['parent'] ) ? sanitize_text_field( wp_unslash( $_POST['parent'] ) ) : '';
484 +
485 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
486 + $q = [
487 + 'post_type' => 'topic',
488 + 'post_parent' => $parent,
489 + 'post_status' => 'publish',
490 + 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ),
491 + 'ignore_sticky_posts' => 1,
492 + ];
493 +
494 + if ( 'newest_posts' === $sort ) {
495 + $newest_posts = [
496 + 'order' => 'DESC',
497 + ];
498 + $q = array_merge( $q, $newest_posts );
499 + } elseif ( 'oldest_posts' === $sort ) {
500 + $oldest_posts = [
501 + 'order' => 'ASC',
502 + ];
503 + $q = array_merge( $q, $oldest_posts );
504 + } elseif ( 'comment_count' === $sort ) {
505 + $comment_count = [
506 + 'meta_key' => '_bbp_reply_count',
507 + 'orderby' => 'meta_value_num',
508 + 'order' => 'DESC',
509 + ];
510 + $q = array_merge( $q, $comment_count );
511 + } elseif ( 'comment_date' === $sort ) {
512 + $comment_count = [
513 + 'meta_key' => '_bbp_reply_count',
514 + 'meta_type' => 'NUMERIC',
515 + 'orderby' => 'meta_value_num',
516 + 'order' => 'ASC',
517 + ];
518 + $q = array_merge( $q, $comment_count );
519 + } elseif ( 'recent_updated_post' === $sort ) {
520 + $post_date = [
521 + 'orderby' => 'post_modified',
522 + 'order' => 'DESC',
523 + ];
524 + $q = array_merge( $q, $post_date );
525 + } elseif ( 'last_recent_updated_post' === $sort ) {
526 + $post_modified = [
527 + 'orderby' => 'post_modified',
528 + 'order' => 'ASC',
529 + ];
530 + $q = array_merge( $q, $post_modified );
531 + }
532 +
533 + $tax_query[] = [
534 + 'taxonomy' => 'post_format',
535 + 'field' => 'slug',
536 + 'terms' => [ 'post-format-quote', 'post-format-link' ],
537 + 'operator' => 'NOT IN',
538 + ];
539 +
540 + if ( ! empty( $tax_query ) ) {
541 + $tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query );
542 + $q = array_merge( $q, [ 'tax_query' => $tax_query ] );
543 + }
544 +
545 + $query = new WP_Query( $q );
546 + if ( $query->have_posts() ) :
547 + echo '<div class="community-posts-wrapper bb-radius">';
548 + while ( $query->have_posts() ) : $query->the_post();
549 + global $post;
550 +
551 + $author_id = $post->post_author;
552 + $parent_post_id = $parent;
553 + $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true );
554 + $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0';
555 + $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true );
556 + $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0;
557 + ?>
558 + <div class="community-post style-two <?php the_author_meta( 'user_nicename', $author_id ); ?>">
559 + <div class="post-content">
560 + <div class="author-avatar">
561 + <?php
562 + echo bbp_get_topic_author_link(
563 + [
564 + 'post_id' => get_the_ID(),
565 + 'type' => 'avatar',
566 + 'size' => 40,
567 + ]
568 + );
569 + ?>
570 + </div>
571 + <div class="entry-content">
572 + <?php the_title( sprintf( '<a href="%s" rel="bookmark"> <h3 class="post-title">', esc_url( get_permalink() ) ), '</h3></a>' ); ?>
573 + <ul class="meta">
574 + <li>
575 + <?php
576 + if ( get_the_post_thumbnail_url( $parent_post_id ) ) :
577 + ?>
578 + <img src="<?php echo get_the_post_thumbnail_url( $parent_post_id ); ?>"
579 + alt="<?php echo get_the_title( $parent_post_id ); ?>">
580 + <?php
581 + endif;
582 + ?>
583 + <a href="<?php echo get_permalink( $parent_post_id ); ?>"> <?php echo get_the_title( $parent_post_id ); ?> </a>
584 + </li>
585 + <li><i class="icon_clock_alt"></i> <?php bbp_topic_post_date( get_the_ID() ); ?> </li>
586 + </ul>
587 + </div>
588 + </div>
589 + <div class="post-meta-wrapper">
590 + <ul class="post-meta-info">
591 + <li><a href="#"><i class="icon_chat_alt"></i><?php echo esc_html( $_reply_count ); ?></a></li>
592 + <li><a href="#"><i class="icon_star"></i><?php echo esc_html( $favorite_count ); ?></a></li>
593 + </ul>
594 + </div>
595 + </div>
596 + <?php endwhile;
597 + wp_reset_postdata();
598 +
599 + echo '</div>';
600 + else :
601 + echo '<div class="community-post-error bug">';
602 + echo '<div class="error-content">';
603 + echo '<svg height="40" class="forumax-error error-icon" viewBox="0 0 24 24" version="1.1" width="40" aria-hidden="true"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zm1 9a1 1 0 11-2 0 1 1 0 012 0z"></path><path fill-rule="evenodd" d="M12 1C5.925 1 1 5.925 1 12s4.925 11 11 11 11-4.925 11-11S18.075 1 12 1zM2.5 12a9.5 9.5 0 1119 0 9.5 9.5 0 01-19 0z"></path></svg>';
604 + echo '<h3 class="error">' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '</h3>';
605 + echo '<p class="error">' . esc_html__( 'You could search again.', 'forumax' ) . '</p>';
606 + echo '</div>';
607 + echo '</div>';
608 + endif;
609 +
610 + wp_die();
611 +}