PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.0
Forumax – AI Powered Advanced Community Forum Plugin v2.4.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
bbp-core / lib / bbpress / includes / forums / template.php

template.php in Forumax – AI Powered Advanced Community Forum Plugin 2.4.0, at lib/bbpress/includes/forums/template.php

2,721 lines 77.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Forum Template Tags
5 *
6 * @package bbPress
7 * @subpackage TemplateTags
8 */
9
10 // Exit if accessed directly
11 defined( 'ABSPATH' ) || exit;
12
13 /** Post Type *****************************************************************/
14
15 /**
16 * Output the unique id of the custom post type for forums
17 *
18 * @since 2.0.0 bbPress (r2857)
19 */
20 function bbp_forum_post_type() {
21 echo bbp_get_forum_post_type();
22 }
23 /**
24 * Return the unique id of the custom post type for forums
25 *
26 * @since 2.0.0 bbPress (r2857)
27 *
28 * @return string The unique forum post type id
29 */
30 function bbp_get_forum_post_type() {
31
32 // Filter & return
33 return apply_filters( 'bbp_get_forum_post_type', bbpress()->forum_post_type );
34 }
35
36
37 /**
38 * Return array of labels used by the forum post type
39 *
40 * @since 2.5.0 bbPress (r5129)
41 *
42 * @return array
43 */
44 function bbp_get_forum_post_type_labels() {
45
46 // Filter & return
47 return (array) apply_filters( 'bbp_get_forum_post_type_labels', array(
48 'name' => esc_attr__( 'Forums', 'bbpress' ),
49 'menu_name' => esc_attr__( 'Forums', 'bbpress' ),
50 'singular_name' => esc_attr__( 'Forum', 'bbpress' ),
51 'all_items' => esc_attr__( 'All Forums', 'bbpress' ),
52 'add_new' => esc_attr__( 'Add New', 'bbpress' ),
53 'add_new_item' => esc_attr__( 'Create New Forum', 'bbpress' ),
54 'edit' => esc_attr__( 'Edit', 'bbpress' ),
55 'edit_item' => esc_attr__( 'Edit Forum', 'bbpress' ),
56 'new_item' => esc_attr__( 'New Forum', 'bbpress' ),
57 'view' => esc_attr__( 'View Forum', 'bbpress' ),
58 'view_item' => esc_attr__( 'View Forum', 'bbpress' ),
59 'view_items' => esc_attr__( 'View Forums', 'bbpress' ),
60 'search_items' => esc_attr__( 'Search Forums', 'bbpress' ),
61 'not_found' => esc_attr__( 'No forums found', 'bbpress' ),
62 'not_found_in_trash' => esc_attr__( 'No forums found in Trash', 'bbpress' ),
63 'filter_items_list' => esc_attr__( 'Filter forums list', 'bbpress' ),
64 'items_list' => esc_attr__( 'Forums list', 'bbpress' ),
65 'items_list_navigation' => esc_attr__( 'Forums list navigation', 'bbpress' ),
66 'parent_item_colon' => esc_attr__( 'Parent Forum:', 'bbpress' ),
67 'archives' => esc_attr__( 'Forums', 'bbpress' ),
68 'attributes' => esc_attr__( 'Forum Attributes', 'bbpress' ),
69 'insert_into_item' => esc_attr__( 'Insert into forum', 'bbpress' ),
70 'uploaded_to_this_item' => esc_attr__( 'Uploaded to this forum', 'bbpress' ),
71 'featured_image' => esc_attr__( 'Forum Image', 'bbpress' ),
72 'set_featured_image' => esc_attr__( 'Set forum image', 'bbpress' ),
73 'remove_featured_image' => esc_attr__( 'Remove forum image', 'bbpress' ),
74 'use_featured_image' => esc_attr__( 'Use as forum image', 'bbpress' ),
75 'item_published' => esc_attr__( 'Forum published.', 'bbpress' ),
76 'item_published_privately' => esc_attr__( 'Forum published privately.', 'bbpress' ),
77 'item_reverted_to_draft' => esc_attr__( 'Forum reverted to draft.', 'bbpress' ),
78 'item_scheduled' => esc_attr__( 'Forum scheduled.', 'bbpress' ),
79 'item_updated' => esc_attr__( 'Forum updated.', 'bbpress' )
80 ) );
81 }
82
83 /**
84 * Return array of forum post type rewrite settings
85 *
86 * @since 2.5.0 bbPress (r5129)
87 *
88 * @return array
89 */
90 function bbp_get_forum_post_type_rewrite() {
91
92 // Filter & return
93 return (array) apply_filters( 'bbp_get_forum_post_type_rewrite', array(
94 'slug' => bbp_get_forum_slug(),
95 'with_front' => false
96 ) );
97 }
98
99 /**
100 * Return array of features the forum post type supports
101 *
102 * @since 2.5.0 bbPress (r5129)
103 *
104 * @return array
105 */
106 function bbp_get_forum_post_type_supports() {
107
108 // Filter & return
109 return (array) apply_filters( 'bbp_get_forum_post_type_supports', array(
110 'title',
111 'editor',
112 'revisions',
113 'thumbnail'
114 ) );
115 }
116
117 /** Forum Loop ****************************************************************/
118
119 /**
120 * The main forum loop.
121 *
122 * WordPress makes this easy for us.
123 *
124 * @since 2.0.0 bbPress (r2464)
125 *
126 * @param array $args All the arguments supported by {@link WP_Query}
127 *
128 * @return object Multidimensional array of forum information
129 */
130 function bbp_has_forums( $args = array() ) {
131
132 // Forum archive only shows root
133 if ( bbp_is_forum_archive() ) {
134 $default_post_parent = 0;
135
136 // User subscriptions shows any
137 } elseif ( bbp_is_subscriptions() ) {
138 $default_post_parent = 'any';
139
140 // Could be anything, so look for possible parent ID
141 } else {
142 $default_post_parent = bbp_get_forum_id();
143 }
144
145 $default_forum_search = bbp_sanitize_search_request( 'fs' );
146
147 // Default argument array
148 $default = array(
149 'post_type' => bbp_get_forum_post_type(),
150 'post_parent' => $default_post_parent,
151 'post_status' => bbp_get_public_status_id(),
152 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
153 'orderby' => 'menu_order title',
154 'order' => 'ASC',
155 'no_found_rows' => true,
156 'ignore_sticky_posts' => true,
157
158 // Conditionally prime the cache for last active posts
159 'update_post_family_cache' => true
160 );
161
162 // Only add 's' arg if searching for forums
163 // See https://bbpress.trac.wordpress.org/ticket/2607
164 if ( ! empty( $default_forum_search ) ) {
165 $default['s'] = $default_forum_search;
166 }
167
168 // Parse arguments with default forum query for most circumstances
169 $r = bbp_parse_args( $args, $default, 'has_forums' );
170
171 // Run the query
172 $bbp = bbpress();
173 $bbp->forum_query = new WP_Query( $r );
174
175 // Maybe prime last active posts
176 if ( ! empty( $r['update_post_family_cache'] ) ) {
177 bbp_update_post_family_caches( $bbp->forum_query->posts );
178 }
179
180 // Filter & return
181 return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
182 }
183
184 /**
185 * Whether there are more forums available in the loop
186 *
187 * @since 2.0.0 bbPress (r2464)
188 *
189 * @return object Forum information
190 */
191 function bbp_forums() {
192
193 // Put into variable to check against next
194 $have_posts = bbpress()->forum_query->have_posts();
195
196 // Reset the post data when finished
197 if ( empty( $have_posts ) ) {
198 wp_reset_postdata();
199 }
200
201 return $have_posts;
202 }
203
204 /**
205 * Loads up the current forum in the loop
206 *
207 * @since 2.0.0 bbPress (r2464)
208 *
209 * @return object Forum information
210 */
211 function bbp_the_forum() {
212 return bbpress()->forum_query->the_post();
213 }
214
215 /** Forum *********************************************************************/
216
217 /**
218 * Output forum id
219 *
220 * @since 2.0.0 bbPress (r2464)
221 *
222 * @param $forum_id Optional. Used to check emptiness
223 */
224 function bbp_forum_id( $forum_id = 0 ) {
225 echo bbp_get_forum_id( $forum_id );
226 }
227 /**
228 * Return the forum id
229 *
230 * @since 2.0.0 bbPress (r2464)
231 *
232 * @param $forum_id Optional. Used to check emptiness
233 * @return int The forum id
234 */
235 function bbp_get_forum_id( $forum_id = 0 ) {
236 $bbp = bbpress();
237 $wp_query = bbp_get_wp_query();
238
239 // Easy empty checking
240 if ( ! empty( $forum_id ) && is_numeric( $forum_id ) ) {
241 $bbp_forum_id = $forum_id;
242
243 // Currently inside a forum loop
244 } elseif ( ! empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
245 $bbp_forum_id = $bbp->forum_query->post->ID;
246
247 // Currently inside a search loop
248 } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
249 $bbp_forum_id = $bbp->search_query->post->ID;
250
251 // Currently viewing a forum
252 } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && ! empty( $bbp->current_forum_id ) ) {
253 $bbp_forum_id = $bbp->current_forum_id;
254
255 // Currently viewing a forum
256 } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && isset( $wp_query->post->ID ) ) {
257 $bbp_forum_id = $wp_query->post->ID;
258
259 // Currently viewing a topic
260 } elseif ( bbp_is_single_topic() ) {
261 $bbp_forum_id = bbp_get_topic_forum_id();
262
263 // Fallback
264 } else {
265 $bbp_forum_id = 0;
266 }
267
268 // Filter & return
269 return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
270 }
271
272 /**
273 * Gets a forum
274 *
275 * @since 2.0.0 bbPress (r2787)
276 *
277 * @param int|object $forum forum id or forum object
278 * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
279 * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
280 *
281 * @return mixed Null if error or forum (in specified form) if success
282 */
283 function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) {
284
285 // Maybe get ID from empty or int
286 if ( empty( $forum ) || is_numeric( $forum ) ) {
287 $forum = bbp_get_forum_id( $forum );
288 }
289
290 // Bail if no post object
291 $forum = get_post( $forum, OBJECT, $filter );
292 if ( empty( $forum ) ) {
293 return $forum;
294 }
295
296 // Bail if not correct post type
297 if ( $forum->post_type !== bbp_get_forum_post_type() ) {
298 return null;
299 }
300
301 // Default return value is OBJECT
302 $retval = $forum;
303
304 // Array A
305 if ( $output === ARRAY_A ) {
306 $retval = get_object_vars( $forum );
307
308 // Array N
309 } elseif ( $output === ARRAY_N ) {
310 $retval = array_values( get_object_vars( $forum ) );
311 }
312
313 // Filter & return
314 return apply_filters( 'bbp_get_forum', $retval, $forum, $output, $filter );
315 }
316
317 /**
318 * Output the link to the forum
319 *
320 * @since 2.0.0 bbPress (r2464)
321 *
322 * @param int $forum_id Optional. Forum id
323 * @param string $redirect_to Optional. Pass a redirect value for use with
324 * shortcodes and other fun things.
325 */
326 function bbp_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
327 echo esc_url( bbp_get_forum_permalink( $forum_id, $redirect_to ) );
328 }
329 /**
330 * Return the link to the forum
331 *
332 * @since 2.0.0 bbPress (r2464)
333 *
334 * @param int $forum_id Optional. Forum id
335 * @param string $redirect_to Optional. Pass a redirect value for use with
336 * shortcodes and other fun things.
337 *
338 * @return string Permanent link to forum
339 */
340 function bbp_get_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
341 $forum_id = bbp_get_forum_id( $forum_id );
342
343 // Use the redirect address
344 if ( ! empty( $redirect_to ) ) {
345 $forum_permalink = esc_url_raw( $redirect_to );
346
347 // Use the topic permalink
348 } else {
349 $forum_permalink = get_permalink( $forum_id );
350 }
351
352 // Filter & return
353 return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id );
354 }
355
356 /**
357 * Output the title of the forum
358 *
359 * @since 2.0.0 bbPress (r2464)
360 *
361 * @param int $forum_id Optional. Forum id
362 */
363 function bbp_forum_title( $forum_id = 0 ) {
364 echo bbp_get_forum_title( $forum_id );
365 }
366 /**
367 * Return the title of the forum
368 *
369 * @since 2.0.0 bbPress (r2464)
370 *
371 * @param int $forum_id Optional. Forum id
372 * @return string Title of forum
373 */
374 function bbp_get_forum_title( $forum_id = 0 ) {
375 $forum_id = bbp_get_forum_id( $forum_id );
376 $title = get_the_title( $forum_id );
377
378 // Filter & return
379 return apply_filters( 'bbp_get_forum_title', $title, $forum_id );
380 }
381
382 /**
383 * Output the forum archive title
384 *
385 * @since 2.0.0 bbPress (r3249)
386 *
387 * @param string $title Default text to use as title
388 */
389 function bbp_forum_archive_title( $title = '' ) {
390 echo bbp_get_forum_archive_title( $title );
391 }
392 /**
393 * Return the forum archive title
394 *
395 * @since 2.0.0 bbPress (r3249)
396 *
397 * @param string $title Default text to use as title
398 *
399 * @return string The forum archive title
400 */
401 function bbp_get_forum_archive_title( $title = '' ) {
402
403 // If no title was passed
404 if ( empty( $title ) ) {
405
406 // Set root text to page title
407 $page = bbp_get_page_by_path( bbp_get_root_slug() );
408 if ( ! empty( $page ) ) {
409 $title = get_the_title( $page->ID );
410
411 // Default to forum post type name label
412 } else {
413 $fto = get_post_type_object( bbp_get_forum_post_type() );
414 $title = $fto->labels->name;
415 }
416 }
417
418 // Filter & return
419 return apply_filters( 'bbp_get_forum_archive_title', $title );
420 }
421
422 /**
423 * Output the content of the forum
424 *
425 * @since 2.0.0 bbPress (r2780)
426 *
427 * @param int $forum_id Optional. Topic id
428 */
429 function bbp_forum_content( $forum_id = 0 ) {
430 echo bbp_get_forum_content( $forum_id );
431 }
432 /**
433 * Return the content of the forum
434 *
435 * @since 2.0.0 bbPress (r2780)
436 *
437 * @param int $forum_id Optional. Topic id
438 *
439 * @return string Content of the forum
440 */
441 function bbp_get_forum_content( $forum_id = 0 ) {
442 $forum_id = bbp_get_forum_id( $forum_id );
443
444 // Check if password is required
445 if ( post_password_required( $forum_id ) ) {
446 return get_the_password_form();
447 }
448
449 $content = get_post_field( 'post_content', $forum_id );
450
451 // Filter & return
452 return apply_filters( 'bbp_get_forum_content', $content, $forum_id );
453 }
454
455 /**
456 * Allow forum rows to have administrative actions
457 *
458 * @since 2.1.0 bbPress (r3653)
459 *
460 * @todo Links and filter
461 */
462 function bbp_forum_row_actions() {
463 do_action( 'bbp_forum_row_actions' );
464 }
465
466 /**
467 * Output the forums last active ID
468 *
469 * @since 2.0.0 bbPress (r2860)
470 *
471 * @param int $forum_id Optional. Forum id
472 */
473 function bbp_forum_last_active_id( $forum_id = 0 ) {
474 echo bbp_get_forum_last_active_id( $forum_id );
475 }
476 /**
477 * Return the forums last active ID
478 *
479 * @since 2.0.0 bbPress (r2860)
480 *
481 * @param int $forum_id Optional. Forum id
482 * the last active id and forum id
483 * @return int Forum's last active id
484 */
485 function bbp_get_forum_last_active_id( $forum_id = 0 ) {
486 $forum_id = bbp_get_forum_id( $forum_id );
487 $active_id = (int) get_post_meta( $forum_id, '_bbp_last_active_id', true );
488
489 // Filter & return
490 return (int) apply_filters( 'bbp_get_forum_last_active_id', $active_id, $forum_id );
491 }
492
493 /**
494 * Output the forums last update date/time (aka freshness)
495 *
496 * @since 2.0.0 bbPress (r2464)
497 *
498 * @param int $forum_id Optional. Forum id
499 */
500 function bbp_forum_last_active_time( $forum_id = 0 ) {
501 echo bbp_get_forum_last_active_time( $forum_id );
502 }
503 /**
504 * Return the forums last update date/time (aka freshness)
505 *
506 * @since 2.0.0 bbPress (r2464)
507 *
508 * @param int $forum_id Optional. Forum id
509 * @return string Forum last update date/time (freshness)
510 */
511 function bbp_get_forum_last_active_time( $forum_id = 0 ) {
512
513 // Verify forum and get last active meta
514 $forum_id = bbp_get_forum_id( $forum_id );
515 $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
516
517 if ( empty( $last_active ) ) {
518 $reply_id = bbp_get_forum_last_reply_id( $forum_id );
519 if ( ! empty( $reply_id ) ) {
520 $last_active = get_post_field( 'post_date', $reply_id );
521 } else {
522 $topic_id = bbp_get_forum_last_topic_id( $forum_id );
523 if ( ! empty( $topic_id ) ) {
524 $last_active = bbp_get_topic_last_active_time( $topic_id );
525 }
526 }
527 }
528
529 $active_time = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
530
531 // Filter & return
532 return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id );
533 }
534
535 /**
536 * Output link to the most recent activity inside a forum.
537 *
538 * Outputs a complete link with attributes and content.
539 *
540 * @since 2.0.0 bbPress (r2625)
541 *
542 * @param int $forum_id Optional. Forum id
543 */
544 function bbp_forum_freshness_link( $forum_id = 0) {
545 echo bbp_get_forum_freshness_link( $forum_id );
546 }
547 /**
548 * Returns link to the most recent activity inside a forum.
549 *
550 * Returns a complete link with attributes and content.
551 *
552 * @since 2.0.0 bbPress (r2625)
553 *
554 * @param int $forum_id Optional. Forum id
555 */
556 function bbp_get_forum_freshness_link( $forum_id = 0 ) {
557 $forum_id = bbp_get_forum_id( $forum_id );
558 $active_id = bbp_get_forum_last_active_id( $forum_id );
559 $link_url = $title = '';
560
561 if ( empty( $active_id ) ) {
562 $active_id = bbp_get_forum_last_reply_id( $forum_id );
563 }
564
565 if ( empty( $active_id ) ) {
566 $active_id = bbp_get_forum_last_topic_id( $forum_id );
567 }
568
569 if ( bbp_is_topic( $active_id ) ) {
570 $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
571 $title = bbp_get_forum_last_topic_title( $forum_id );
572 } elseif ( bbp_is_reply( $active_id ) ) {
573 $link_url = bbp_get_forum_last_reply_url( $forum_id );
574 $title = bbp_get_forum_last_reply_title( $forum_id );
575 }
576
577 $time_since = bbp_get_forum_last_active_time( $forum_id );
578
579 if ( ! empty( $time_since ) && ! empty( $link_url ) ) {
580 $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
581 } else {
582 $anchor = esc_html__( 'No Topics', 'bbpress' );
583 }
584
585 // Filter & return
586 return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id );
587 }
588
589 /**
590 * Output parent ID of a forum, if exists
591 *
592 * @since 2.1.0 bbPress (r3675)
593 *
594 * @param int $forum_id Forum ID
595 */
596 function bbp_forum_parent_id( $forum_id = 0 ) {
597 echo bbp_get_forum_parent_id( $forum_id );
598 }
599 /**
600 * Return ID of forum parent, if exists
601 *
602 * @since 2.1.0 bbPress (r3675)
603 *
604 * @param int $forum_id Optional. Forum id
605 * @return int Forum parent
606 */
607 function bbp_get_forum_parent_id( $forum_id = 0 ) {
608 $forum_id = bbp_get_forum_id( $forum_id );
609 $parent_id = (int) get_post_field( 'post_parent', $forum_id );
610
611 // Meta-data fallback
612 if ( empty( $parent_id ) ) {
613 $parent_id = (int) get_post_meta( $forum_id, '_bbp_forum_id', true );
614 }
615
616 // Filter
617 if ( ! empty( $parent_id ) ) {
618 $parent_id = (int) bbp_get_forum_id( $parent_id );
619 }
620
621 // Filter & return
622 return (int) apply_filters( 'bbp_get_forum_parent_id', $parent_id, $forum_id );
623 }
624
625 /**
626 * Return array of parent forums
627 *
628 * @since 2.0.0 bbPress (r2625)
629 *
630 * @param int $forum_id Optional. Forum id
631 * @return array Forum ancestors
632 */
633 function bbp_get_forum_ancestors( $forum_id = 0 ) {
634 $forum_id = bbp_get_forum_id( $forum_id );
635 $ancestors = array();
636 $forum = bbp_get_forum( $forum_id );
637
638 if ( ! empty( $forum ) ) {
639 while ( 0 !== (int) $forum->post_parent ) {
640 $ancestors[] = $forum->post_parent;
641 $forum = bbp_get_forum( $forum->post_parent );
642 }
643 }
644
645 // Filter & return
646 return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id );
647 }
648
649 /**
650 * Return subforums of given forum
651 *
652 * @since 2.0.0 bbPress (r2747)
653 *
654 * @param array $args All the arguments supported by {@link WP_Query}
655 * @return mixed false if none, array of subs if yes
656 */
657 function bbp_forum_get_subforums( $args = array() ) {
658
659 // Default return value
660 $retval = array();
661
662 // Use passed integer as post_parent
663 if ( is_numeric( $args ) && ! empty( $args ) ) {
664 $args = array( 'post_parent' => bbp_get_forum_id( $args ) );
665 }
666
667 // Parse arguments against default values
668 $r = bbp_parse_args( $args, array(
669 'post_parent' => 0,
670 'post_type' => bbp_get_forum_post_type(),
671 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
672 'orderby' => 'menu_order title',
673 'order' => 'ASC',
674 'ignore_sticky_posts' => true,
675 'no_found_rows' => true
676 ), 'forum_get_subforums' );
677
678 // Ensure post_parent is properly set
679 $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
680
681 // Query if post_parent has subforums
682 if ( ! empty( $r['post_parent'] ) && bbp_get_forum_subforum_count( $r['post_parent'], true ) ) {
683 $get_posts = new WP_Query();
684 $retval = $get_posts->query( $r );
685 }
686
687 // Filter & return
688 return (array) apply_filters( 'bbp_forum_get_subforums', $retval, $r, $args );
689 }
690
691 /**
692 * Output a list of forums (can be used to list subforums)
693 *
694 * @since 2.0.0 bbPress (r2708)
695 *
696 * @param array $args The function supports these args:
697 * - before: To put before the output. Defaults to '<ul class="bbp-forums-list">'
698 * - after: To put after the output. Defaults to '</ul>'
699 * - link_before: To put before every link. Defaults to '<li class="bbp-forum">'
700 * - link_after: To put after every link. Defaults to '</li>'
701 * - sep: Separator. Defaults to ''. Make sure your markup is valid!
702 * - count_before: String before each count Defaults to ' ('
703 * - count_after: String before each count Defaults to ')'
704 * - count_sep: Count separator. Defaults to ', '
705 * - forum_id: Forum id. Defaults to ''
706 * - show_topic_count - To show forum topic count or not. Defaults to true
707 * - show_reply_count - To show forum reply count or not. Defaults to true
708 */
709 function bbp_list_forums( $args = array() ) {
710
711 // Parse arguments against default values
712 $r = bbp_parse_args( $args, array(
713 'before' => '<ul class="bbp-forums-list">',
714 'after' => '</ul>',
715 'link_before' => '<li class="bbp-forum css-sep">',
716 'link_after' => '</li>',
717 'sep' => '',
718 'count_before' => ' (',
719 'count_after' => ')',
720 'count_sep' => ', ',
721 'forum_id' => bbp_get_forum_id(),
722 'show_topic_count' => true,
723 'show_reply_count' => true,
724 'echo' => true,
725
726 // Retired, use 'sep' instead
727 'separator' => false
728 ), 'list_forums' );
729
730 /**
731 * Necessary for backwards compatibility
732 * @see https://bbpress.trac.wordpress.org/ticket/2900
733 */
734 if ( ! empty( $r['separator'] ) ) {
735 $r['sep'] = $r['separator'];
736 }
737
738 // Default values
739 $links = array();
740 $output = '';
741
742 // Query for subforums
743 $sub_forums = ! empty( $r['forum_id'] )
744 ? bbp_forum_get_subforums( $r['forum_id'] )
745 : array();
746
747 // Loop through forums and create a list
748 if ( ! empty( $sub_forums ) ) {
749 foreach ( $sub_forums as $sub_forum ) {
750
751 // Get forum details
752 $count = array();
753 $permalink = bbp_get_forum_permalink( $sub_forum->ID );
754 $title = bbp_get_forum_title( $sub_forum->ID );
755
756 // Show topic count
757 if ( ! empty( $r['show_topic_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
758 $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
759 }
760
761 // Show reply count
762 if ( ! empty( $r['show_reply_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
763 $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
764 }
765
766 // Counts to show
767 $counts = ! empty( $count )
768 ? $r['count_before'] . implode( $r['count_sep'], $count ) . $r['count_after']
769 : '';
770
771 // Subforum classes
772 $subforum_classes = array( 'bbp-forum-link' );
773 $subforum_classes = apply_filters( 'bbp_list_forums_subforum_classes', $subforum_classes, $sub_forum->ID );
774
775 // This could use bbp_get_forum_class() eventually...
776 $subforum_classes_attr = 'class="' . implode( ' ', array_map( 'sanitize_html_class', $subforum_classes ) ) . '"';
777
778 // Build this sub forums link
779 $links[] = $r['link_before'] . '<a href="' . esc_url( $permalink ) . '" ' . $subforum_classes_attr . '>' . $title . $counts . '</a>' . $r['link_after'];
780 }
781
782 // Maybe wrap output
783 $output = ! empty( $links )
784 ? $r['before'] . implode( $r['sep'], $links ) . $r['after']
785 : '';
786 }
787
788 // Filter output
789 $the_list = apply_filters( 'bbp_list_forums', $output, $r, $args );
790
791 // Echo or return the forums list
792 if ( ! empty( $r['echo'] ) ) {
793 echo $the_list;
794 } else {
795 return $the_list;
796 }
797 }
798
799 /** Forum Subscriptions *******************************************************/
800
801 /**
802 * Output the forum subscription link
803 *
804 * @since 2.5.0 bbPress (r5156)
805 * @since 2.6.0 bbPress (r6308) Add 'redirect_to' support
806 */
807 function bbp_forum_subscription_link( $args = array() ) {
808 echo bbp_get_forum_subscription_link( $args );
809 }
810
811 /**
812 * Get the forum subscription link
813 *
814 * A custom wrapper for bbp_get_user_subscribe_link()
815 *
816 * @since 2.5.0 bbPress (r5156)
817 * @since 2.6.0 bbPress (r6308) Add 'redirect_to' support
818 */
819 function bbp_get_forum_subscription_link( $args = array() ) {
820
821 // Defaults
822 $retval = false;
823 $redirect_to = bbp_is_subscriptions()
824 ? bbp_get_subscriptions_permalink()
825 : '';
826
827 // Parse the arguments
828 $r = bbp_parse_args( $args, array(
829 'user_id' => bbp_get_current_user_id(),
830 'object_id' => bbp_get_forum_id(),
831 'object_type' => 'post',
832 'before' => '',
833 'after' => '',
834 'subscribe' => esc_html__( 'Subscribe', 'bbpress' ),
835 'unsubscribe' => esc_html__( 'Unsubscribe', 'bbpress' ),
836 'redirect_to' => $redirect_to
837 ), 'get_forum_subscribe_link' );
838
839 // No link for categories until we support subscription hierarchy
840 // @see https://bbpress.trac.wordpress.org/ticket/2475
841 if ( ! bbp_is_forum_category() ) {
842 $retval = bbp_get_user_subscribe_link( $r );
843 }
844
845 // Filter & return
846 return apply_filters( 'bbp_get_forum_subscribe_link', $retval, $r, $args );
847 }
848
849 /** Forum Last Topic **********************************************************/
850
851 /**
852 * Output the forum's last topic id
853 *
854 * @since 2.0.0 bbPress (r2464)
855 *
856 * @param int $forum_id Optional. Forum id
857 */
858 function bbp_forum_last_topic_id( $forum_id = 0 ) {
859 echo bbp_get_forum_last_topic_id( $forum_id );
860 }
861 /**
862 * Return the forum's last topic id
863 *
864 * @since 2.0.0 bbPress (r2464)
865 *
866 * @param int $forum_id Optional. Forum id
867 * @return int Forum's last topic id
868 */
869 function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
870 $forum_id = bbp_get_forum_id( $forum_id );
871 $topic_id = (int) get_post_meta( $forum_id, '_bbp_last_topic_id', true );
872
873 // Filter & return
874 return (int) apply_filters( 'bbp_get_forum_last_topic_id', $topic_id, $forum_id );
875 }
876
877 /**
878 * Output the title of the last topic inside a forum
879 *
880 * @since 2.0.0 bbPress (r2625)
881 *
882 * @param int $forum_id Optional. Forum id
883 */
884 function bbp_forum_last_topic_title( $forum_id = 0 ) {
885 echo bbp_get_forum_last_topic_title( $forum_id );
886 }
887 /**
888 * Return the title of the last topic inside a forum
889 *
890 * @since 2.0.0 bbPress (r2625)
891 *
892 * @param int $forum_id Optional. Forum id
893 * @return string Forum's last topic's title
894 */
895 function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
896 $forum_id = bbp_get_forum_id( $forum_id );
897 $topic_id = bbp_get_forum_last_topic_id( $forum_id );
898 $title = ! empty( $topic_id ) ? bbp_get_topic_title( $topic_id ) : '';
899
900 // Filter & return
901 return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id );
902 }
903
904 /**
905 * Output the link to the last topic in a forum
906 *
907 * @since 2.0.0 bbPress (r2464)
908 *
909 * @param int $forum_id Optional. Forum id
910 */
911 function bbp_forum_last_topic_permalink( $forum_id = 0 ) {
912 echo esc_url( bbp_get_forum_last_topic_permalink( $forum_id ) );
913 }
914 /**
915 * Return the link to the last topic in a forum
916 *
917 * @since 2.0.0 bbPress (r2464)
918 *
919 * @param int $forum_id Optional. Forum id
920 * @return string Permanent link to topic
921 */
922 function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
923 $forum_id = bbp_get_forum_id( $forum_id );
924 $topic_id = bbp_get_forum_last_topic_id( $forum_id );
925 $link = bbp_get_topic_permalink( $topic_id );
926
927 // Filter & return
928 return apply_filters( 'bbp_get_forum_last_topic_permalink', $link, $forum_id, $topic_id );
929 }
930
931 /**
932 * Return the author ID of the last topic of a forum
933 *
934 * @since 2.0.0 bbPress (r2625)
935 *
936 * @param int $forum_id Optional. Forum id
937 * @return int Forum's last topic's author id
938 */
939 function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
940 $forum_id = bbp_get_forum_id( $forum_id );
941 $topic_id = bbp_get_forum_last_topic_id( $forum_id );
942 $author_id = bbp_get_topic_author_id( $topic_id );
943
944 // Filter & return
945 return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id, $topic_id );
946 }
947
948 /**
949 * Output link to author of last topic of forum
950 *
951 * @since 2.0.0 bbPress (r2625)
952 *
953 * @param int $forum_id Optional. Forum id
954 */
955 function bbp_forum_last_topic_author_link( $forum_id = 0 ) {
956 echo bbp_get_forum_last_topic_author_link( $forum_id );
957 }
958 /**
959 * Return link to author of last topic of forum
960 *
961 * @since 2.0.0 bbPress (r2625)
962 *
963 * @param int $forum_id Optional. Forum id
964 * @return string Forum's last topic's author link
965 */
966 function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
967 $forum_id = bbp_get_forum_id( $forum_id );
968 $author_id = bbp_get_forum_last_topic_author_id( $forum_id );
969 $author_link = bbp_get_user_profile_link( $author_id );
970
971 // Filter & return
972 return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
973 }
974
975 /** Forum Last Reply **********************************************************/
976
977 /**
978 * Output the forums last reply id
979 *
980 * @since 2.0.0 bbPress (r2464)
981 *
982 * @param int $forum_id Optional. Forum id
983 */
984 function bbp_forum_last_reply_id( $forum_id = 0 ) {
985 echo bbp_get_forum_last_reply_id( $forum_id );
986 }
987 /**
988 * Return the forums last reply id
989 *
990 * @since 2.0.0 bbPress (r2464)
991 *
992 * @param int $forum_id Optional. Forum id
993 * @return int Forum's last reply id
994 */
995 function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
996 $forum_id = bbp_get_forum_id( $forum_id );
997 $reply_id = (int) get_post_meta( $forum_id, '_bbp_last_reply_id', true );
998
999 // Filter & return
1000 return (int) apply_filters( 'bbp_get_forum_last_reply_id', $reply_id, $forum_id );
1001 }
1002
1003 /**
1004 * Output the title of the last reply inside a forum
1005 *
1006 * @param int $forum_id Optional. Forum id
1007 */
1008 function bbp_forum_last_reply_title( $forum_id = 0 ) {
1009 echo bbp_get_forum_last_reply_title( $forum_id );
1010 }
1011 /**
1012 * Return the title of the last reply inside a forum
1013 *
1014 * @param int $forum_id Optional. Forum id
1015 * @return string
1016 */
1017 function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
1018 $forum_id = bbp_get_forum_id( $forum_id );
1019 $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1020 $title = bbp_get_reply_title( $reply_id );
1021
1022 // Filter & return
1023 return apply_filters( 'bbp_get_forum_last_reply_title', $title, $forum_id, $reply_id );
1024 }
1025
1026 /**
1027 * Output the link to the last reply in a forum
1028 *
1029 * @since 2.0.0 bbPress (r2464)
1030 *
1031 * @param int $forum_id Optional. Forum id
1032 */
1033 function bbp_forum_last_reply_permalink( $forum_id = 0 ) {
1034 echo esc_url( bbp_get_forum_last_reply_permalink( $forum_id ) );
1035 }
1036 /**
1037 * Return the link to the last reply in a forum
1038 *
1039 * @since 2.0.0 bbPress (r2464)
1040 *
1041 * @param int $forum_id Optional. Forum id
1042 *
1043 * @return string Permanent link to the forum's last reply
1044 */
1045 function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
1046 $forum_id = bbp_get_forum_id( $forum_id );
1047 $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1048 $link = bbp_get_reply_permalink( $reply_id );
1049
1050 // Filter & return
1051 return apply_filters( 'bbp_get_forum_last_reply_permalink', $link, $forum_id, $reply_id );
1052 }
1053
1054 /**
1055 * Output the url to the last reply in a forum
1056 *
1057 * @since 2.0.0 bbPress (r2683)
1058 *
1059 * @param int $forum_id Optional. Forum id
1060 */
1061 function bbp_forum_last_reply_url( $forum_id = 0 ) {
1062 echo esc_url( bbp_get_forum_last_reply_url( $forum_id ) );
1063 }
1064 /**
1065 * Return the url to the last reply in a forum
1066 *
1067 * @since 2.0.0 bbPress (r2683)
1068 *
1069 * @param int $forum_id Optional. Forum id
1070 * @return string Paginated URL to latest reply
1071 */
1072 function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
1073 $forum_id = bbp_get_forum_id( $forum_id );
1074
1075 // If forum has replies, get the last reply and use its url
1076 $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1077 if ( ! empty( $reply_id ) ) {
1078 $reply_url = bbp_get_reply_url( $reply_id );
1079
1080 // No replies, so look for topics and use last permalink
1081 } else {
1082 $reply_url = bbp_get_forum_last_topic_permalink( $forum_id );
1083
1084 // No topics either, so set $reply_url as empty string
1085 if ( empty( $reply_url ) ) {
1086 $reply_url = '';
1087 }
1088 }
1089
1090 // Filter & return
1091 return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id, $reply_id );
1092 }
1093
1094 /**
1095 * Output author ID of last reply of forum
1096 *
1097 * @since 2.0.0 bbPress (r2625)
1098 *
1099 * @param int $forum_id Optional. Forum id
1100 */
1101 function bbp_forum_last_reply_author_id( $forum_id = 0 ) {
1102 echo bbp_get_forum_last_reply_author_id( $forum_id );
1103 }
1104 /**
1105 * Return author ID of last reply of forum
1106 *
1107 * @since 2.0.0 bbPress (r2625)
1108 *
1109 * @param int $forum_id Optional. Forum id
1110 * @return int Forum's last reply author id
1111 */
1112 function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
1113 $forum_id = bbp_get_forum_id( $forum_id );
1114 $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1115 $author_id = bbp_get_reply_author_id( $reply_id );
1116
1117 // Filter & return
1118 return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id, $reply_id );
1119 }
1120
1121 /**
1122 * Output link to author of last reply of forum
1123 *
1124 * @since 2.0.0 bbPress (r2625)
1125 *
1126 * @param int $forum_id Optional. Forum id
1127 */
1128 function bbp_forum_last_reply_author_link( $forum_id = 0 ) {
1129 echo bbp_get_forum_last_reply_author_link( $forum_id );
1130 }
1131 /**
1132 * Return link to author of last reply of forum
1133 *
1134 * @since 2.0.0 bbPress (r2625)
1135 *
1136 * @param int $forum_id Optional. Forum id
1137 * @return string Link to author of last reply of forum
1138 */
1139 function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
1140 $forum_id = bbp_get_forum_id( $forum_id );
1141 $author_id = bbp_get_forum_last_reply_author_id( $forum_id );
1142 $author_link = bbp_get_user_profile_link( $author_id );
1143
1144 // Filter & return
1145 return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id, $author_id );
1146 }
1147
1148 /** Forum Counts **************************************************************/
1149
1150 /**
1151 * Output the topics link of the forum
1152 *
1153 * @since 2.0.0 bbPress (r2883)
1154 *
1155 * @param int $forum_id Optional. Topic id
1156 */
1157 function bbp_forum_topics_link( $forum_id = 0 ) {
1158 echo bbp_get_forum_topics_link( $forum_id );
1159 }
1160
1161 /**
1162 * Return the topics link of the forum
1163 *
1164 * @since 2.0.0 bbPress (r2883)
1165 *
1166 * @param int $forum_id Optional. Topic id
1167 */
1168 function bbp_get_forum_topics_link( $forum_id = 0 ) {
1169 $forum_id = bbp_get_forum_id( $forum_id );
1170 $link = bbp_get_forum_permalink( $forum_id );
1171 $topics = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, true ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id, true, false ) );
1172
1173 // First link never has view=all
1174 $retval = bbp_get_view_all( 'edit_others_topics' )
1175 ? "<a href='" . esc_url( bbp_remove_view_all( $link ) ) . "'>" . esc_html( $topics ) . "</a>"
1176 : esc_html( $topics );
1177
1178 // Get deleted topics
1179 $deleted_int = bbp_get_forum_topic_count_hidden( $forum_id, false, true );
1180
1181 // This forum has hidden topics
1182 if ( ! empty( $deleted_int ) && current_user_can( 'edit_others_topics' ) ) {
1183
1184 // Hidden text
1185 $deleted_num = bbp_get_forum_topic_count_hidden( $forum_id, false, false );
1186 $extra = ' ' . sprintf( _n( '(+%s hidden)', '(+%s hidden)', $deleted_int, 'bbpress' ), $deleted_num );
1187
1188 // Hidden link
1189 $retval .= ! bbp_get_view_all( 'edit_others_topics' )
1190 ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>"
1191 : " {$extra}";
1192 }
1193
1194 // Filter & return
1195 return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
1196 }
1197
1198 /**
1199 * Output total sub-forum count of a forum
1200 *
1201 * @since 2.0.0 bbPress (r2464)
1202 *
1203 * @param int $forum_id Optional. Forum id to check
1204 * @param boolean $integer Optional. Whether or not to format the result
1205 */
1206 function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) {
1207 echo bbp_get_forum_subforum_count( $forum_id, $integer );
1208 }
1209 /**
1210 * Return total subforum count of a forum
1211 *
1212 * @since 2.0.0 bbPress (r2464)
1213 *
1214 * @param int $forum_id Optional. Forum id
1215 * @param boolean $integer Optional. Whether or not to format the result
1216 * @return int Forum's subforum count
1217 */
1218 function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) {
1219 $forum_id = bbp_get_forum_id( $forum_id );
1220 $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
1221 $filter = ( true === $integer )
1222 ? 'bbp_get_forum_subforum_count_int'
1223 : 'bbp_get_forum_subforum_count';
1224
1225 return apply_filters( $filter, $forum_count, $forum_id );
1226 }
1227
1228 /**
1229 * Output total topic count of a forum
1230 *
1231 * @since 2.0.0 bbPress (r2464)
1232 *
1233 * @param int $forum_id Optional. Forum id
1234 * @param bool $total_count Optional. To get the total count or normal count?
1235 * @param boolean $integer Optional. Whether or not to format the result
1236 */
1237 function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
1238 echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer );
1239 }
1240 /**
1241 * Return total topic count of a forum
1242 *
1243 * @since 2.0.0 bbPress (r2464)
1244 *
1245 * @param int $forum_id Optional. Forum id
1246 * @param bool $total_count Optional. To get the total count or normal
1247 * count? Defaults to total.
1248 * @param boolean $integer Optional. Whether or not to format the result
1249 * @return int Forum topic count
1250 */
1251 function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
1252 $forum_id = bbp_get_forum_id( $forum_id );
1253 $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count';
1254 $topics = (int) get_post_meta( $forum_id, $meta_key, true );
1255 $filter = ( true === $integer )
1256 ? 'bbp_get_forum_topic_count_int'
1257 : 'bbp_get_forum_topic_count';
1258
1259 return apply_filters( $filter, $topics, $forum_id );
1260 }
1261
1262 /**
1263 * Output total reply count of a forum
1264 *
1265 * @since 2.0.0 bbPress (r2464)
1266 *
1267 * @param int $forum_id Optional. Forum id
1268 * @param bool $total_count Optional. To get the total count or normal count?
1269 * @param boolean $integer Optional. Whether or not to format the result
1270 */
1271 function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
1272 echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer );
1273 }
1274 /**
1275 * Return total post count of a forum
1276 *
1277 * @since 2.0.0 bbPress (r2464)
1278 *
1279 * @param int $forum_id Optional. Forum id
1280 * @param bool $total_count Optional. To get the total count or normal
1281 * count?
1282 * @param boolean $integer Optional. Whether or not to format the result
1283 * @return int Forum reply count
1284 */
1285 function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
1286 $forum_id = bbp_get_forum_id( $forum_id );
1287 $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
1288 $replies = (int) get_post_meta( $forum_id, $meta_key, true );
1289 $filter = ( true === $integer )
1290 ? 'bbp_get_forum_reply_count_int'
1291 : 'bbp_get_forum_reply_count';
1292
1293 return apply_filters( $filter, $replies, $forum_id );
1294 }
1295
1296 /**
1297 * Output total post count of a forum
1298 *
1299 * @since 2.0.0 bbPress (r2954)
1300 *
1301 * @param int $forum_id Optional. Forum id
1302 * @param bool $total_count Optional. To get the total count or normal count?
1303 * @param boolean $integer Optional. Whether or not to format the result
1304 */
1305 function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
1306 echo bbp_get_forum_post_count( $forum_id, $total_count, $integer );
1307 }
1308 /**
1309 * Return total post count of a forum
1310 *
1311 * @since 2.0.0 bbPress (r2954)
1312 *
1313 * @param int $forum_id Optional. Forum id
1314 * @param bool $total_count Optional. To get the total count or normal
1315 * count?
1316 * @param boolean $integer Optional. Whether or not to format the result
1317 * @return int Forum post count
1318 */
1319 function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
1320 $forum_id = bbp_get_forum_id( $forum_id );
1321 $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true );
1322 $replies = bbp_get_forum_reply_count( $forum_id, $total_count, true );
1323 $retval = ( $replies + $topics );
1324 $filter = ( true === $integer )
1325 ? 'bbp_get_forum_post_count_int'
1326 : 'bbp_get_forum_post_count';
1327
1328 return apply_filters( $filter, $retval, $forum_id );
1329 }
1330
1331 /**
1332 * Output total hidden topic count of a forum (hidden includes trashed, spammed,
1333 * and pending topics)
1334 *
1335 * @since 2.0.0 bbPress (r2883)
1336 * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts
1337 *
1338 * @param int $forum_id Optional. Forum id
1339 * @param bool $total_count Optional. To get the total count or normal count?
1340 * @param boolean $integer Optional. Whether or not to format the result
1341 */
1342 function bbp_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) {
1343 echo bbp_get_forum_topic_count_hidden( $forum_id, $total_count, $integer );
1344 }
1345 /**
1346 * Return total hidden topic count of a forum (hidden includes trashed,
1347 * spammed and pending topics)
1348 *
1349 * @since 2.0.0 bbPress (r2883)
1350 * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts
1351 *
1352 * @param int $forum_id Optional. Forum id
1353 * @param bool $total_count Optional. To get the total count or normal count?
1354 * @param boolean $integer Optional. Whether or not to format the result
1355 * @return int Topic hidden topic count
1356 */
1357 function bbp_get_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) {
1358 $forum_id = bbp_get_forum_id( $forum_id );
1359 $meta_key = empty( $total_count ) ? '_bbp_topic_count_hidden' : '_bbp_total_topic_count_hidden';
1360 $topics = (int) get_post_meta( $forum_id, $meta_key, true );
1361 $filter = ( true === $integer )
1362 ? 'bbp_get_forum_topic_count_hidden_int'
1363 : 'bbp_get_forum_topic_count_hidden';
1364
1365 return apply_filters( $filter, $topics, $forum_id );
1366 }
1367
1368 /**
1369 * Output total hidden reply count of a forum (hidden includes trashed, spammed,
1370 * and pending replies)
1371 *
1372 * @since 2.6.0 bbPress (r6922)
1373 *
1374 * @param int $forum_id Optional. Forum id
1375 * @param bool $total_count Optional. To get the total count or normal count?
1376 * @param boolean $integer Optional. Whether or not to format the result
1377 */
1378 function bbp_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) {
1379 echo bbp_get_forum_reply_count_hidden( $forum_id, $total_count, $integer );
1380 }
1381 /**
1382 * Return total hidden reply count of a forum (hidden includes trashed,
1383 * spammed and pending replies)
1384 *
1385 * @since 2.6.0 bbPress (r6922)
1386 *
1387 * @param int $forum_id Optional. Forum id
1388 * @param bool $total_count Optional. To get the total count or normal
1389 * count?
1390 * @param boolean $integer Optional. Whether or not to format the result
1391 * @return int Forum reply count
1392 */
1393 function bbp_get_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) {
1394 $forum_id = bbp_get_forum_id( $forum_id );
1395 $meta_key = empty( $total_count ) ? '_bbp_reply_count_hidden' : '_bbp_total_reply_count_hidden';
1396 $replies = (int) get_post_meta( $forum_id, $meta_key, true );
1397 $filter = ( true === $integer )
1398 ? 'bbp_get_forum_reply_count_hidden_int'
1399 : 'bbp_get_forum_reply_count_hidden';
1400
1401 return apply_filters( $filter, $replies, $forum_id );
1402 }
1403
1404 /**
1405 * Output the status of the forum
1406 *
1407 * @since 2.0.0 bbPress (r2667)
1408 *
1409 * @param int $forum_id Optional. Forum id
1410 */
1411 function bbp_forum_status( $forum_id = 0 ) {
1412 echo bbp_get_forum_status( $forum_id );
1413 }
1414 /**
1415 * Return the status of the forum
1416 *
1417 * @since 2.0.0 bbPress (r2667)
1418 *
1419 * @param int $forum_id Optional. Forum id
1420 * @return string Status of forum
1421 */
1422 function bbp_get_forum_status( $forum_id = 0 ) {
1423 $forum_id = bbp_get_forum_id( $forum_id );
1424 $status = get_post_meta( $forum_id, '_bbp_status', true );
1425
1426 if ( empty( $status ) ) {
1427 $status = 'open';
1428 }
1429
1430 // Filter & return
1431 return apply_filters( 'bbp_get_forum_status', $status, $forum_id );
1432 }
1433
1434 /**
1435 * Output the visibility of the forum
1436 *
1437 * @since 2.0.0 bbPress (r2997)
1438 *
1439 * @param int $forum_id Optional. Forum id
1440 */
1441 function bbp_forum_visibility( $forum_id = 0 ) {
1442 echo bbp_get_forum_visibility( $forum_id );
1443 }
1444 /**
1445 * Return the visibility of the forum
1446 *
1447 * @since 2.0.0 bbPress (r2997)
1448 *
1449 * @param int $forum_id Optional. Forum id
1450 * @return string Status of forum
1451 */
1452 function bbp_get_forum_visibility( $forum_id = 0 ) {
1453 $forum_id = bbp_get_forum_id( $forum_id );
1454 $visibility = get_post_status( $forum_id );
1455
1456 // Filter & return
1457 return apply_filters( 'bbp_get_forum_visibility', $visibility, $forum_id );
1458 }
1459
1460 /**
1461 * Output the type of the forum
1462 *
1463 * @since 2.1.0 bbPress (r3563)
1464 *
1465 * @param int $forum_id Optional. Forum id
1466 */
1467 function bbp_forum_type( $forum_id = 0 ) {
1468 echo bbp_get_forum_type( $forum_id );
1469 }
1470 /**
1471 * Return the type of forum (category/forum/etc...)
1472 *
1473 * @since 2.1.0 bbPress (r3563)
1474 *
1475 * @param int $forum_id Optional. Forum id
1476 * @return bool Whether the forum is a category or not
1477 */
1478 function bbp_get_forum_type( $forum_id = 0 ) {
1479 $forum_id = bbp_get_forum_id( $forum_id );
1480 $retval = get_post_meta( $forum_id, '_bbp_forum_type', true );
1481
1482 if ( empty( $retval ) ) {
1483 $retval = 'forum';
1484 }
1485
1486 // Filter & return
1487 return apply_filters( 'bbp_get_forum_type', $retval, $forum_id );
1488 }
1489
1490 /**
1491 * Is the forum a category?
1492 *
1493 * @since 2.0.0 bbPress (r2746)
1494 *
1495 * @param int $forum_id Optional. Forum id
1496 * @return bool Whether the forum is a category or not
1497 */
1498 function bbp_is_forum_category( $forum_id = 0 ) {
1499 $forum_id = bbp_get_forum_id( $forum_id );
1500 $type = bbp_get_forum_type( $forum_id );
1501 $retval = ( ! empty( $type ) && 'category' === $type );
1502
1503 // Filter & return
1504 return (bool) apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id );
1505 }
1506
1507 /**
1508 * Is the forum open?
1509 *
1510 * @since 2.0.0 bbPress (r2746)
1511 *
1512 * @param int $forum_id Optional. Forum id
1513 * @param bool $check_ancestors Check if the ancestors are open (only
1514 * if they're a category)
1515 * @return bool Whether the forum is open or not
1516 */
1517 function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) {
1518 return ! bbp_is_forum_closed( $forum_id, $check_ancestors );
1519 }
1520
1521 /**
1522 * Is the forum closed?
1523 *
1524 * @since 2.0.0 bbPress (r2746)
1525 *
1526 * @param int $forum_id Optional. Forum id
1527 * @param bool $check_ancestors Check if the ancestors are closed (only
1528 * if they're a category)
1529 * @return bool True if closed, false if not
1530 */
1531 function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
1532
1533 // Get the forum ID
1534 $forum_id = bbp_get_forum_id( $forum_id );
1535
1536 // Check if the forum or one of it's ancestors is closed
1537 $retval = bbp_is_forum_status( $forum_id, bbp_get_closed_status_id(), $check_ancestors, 'OR' );
1538
1539 // Filter & return
1540 return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
1541 }
1542
1543 /**
1544 * Check if the forum status is a specific one, also maybe checking ancestors
1545 *
1546 * @since 2.6.0 bbPress (r5499)
1547 *
1548 * @param bool $status_name The forum status name to check
1549 * @param bool $check_ancestors Check the forum ancestors
1550 * @param string $operator The logical operation to perform.
1551 * 'OR' means only one forum from the tree needs to match;
1552 * 'AND' means all forums must match. The default is 'AND'.
1553 * @return bool True if match, false if not
1554 */
1555 function bbp_is_forum_status( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
1556
1557 // Setup some default variables
1558 $count = 0;
1559 $retval = false;
1560 $operator = strtoupper( $operator );
1561 $forum_id = bbp_get_forum_id( $forum_id );
1562 $forum_status = bbp_get_forum_status( $forum_id );
1563
1564 // Quickly compare statuses of first forum ID
1565 if ( $status_name === $forum_status ) {
1566 $retval = true;
1567 $count++;
1568 }
1569
1570 // Let's check the forum's ancestors too
1571 if ( ! empty( $check_ancestors ) ) {
1572
1573 // Adjust the ancestor check based on the count
1574 switch( $operator ) {
1575 default:
1576 case 'AND':
1577 $check_ancestors = ( $count > 0 );
1578 break;
1579
1580 case 'OR':
1581 $check_ancestors = ( $count < 1 );
1582 break;
1583 }
1584
1585 // Ancestor check passed, so continue looping through them
1586 if ( ! empty( $check_ancestors ) ) {
1587
1588 // Loop through the forum ancestors
1589 foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
1590
1591 // Check if the forum is a category
1592 if ( bbp_is_forum_category( $ancestor ) ) {
1593
1594 // Check the ancestor forum status
1595 $retval = bbp_is_forum_status( $ancestor, $status_name, false );
1596 if ( true === $retval ) {
1597 $count++;
1598 }
1599 }
1600
1601 // Break when it reach the max count
1602 if ( ( $operator === 'OR' ) && ( $count >= 1 ) ) {
1603 break;
1604 }
1605 }
1606 }
1607 }
1608
1609 // Filter & return
1610 return (bool) apply_filters( 'bbp_is_forum_status', $retval, $count, $forum_id, $status_name, $check_ancestors, $operator );
1611 }
1612
1613 /**
1614 * Is the forum public?
1615 *
1616 * @since 2.0.0 bbPress (r2997)
1617 *
1618 * @param int $forum_id Optional. Forum id
1619 * @param bool $check_ancestors Check if the ancestors are public
1620 * @return bool True if closed, false if not
1621 */
1622 function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
1623
1624 // Get the forum ID
1625 $forum_id = bbp_get_forum_id( $forum_id );
1626
1627 // Check if the forum and all of it's ancestors are public
1628 $retval = bbp_is_forum_visibility( $forum_id, bbp_get_public_status_id(), $check_ancestors );
1629
1630 // Filter & return
1631 return (bool) apply_filters( 'bbp_is_forum_public', $retval, $forum_id, $check_ancestors );
1632 }
1633
1634 /**
1635 * Is the forum private?
1636 *
1637 * @since 2.0.0 bbPress (r2746)
1638 *
1639 * @param int $forum_id Optional. Forum id
1640 * @param bool $check_ancestors Check if the ancestors are private
1641 * @return bool True if private, false if not
1642 */
1643 function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
1644
1645 // Get the forum ID
1646 $forum_id = bbp_get_forum_id( $forum_id );
1647
1648 // Check if the forum or one of it's ancestors is private
1649 $retval = bbp_is_forum_visibility( $forum_id, bbp_get_private_status_id(), $check_ancestors, 'OR' );
1650
1651 // Filter & return
1652 return (bool) apply_filters( 'bbp_is_forum_private', $retval, $forum_id, $check_ancestors );
1653 }
1654
1655 /**
1656 * Is the forum hidden?
1657 *
1658 * @since 2.0.0 bbPress (r2997)
1659 *
1660 * @param int $forum_id Optional. Forum id
1661 * @param bool $check_ancestors Check if the ancestors are private (only if
1662 * they're a category)
1663 * @return bool True if hidden, false if not
1664 */
1665 function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
1666
1667 // Get the forum ID
1668 $forum_id = bbp_get_forum_id( $forum_id );
1669
1670 // Check if the forum or one of it's ancestors is hidden
1671 $retval = bbp_is_forum_visibility( $forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR' );
1672
1673 // Filter & return
1674 return (bool) apply_filters( 'bbp_is_forum_hidden', $retval, $forum_id, $check_ancestors );
1675 }
1676
1677 /**
1678 * Check the forum visibility ID
1679 *
1680 * @since 2.6.0 bbPress (r5499)
1681 *
1682 * @param int $forum_id Optional. Forum id
1683 * @param bool $status_name The post status name to check
1684 * @param bool $check_ancestors Check the forum ancestors
1685 * @param string $operator The logical operation to perform.
1686 * 'OR' means only one forum from the tree needs to match;
1687 * 'AND' means all forums must match. The default is 'AND'.
1688 * @return bool True if match, false if not
1689 */
1690 function bbp_is_forum_visibility( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
1691
1692 // Setup some default variables
1693 $count = 0;
1694 $retval = false;
1695 $operator = strtoupper( $operator );
1696 $forum_id = bbp_get_forum_id( $forum_id );
1697 $visibility = bbp_get_forum_visibility( $forum_id );
1698
1699 // Quickly compare visibility of first forum ID
1700 if ( $status_name === $visibility ) {
1701 $retval = true;
1702 $count++;
1703 }
1704
1705 // Let's check the forum's ancestors too
1706 if ( ! empty( $check_ancestors ) ) {
1707
1708 // Adjust the ancestor check based on the count
1709 switch ( $operator ) {
1710
1711 // Adjust the ancestor check based on the count
1712 default:
1713 case 'AND':
1714 $check_ancestors = ( $count > 0 );
1715 break;
1716
1717 case 'OR':
1718 $check_ancestors = ( $count < 1 );
1719 break;
1720 }
1721
1722 // Ancestor check passed, so continue looping through them
1723 if ( ! empty( $check_ancestors ) ) {
1724
1725 // Loop through the forum ancestors
1726 foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
1727
1728 // Check if the forum is not a category
1729 if ( bbp_is_forum( $ancestor ) ) {
1730
1731 // Check the forum visibility
1732 $retval = bbp_is_forum_visibility( $ancestor, $status_name, false );
1733 if ( true === $retval ) {
1734 $count++;
1735 }
1736 }
1737
1738 // Break when it reach the max count
1739 if ( ( $operator === 'OR' ) && ( $count >= 1 ) ) {
1740 break;
1741 }
1742 }
1743 }
1744 }
1745
1746 // Filter & return
1747 return (bool) apply_filters( 'bbp_is_forum_visibility', $retval, $count, $forum_id, $status_name, $check_ancestors, $operator );
1748 }
1749
1750 /**
1751 * Output the author ID of the forum
1752 *
1753 * @since 2.1.0 bbPress (r3675)
1754 *
1755 * @param int $forum_id Optional. Forum id
1756 */
1757 function bbp_forum_author_id( $forum_id = 0 ) {
1758 echo bbp_get_forum_author_id( $forum_id );
1759 }
1760 /**
1761 * Return the author ID of the forum
1762 *
1763 * @since 2.1.0 bbPress (r3675)
1764 *
1765 * @param int $forum_id Optional. Forum id
1766 *
1767 * @return string Author of forum
1768 */
1769 function bbp_get_forum_author_id( $forum_id = 0 ) {
1770 $forum_id = bbp_get_forum_id( $forum_id );
1771 $author_id = get_post_field( 'post_author', $forum_id );
1772
1773 // Filter & return
1774 return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id );
1775 }
1776
1777 /**
1778 * Output the author of the forum
1779 *
1780 * @since 2.1.0 bbPress (r3675)
1781 *
1782 * @param int $forum_id Optional. Forum id
1783 */
1784 function bbp_forum_author_display_name( $forum_id = 0 ) {
1785 echo bbp_get_forum_author_display_name( $forum_id );
1786 }
1787 /**
1788 * Return the author of the forum
1789 *
1790 * @since 2.1.0 bbPress (r3675)
1791 *
1792 * @param int $forum_id Optional. Forum id
1793 * @return string Author of forum
1794 */
1795 function bbp_get_forum_author_display_name( $forum_id = 0 ) {
1796 $forum_id = bbp_get_forum_id( $forum_id );
1797 $author_id = bbp_get_forum_author_id( $forum_id );
1798 $author = get_the_author_meta( 'display_name', $author_id );
1799
1800 // Filter & return
1801 return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id, $author_id );
1802 }
1803
1804 /**
1805 * Replace forum meta details for users that cannot view them.
1806 *
1807 * @since 2.0.0 bbPress (r3162)
1808 *
1809 * @param string $retval
1810 * @param int $forum_id
1811 *
1812 * @return string
1813 */
1814 function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
1815 if ( bbp_is_forum_private( $forum_id, false ) && ! current_user_can( 'read_forum', $forum_id ) ) {
1816 $retval = '-';
1817 }
1818
1819 // Filter & return
1820 return apply_filters( 'bbp_suppress_private_forum_meta', $retval );
1821 }
1822
1823 /**
1824 * Replace forum author details for users that cannot view them.
1825 *
1826 * @since 2.0.0 bbPress (r3162)
1827 *
1828 * @param string $author_link
1829 * @param array $args
1830 *
1831 * @return string
1832 */
1833 function bbp_suppress_private_author_link( $author_link = '', $args = array() ) {
1834
1835 // Assume the author link is the return value
1836 $retval = $author_link;
1837
1838 // Show the normal author link
1839 if ( ! empty( $args['post_id'] ) && ! current_user_can( 'read_private_forums' ) ) {
1840
1841 // What post type are we looking at?
1842 switch ( get_post_type( $args['post_id'] ) ) {
1843
1844 // Topic
1845 case bbp_get_topic_post_type() :
1846 $forum_id = bbp_get_topic_forum_id( $args['post_id'] );
1847 break;
1848
1849 // Reply
1850 case bbp_get_reply_post_type() :
1851 $forum_id = bbp_get_reply_forum_id( $args['post_id'] );
1852 break;
1853
1854 // Post
1855 default :
1856 $forum_id = bbp_get_forum_id( $args['post_id'] );
1857 break;
1858 }
1859
1860 // Hide if forum is private
1861 if ( bbp_is_forum_private( $forum_id ) ) {
1862 $retval = '';
1863 }
1864 }
1865
1866 // Filter & return
1867 return apply_filters( 'bbp_suppress_private_author_link', $retval, $author_link, $args );
1868 }
1869
1870 /**
1871 * Output the row class of a forum
1872 *
1873 * @since 2.0.0 bbPress (r2667)
1874 *
1875 * @param int $forum_id Optional. Forum ID.
1876 * @param array Extra classes you can pass when calling this function
1877 */
1878 function bbp_forum_class( $forum_id = 0, $classes = array() ) {
1879 echo bbp_get_forum_class( $forum_id, $classes );
1880 }
1881 /**
1882 * Return the row class of a forum
1883 *
1884 * @since 2.0.0 bbPress (r2667)
1885 *
1886 * @param int $forum_id Optional. Forum ID
1887 * @param array Extra classes you can pass when calling this function
1888 * @return string Row class of the forum
1889 */
1890 function bbp_get_forum_class( $forum_id = 0, $classes = array() ) {
1891 $bbp = bbpress();
1892 $forum_id = bbp_get_forum_id( $forum_id );
1893 $parent_id = bbp_get_forum_parent_id( $forum_id );
1894 $author_id = bbp_get_forum_author_id( $forum_id );
1895 $status = bbp_get_forum_status( $forum_id );
1896 $visibility = bbp_get_forum_visibility( $forum_id );
1897 $classes = array_filter( (array) $classes );
1898 $count = isset( $bbp->forum_query->current_post )
1899 ? (int) $bbp->forum_query->current_post
1900 : 1;
1901
1902 // Stripes
1903 $even_odd = ( $count % 2 )
1904 ? 'even'
1905 : 'odd';
1906
1907 // User is moderator of forum
1908 $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id )
1909 ? 'forum-mod'
1910 : '';
1911
1912 // Is forum a non-postable category?
1913 $category = bbp_is_forum_category( $forum_id )
1914 ? 'status-category'
1915 : '';
1916
1917 // Forum has children?
1918 $subs = bbp_get_forum_subforum_count( $forum_id )
1919 ? 'bbp-has-subforums'
1920 : '';
1921
1922 // Forum has parent?
1923 $parent = ! empty( $parent_id )
1924 ? 'bbp-parent-forum-' . $parent_id
1925 : '';
1926
1927 // Get forum classes
1928 $forum_classes = array(
1929 'loop-item-' . $count,
1930 'bbp-forum-status-' . $status,
1931 'bbp-forum-visibility-' . $visibility,
1932 $even_odd,
1933 $forum_moderator,
1934 $category,
1935 $subs,
1936 $parent
1937 );
1938
1939 // Run the topic classes through the post-class filters, which also
1940 // handles the escaping of each individual class.
1941 $post_classes = get_post_class( array_merge( $classes, $forum_classes ), $forum_id );
1942
1943 // Filter
1944 $new_classes = apply_filters( 'bbp_get_forum_class', $post_classes, $forum_id, $classes );
1945
1946 // Return
1947 return 'class="' . implode( ' ', $new_classes ) . '"';
1948 }
1949
1950 /** Single Forum **************************************************************/
1951
1952 /**
1953 * Output a fancy description of the current forum, including total topics,
1954 * total replies, and last activity.
1955 *
1956 * @since 2.0.0 bbPress (r2860)
1957 *
1958 * @param array $args Arguments passed to alter output
1959 */
1960 function bbp_single_forum_description( $args = array() ) {
1961 echo bbp_get_single_forum_description( $args );
1962 }
1963 /**
1964 * Return a fancy description of the current forum, including total
1965 * topics, total replies, and last activity.
1966 *
1967 * @since 2.0.0 bbPress (r2860)
1968 *
1969 * @param array $args This function supports these arguments:
1970 * - forum_id: Forum id
1971 * - before: Before the text
1972 * - after: After the text
1973 * - size: Size of the avatar
1974 * @return string Filtered forum description
1975 */
1976 function bbp_get_single_forum_description( $args = array() ) {
1977
1978 // Parse arguments against default values
1979 $r = bbp_parse_args( $args, array(
1980 'forum_id' => 0,
1981 'before' => '<div class="bbp-template-notice info"><ul><li class="bbp-forum-description">',
1982 'after' => '</li></ul></div>',
1983 'size' => 14,
1984 'feed' => true
1985 ), 'get_single_forum_description' );
1986
1987 // Validate forum_id
1988 $forum_id = bbp_get_forum_id( $r['forum_id'] );
1989
1990 // Unhook the 'view all' query var adder
1991 remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1992
1993 // Get some forum data
1994 $tc_int = bbp_get_forum_topic_count( $forum_id, true, true );
1995 $rc_int = bbp_get_forum_reply_count( $forum_id, true, true );
1996 $topic_count = bbp_get_forum_topic_count( $forum_id, true, false );
1997 $reply_count = bbp_get_forum_reply_count( $forum_id, true, false );
1998 $last_active = bbp_get_forum_last_active_id( $forum_id );
1999
2000 // Has replies
2001 if ( ! empty( $reply_count ) ) {
2002 $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count );
2003 }
2004
2005 // Forum has active data
2006 if ( ! empty( $last_active ) ) {
2007 $topic_text = bbp_get_forum_topics_link( $forum_id );
2008 $time_since = bbp_get_forum_freshness_link( $forum_id );
2009 $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_active, 'size' => $r['size'] ) );
2010
2011 // Forum has no last active data
2012 } else {
2013 $topic_text = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count );
2014 }
2015
2016 // Forum has active data
2017 if ( ! empty( $last_active ) ) {
2018
2019 // Has replies
2020 if ( ! empty( $reply_count ) ) {
2021 $retstr = bbp_is_forum_category( $forum_id )
2022 ? sprintf( esc_html__( 'This category has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by )
2023 : sprintf( esc_html__( 'This forum has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by );
2024
2025 // Only has topics
2026 } else {
2027 $retstr = bbp_is_forum_category( $forum_id )
2028 ? sprintf( esc_html__( 'This category has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by )
2029 : sprintf( esc_html__( 'This forum has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by );
2030 }
2031
2032 // Forum has no last active data (but does have topics & replies)
2033 } elseif ( ! empty( $reply_count ) ) {
2034 $retstr = bbp_is_forum_category( $forum_id )
2035 ? sprintf( esc_html__( 'This category has %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text )
2036 : sprintf( esc_html__( 'This forum has %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text );
2037
2038 // Forum has no last active data or replies (but does have topics)
2039 } elseif ( ! empty( $topic_count ) ) {
2040 $retstr = bbp_is_forum_category( $forum_id )
2041 ? sprintf( esc_html__( 'This category has %1$s.', 'bbpress' ), $topic_text )
2042 : sprintf( esc_html__( 'This forum has %1$s.', 'bbpress' ), $topic_text );
2043
2044 // Forum is empty
2045 } else {
2046 $retstr = esc_html__( 'This forum is empty.', 'bbpress' );
2047 }
2048
2049 // Add the 'view all' filter back
2050 add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
2051
2052 // Combine the elements together
2053 $retstr = $r['before'] . $retstr . $r['after'];
2054
2055 // Filter & return
2056 return apply_filters( 'bbp_get_single_forum_description', $retstr, $r, $args );
2057 }
2058
2059 /** Forms *********************************************************************/
2060
2061 /**
2062 * Output the value of forum title field
2063 *
2064 * @since 2.1.0 bbPress (r3551)
2065 */
2066 function bbp_form_forum_title() {
2067 echo bbp_get_form_forum_title();
2068 }
2069 /**
2070 * Return the value of forum title field
2071 *
2072 * @since 2.1.0 bbPress (r3551)
2073 *
2074 * @return string Value of forum title field
2075 */
2076 function bbp_get_form_forum_title() {
2077
2078 // Get _POST data
2079 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_title'] ) ) {
2080 $forum_title = wp_unslash( $_POST['bbp_forum_title'] );
2081
2082 // Get edit data
2083 } elseif ( bbp_is_forum_edit() ) {
2084 $forum_title = bbp_get_global_post_field( 'post_title', 'raw' );
2085
2086 // No data
2087 } else {
2088 $forum_title = '';
2089 }
2090
2091 // Filter & return
2092 return apply_filters( 'bbp_get_form_forum_title', $forum_title );
2093 }
2094
2095 /**
2096 * Output the value of forum content field
2097 *
2098 * @since 2.1.0 bbPress (r3551)
2099 */
2100 function bbp_form_forum_content() {
2101 echo bbp_get_form_forum_content();
2102 }
2103 /**
2104 * Return the value of forum content field
2105 *
2106 * @since 2.1.0 bbPress (r3551)
2107 *
2108 * @return string Value of forum content field
2109 */
2110 function bbp_get_form_forum_content() {
2111
2112 // Get _POST data
2113 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_content'] ) ) {
2114 $forum_content = wp_unslash( $_POST['bbp_forum_content'] );
2115
2116 // Get edit data
2117 } elseif ( bbp_is_forum_edit() ) {
2118 $forum_content = bbp_get_global_post_field( 'post_content', 'raw' );
2119
2120 // No data
2121 } else {
2122 $forum_content = '';
2123 }
2124
2125 // Filter & return
2126 return apply_filters( 'bbp_get_form_forum_content', $forum_content );
2127 }
2128
2129 /**
2130 * Output value of forum moderators field
2131 *
2132 * @since 2.6.0 bbPress (r5837)
2133 */
2134 function bbp_form_forum_moderators() {
2135 echo bbp_get_form_forum_moderators();
2136 }
2137 /**
2138 * Return value of forum moderators field
2139 *
2140 * @since 2.6.0 bbPress (r5837)
2141 *
2142 * @return string Value of forum mods field
2143 */
2144 function bbp_get_form_forum_moderators() {
2145
2146 // Default return value
2147 $forum_mods = '';
2148
2149 // Get _POST data
2150 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_moderators'] ) ) {
2151 $forum_mods = wp_unslash( $_POST['bbp_moderators'] );
2152
2153 // Get edit data
2154 } elseif ( bbp_is_single_forum() || bbp_is_forum_edit() ) {
2155
2156 // Get the forum ID
2157 $forum_id = bbp_get_forum_id( get_the_ID() );
2158
2159 // Forum exists
2160 if ( ! empty( $forum_id ) ) {
2161
2162 // Get moderator IDs
2163 $user_ids = bbp_get_moderator_ids( $forum_id );
2164 if ( ! empty( $user_ids ) ) {
2165 $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids );
2166
2167 // Comma separate user nicenames
2168 if ( ! empty( $user_nicenames ) ) {
2169 $forum_mods = implode( ', ', wp_list_pluck( $user_nicenames, 'user_nicename' ) );
2170 }
2171 }
2172 }
2173 }
2174
2175 // Filter & return
2176 return apply_filters( 'bbp_get_form_forum_moderators', $forum_mods );
2177 }
2178
2179 /**
2180 * Output value of forum parent
2181 *
2182 * @since 2.1.0 bbPress (r3551)
2183 */
2184 function bbp_form_forum_parent() {
2185 echo bbp_get_form_forum_parent();
2186 }
2187 /**
2188 * Return value of forum parent
2189 *
2190 * @since 2.1.0 bbPress (r3551)
2191 *
2192 * @return string Value of topic content field
2193 */
2194 function bbp_get_form_forum_parent() {
2195
2196 // Get _POST data
2197 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) {
2198 $forum_parent = (int) $_POST['bbp_forum_id'];
2199
2200 // Get edit data
2201 } elseif ( bbp_is_forum_edit() ) {
2202 $forum_parent = bbp_get_forum_parent_id();
2203
2204 // No data
2205 } else {
2206 $forum_parent = 0;
2207 }
2208
2209 // Filter & return
2210 return apply_filters( 'bbp_get_form_forum_parent', $forum_parent );
2211 }
2212
2213 /**
2214 * Output value of forum type
2215 *
2216 * @since 2.1.0 bbPress (r3563)
2217 */
2218 function bbp_form_forum_type() {
2219 echo bbp_get_form_forum_type();
2220 }
2221 /**
2222 * Return value of forum type
2223 *
2224 * @since 2.1.0 bbPress (r3563)
2225 *
2226 * @return string Value of topic content field
2227 */
2228 function bbp_get_form_forum_type() {
2229
2230 // Get _POST data
2231 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_type'] ) ) {
2232 $forum_type = sanitize_key( $_POST['bbp_forum_type'] );
2233
2234 // Get edit data
2235 } elseif ( bbp_is_forum_edit() ) {
2236 $forum_type = bbp_get_forum_type();
2237
2238 // No data
2239 } else {
2240 $forum_type = 'forum';
2241 }
2242
2243 // Filter & return
2244 return apply_filters( 'bbp_get_form_forum_type', $forum_type );
2245 }
2246
2247 /**
2248 * Output value of forum visibility
2249 *
2250 * @since 2.1.0 bbPress (r3563)
2251 */
2252 function bbp_form_forum_visibility() {
2253 echo bbp_get_form_forum_visibility();
2254 }
2255 /**
2256 * Return value of forum visibility
2257 *
2258 * @since 2.1.0 bbPress (r3563)
2259 *
2260 * @return string Value of topic content field
2261 */
2262 function bbp_get_form_forum_visibility() {
2263
2264 // Get _POST data
2265 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_visibility'] ) ) {
2266 $forum_visibility = sanitize_key( $_POST['bbp_forum_visibility'] );
2267
2268 // Get edit data
2269 } elseif ( bbp_is_forum_edit() ) {
2270 $forum_visibility = bbp_get_forum_visibility();
2271
2272 // No data
2273 } else {
2274 $forum_visibility = bbpress()->public_status_id;
2275 }
2276
2277 // Filter & return
2278 return apply_filters( 'bbp_get_form_forum_visibility', $forum_visibility );
2279 }
2280
2281 /**
2282 * Output checked value of forum subscription
2283 *
2284 * @since 2.5.0 bbPress (r5156)
2285 */
2286 function bbp_form_forum_subscribed() {
2287 echo bbp_get_form_forum_subscribed();
2288 }
2289 /**
2290 * Return checked value of forum subscription
2291 *
2292 * @since 2.5.0 bbPress (r5156)
2293 *
2294 * @return string Checked value of forum subscription
2295 */
2296 function bbp_get_form_forum_subscribed() {
2297
2298 // Default value
2299 $forum_subscribed = false;
2300
2301 // Get _POST data
2302 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) {
2303 $forum_subscribed = (bool) $_POST['bbp_forum_subscription'];
2304
2305 // Get edit data
2306 } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) {
2307 $post_author = (int) bbp_get_global_post_field( 'post_author', 'raw' );
2308 $forum_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_forum_id() );
2309
2310 // Get current status
2311 } elseif ( bbp_is_single_forum() ) {
2312 $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_forum_id() );
2313 }
2314
2315 // Get checked output
2316 $checked = checked( $forum_subscribed, true, false );
2317
2318 // Filter & return
2319 return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed );
2320 }
2321
2322 /** Form Dropdowns ************************************************************/
2323
2324 /**
2325 * Output value forum type dropdown
2326 *
2327 * @since 2.1.0 bbPress (r3563)
2328 *
2329 * @param $args This function supports these arguments:
2330 * - select_id: Select id. Defaults to bbp_forum_type
2331 * - tab: Deprecated. Tabindex
2332 * - forum_id: Forum id
2333 * - selected: Override the selected option
2334 */
2335 function bbp_form_forum_type_dropdown( $args = array() ) {
2336 echo bbp_get_form_forum_type_dropdown( $args );
2337 }
2338 /**
2339 * Return the forum type dropdown
2340 *
2341 * @since 2.1.0 bbPress (r3563)
2342 *
2343 * @param $args This function supports these arguments:
2344 * - select_id: Select id. Defaults to bbp_forum_type
2345 * - tab: Deprecated. Tabindex
2346 * - forum_id: Forum id
2347 * - selected: Override the selected option
2348 * @return string HTML select list for selecting forum type
2349 */
2350 function bbp_get_form_forum_type_dropdown( $args = array() ) {
2351
2352 // Backpat for handling passing of a forum ID as integer
2353 if ( is_int( $args ) ) {
2354 $forum_id = (int) $args;
2355 $args = array();
2356 } else {
2357 $forum_id = 0;
2358 }
2359
2360 // Parse arguments against default values
2361 $r = bbp_parse_args( $args, array(
2362 'select_id' => 'bbp_forum_type',
2363 'select_class' => 'bbp_dropdown',
2364 'tab' => false,
2365 'forum_id' => $forum_id,
2366 'selected' => false
2367 ), 'forum_type_select' );
2368
2369 // No specific selected value passed
2370 if ( empty( $r['selected'] ) ) {
2371
2372 // Post value is passed
2373 if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2374 $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2375
2376 // No Post value was passed
2377 } else {
2378
2379 // Edit topic
2380 if ( bbp_is_forum_edit() ) {
2381 $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2382 $r['selected'] = bbp_get_forum_type( $r['forum_id'] );
2383
2384 // New topic
2385 } else {
2386 $r['selected'] = bbp_get_public_status_id();
2387 }
2388 }
2389 }
2390
2391 // Start an output buffer, we'll finish it after the select loop
2392 ob_start(); ?>
2393
2394 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2395
2396 <?php foreach ( bbp_get_forum_types( $r['forum_id'] ) as $key => $label ) : ?>
2397
2398 <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2399
2400 <?php endforeach; ?>
2401
2402 </select>
2403
2404 <?php
2405
2406 // Filter & return
2407 return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
2408 }
2409
2410 /**
2411 * Output value forum status dropdown
2412 *
2413 * @since 2.1.0 bbPress (r3563)
2414 *
2415 * @param $args This function supports these arguments:
2416 * - select_id: Select id. Defaults to bbp_forum_status
2417 * - tab: Deprecated. Tabindex
2418 * - forum_id: Forum id
2419 * - selected: Override the selected option
2420 */
2421 function bbp_form_forum_status_dropdown( $args = array() ) {
2422 echo bbp_get_form_forum_status_dropdown( $args );
2423 }
2424 /**
2425 * Return the forum status dropdown
2426 *
2427 * @since 2.1.0 bbPress (r3563)
2428 *
2429 * @param $args This function supports these arguments:
2430 * - select_id: Select id. Defaults to bbp_forum_status
2431 * - tab: Deprecated. Tabindex
2432 * - forum_id: Forum id
2433 * - selected: Override the selected option
2434 * @return string HTML select list for selecting forum status
2435 */
2436 function bbp_get_form_forum_status_dropdown( $args = array() ) {
2437
2438 // Backpat for handling passing of a forum ID
2439 if ( is_int( $args ) ) {
2440 $forum_id = (int) $args;
2441 $args = array();
2442 } else {
2443 $forum_id = 0;
2444 }
2445
2446 // Parse arguments against default values
2447 $r = bbp_parse_args( $args, array(
2448 'select_id' => 'bbp_forum_status',
2449 'select_class' => 'bbp_dropdown',
2450 'tab' => false,
2451 'forum_id' => $forum_id,
2452 'selected' => false
2453 ), 'forum_status_select' );
2454
2455 // No specific selected value passed
2456 if ( empty( $r['selected'] ) ) {
2457
2458 // Post value is passed
2459 if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2460 $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2461
2462 // No Post value was passed
2463 } else {
2464
2465 // Edit topic
2466 if ( bbp_is_forum_edit() ) {
2467 $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2468 $r['selected'] = bbp_get_forum_status( $r['forum_id'] );
2469
2470 // New topic
2471 } else {
2472 $r['selected'] = bbp_get_public_status_id();
2473 }
2474 }
2475 }
2476
2477 // Start an output buffer, we'll finish it after the select loop
2478 ob_start(); ?>
2479
2480 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2481
2482 <?php foreach ( bbp_get_forum_statuses( $r['forum_id'] ) as $key => $label ) : ?>
2483
2484 <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2485
2486 <?php endforeach; ?>
2487
2488 </select>
2489
2490 <?php
2491
2492 // Filter & return
2493 return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r, $args );
2494 }
2495
2496 /**
2497 * Output value forum visibility dropdown
2498 *
2499 * @since 2.1.0 bbPress (r3563)
2500 *
2501 * @param $args This function supports these arguments:
2502 * - select_id: Select id. Defaults to bbp_forum_visibility
2503 * - tab: Deprecated. Tabindex
2504 * - forum_id: Forum id
2505 * - selected: Override the selected option
2506 */
2507 function bbp_form_forum_visibility_dropdown( $args = array() ) {
2508 echo bbp_get_form_forum_visibility_dropdown( $args );
2509 }
2510 /**
2511 * Return the forum visibility dropdown
2512 *
2513 * @since 2.1.0 bbPress (r3563)
2514 *
2515 * @param $args This function supports these arguments:
2516 * - select_id: Select id. Defaults to bbp_forum_visibility
2517 * - tab: Deprecated. Tabindex
2518 * - forum_id: Forum id
2519 * - selected: Override the selected option
2520 * @return string HTML select list for selecting forum visibility
2521 */
2522 function bbp_get_form_forum_visibility_dropdown( $args = array() ) {
2523
2524 // Backpat for handling passing of a forum ID
2525 if ( is_int( $args ) ) {
2526 $forum_id = (int) $args;
2527 $args = array();
2528 } else {
2529 $forum_id = 0;
2530 }
2531
2532 // Parse arguments against default values
2533 $r = bbp_parse_args( $args, array(
2534 'select_id' => 'bbp_forum_visibility',
2535 'select_class' => 'bbp_dropdown',
2536 'tab' => false,
2537 'forum_id' => $forum_id,
2538 'selected' => false
2539 ), 'forum_type_select' );
2540
2541 // No specific selected value passed
2542 if ( empty( $r['selected'] ) ) {
2543
2544 // Post value is passed
2545 if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2546 $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2547
2548 // No Post value was passed
2549 } else {
2550
2551 // Edit topic
2552 if ( bbp_is_forum_edit() ) {
2553 $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2554 $r['selected'] = bbp_get_forum_visibility( $r['forum_id'] );
2555
2556 // New topic
2557 } else {
2558 $r['selected'] = bbp_get_public_status_id();
2559 }
2560 }
2561 }
2562
2563 // Start an output buffer, we'll finish it after the select loop
2564 ob_start(); ?>
2565
2566 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2567
2568 <?php foreach ( bbp_get_forum_visibilities( $r['forum_id'] ) as $key => $label ) : ?>
2569
2570 <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2571
2572 <?php endforeach; ?>
2573
2574 </select>
2575
2576 <?php
2577
2578 // Filter & return
2579 return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
2580 }
2581
2582 /**
2583 * Verify if a POST request came from a failed forum attempt.
2584 *
2585 * Used to avoid cross-site request forgeries when checking posted forum form
2586 * content.
2587 *
2588 * @see bbp_forum_form_fields()
2589 *
2590 * @since 2.6.0 bbPress (r5558)
2591 *
2592 * @return boolean True if is a post request with valid nonce
2593 */
2594 function bbp_is_forum_form_post_request() {
2595
2596 // Bail if not a post request
2597 if ( ! bbp_is_post_request() ) {
2598 return false;
2599 }
2600
2601 // Creating a new forum
2602 if ( bbp_verify_nonce_request( 'bbp-new-forum' ) ) {
2603 return true;
2604 }
2605
2606 // Editing an existing forum
2607 if ( bbp_verify_nonce_request( 'bbp-edit-forum_' . bbp_get_forum_id() ) ) {
2608 return true;
2609 }
2610
2611 return false;
2612 }
2613
2614 /** Feeds *********************************************************************/
2615
2616 /**
2617 * Output the link for the forum feed
2618 *
2619 * @since 2.0.0 bbPress (r3172)
2620 *
2621 * @param int $forum_id Optional. Forum ID.
2622 */
2623 function bbp_forum_topics_feed_link( $forum_id = 0 ) {
2624 echo bbp_get_forum_topics_feed_link( $forum_id );
2625 }
2626 /**
2627 * Retrieve the link for the forum feed
2628 *
2629 * @since 2.0.0 bbPress (r3172)
2630 *
2631 * @param int $forum_id Optional. Forum ID.
2632 *
2633 * @return string
2634 */
2635 function bbp_get_forum_topics_feed_link( $forum_id = 0 ) {
2636
2637 // Validate forum id
2638 $forum_id = bbp_get_forum_id( $forum_id );
2639
2640 // Forum is valid
2641 if ( ! empty( $forum_id ) ) {
2642
2643 // Define local variable(s)
2644 $link = '';
2645
2646 // Pretty permalinks
2647 if ( get_option( 'permalink_structure' ) ) {
2648
2649 // Forum link
2650 $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
2651 $url = user_trailingslashit( $url, 'single_feed' );
2652
2653 // Unpretty permalinks
2654 } else {
2655 $url = home_url( add_query_arg( array(
2656 'feed' => 'rss2',
2657 bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
2658 ) ) );
2659 }
2660
2661 $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link topics"><span>' . esc_attr__( 'Topics', 'bbpress' ) . '</span></a>';
2662 }
2663
2664 // Filter & return
2665 return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id );
2666 }
2667
2668 /**
2669 * Output the link for the forum replies feed
2670 *
2671 * @since 2.0.0 bbPress (r3172)
2672 *
2673 * @param int $forum_id Optional. Forum ID.
2674 */
2675 function bbp_forum_replies_feed_link( $forum_id = 0 ) {
2676 echo bbp_get_forum_replies_feed_link( $forum_id );
2677 }
2678 /**
2679 * Retrieve the link for the forum replies feed
2680 *
2681 * @since 2.0.0 bbPress (r3172)
2682 *
2683 * @param int $forum_id Optional. Forum ID.
2684 *
2685 * @return string
2686 */
2687 function bbp_get_forum_replies_feed_link( $forum_id = 0 ) {
2688
2689 // Validate forum id
2690 $forum_id = bbp_get_forum_id( $forum_id );
2691
2692 // Forum is valid
2693 if ( ! empty( $forum_id ) ) {
2694
2695 // Define local variable(s)
2696 $link = '';
2697
2698 // Pretty permalinks
2699 if ( get_option( 'permalink_structure' ) ) {
2700
2701 // Forum link
2702 $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
2703 $url = user_trailingslashit( $url, 'single_feed' );
2704 $url = add_query_arg( array( 'type' => 'reply' ), $url );
2705
2706 // Unpretty permalinks
2707 } else {
2708 $url = home_url( add_query_arg( array(
2709 'type' => 'reply',
2710 'feed' => 'rss2',
2711 bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
2712 ) ) );
2713 }
2714
2715 $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link replies"><span>' . esc_html__( 'Replies', 'bbpress' ) . '</span></a>';
2716 }
2717
2718 // Filter & return
2719 return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id );
2720 }
2721