PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.0.0
Forumax – AI Powered Advanced Community Forum Plugin v2.0.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 / vendor / bbpress / includes / forums / template.php

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

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