PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / includes / forums / template.php

template.php in bbPress 2.6.17, at includes/forums/template.php

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