PluginProbe
bbPress / 2.0-rc-3
bbPress v2.0-rc-3
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 / bbp-includes / bbp-forum-template.php

bbp-forum-template.php in bbPress 2.0-rc-3, at bbp-includes/bbp-forum-template.php

1,848 lines 58.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Forum Template Tags
5 *
6 * @package bbPress
7 * @subpackage TemplateTags
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Post Type *****************************************************************/
14
15 /**
16 * Output the unique id of the custom post type for forums
17 *
18 * @since bbPress (r2857)
19 * @uses bbp_get_forum_post_type() To get the forum post type
20 */
21 function bbp_forum_post_type() {
22 echo bbp_get_forum_post_type();
23 }
24 /**
25 * Return the unique id of the custom post type for forums
26 *
27 * @since bbPress (r2857)
28 *
29 * @uses apply_filters() Calls 'bbp_get_forum_post_type' with the forum
30 * post type id
31 * @return string The unique forum post type id
32 */
33 function bbp_get_forum_post_type() {
34 global $bbp;
35
36 return apply_filters( 'bbp_get_forum_post_type', $bbp->forum_post_type );
37 }
38
39 /** Forum Loop ****************************************************************/
40
41 /**
42 * The main forum loop.
43 *
44 * WordPress makes this easy for us.
45 *
46 * @since bbPress (r2464)
47 *
48 * @param mixed $args All the arguments supported by {@link WP_Query}
49 * @uses WP_Query To make query and get the forums
50 * @uses bbp_get_forum_post_type() To get the forum post type id
51 * @uses bbp_get_forum_id() To get the forum id
52 * @uses get_option() To get the forums per page option
53 * @uses current_user_can() To check if the current user is capable of editing
54 * others' forums
55 * @uses apply_filters() Calls 'bbp_has_forums' with
56 * bbPres::forum_query::have_posts()
57 * and bbPres::forum_query
58 * @return object Multidimensional array of forum information
59 */
60 function bbp_has_forums( $args = '' ) {
61 global $bbp;
62
63 // Setup possible post__not_in array
64 $post_stati[] = 'publish';
65
66 // Super admin get whitelisted post statuses
67 if ( is_super_admin() ) {
68 $post_stati = array( 'publish', 'private', 'hidden' );
69
70 // Not a super admin, so check caps
71 } else {
72
73 // Check if user can read private forums
74 if ( current_user_can( 'read_private_forums' ) )
75 $post_stati[] = 'private';
76
77 // Check if user can read hidden forums
78 if ( current_user_can( 'read_hidden_forums' ) )
79 $post_stati[] = 'hidden';
80 }
81
82 // The default forum query for most circumstances
83 $default = array (
84 'post_type' => bbp_get_forum_post_type(),
85 'post_parent' => bbp_is_forum_archive() ? 0 : bbp_get_forum_id() ,
86 'post_status' => implode( ',', $post_stati ),
87 'posts_per_page' => get_option( '_bbp_forums_per_page', 15 ),
88 'orderby' => 'menu_order',
89 'order' => 'ASC'
90 );
91
92 // Parse the default against what is requested
93 $bbp_f = wp_parse_args( $args, $default );
94
95 // Filter the forums query to allow just-in-time modifications
96 $bbp_f = apply_filters( 'bbp_has_forums_query', $bbp_f );
97
98 // Run the query
99 $bbp->forum_query = new WP_Query( $bbp_f );
100
101 return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
102 }
103
104 /**
105 * Whether there are more forums available in the loop
106 *
107 * @since bbPress (r2464)
108 *
109 * @uses bbPress:forum_query::have_posts() To check if there are more forums
110 * available
111 * @return object Forum information
112 */
113 function bbp_forums() {
114 global $bbp;
115
116 // Put into variable to check against next
117 $have_posts = $bbp->forum_query->have_posts();
118
119 // Reset the post data when finished
120 if ( empty( $have_posts ) )
121 wp_reset_postdata();
122
123 return $have_posts;
124 }
125
126 /**
127 * Loads up the current forum in the loop
128 *
129 * @since bbPress (r2464)
130 *
131 * @uses bbPress:forum_query::the_post() To get the current forum
132 * @return object Forum information
133 */
134 function bbp_the_forum() {
135 global $bbp;
136 return $bbp->forum_query->the_post();
137 }
138
139 /** Forum *********************************************************************/
140
141 /**
142 * Output forum id
143 *
144 * @since bbPress (r2464)
145 *
146 * @param $forum_id Optional. Used to check emptiness
147 * @uses bbp_get_forum_id() To get the forum id
148 */
149 function bbp_forum_id( $forum_id = 0 ) {
150 echo bbp_get_forum_id( $forum_id );
151 }
152 /**
153 * Return the forum id
154 *
155 * @since bbPress (r2464)
156 *
157 * @param $forum_id Optional. Used to check emptiness
158 * @uses bbPress::forum_query::in_the_loop To check if we're in the loop
159 * @uses bbPress::forum_query::post::ID To get the forum id
160 * @uses WP_Query::post::ID To get the forum id
161 * @uses bbp_is_single_forum() To check if it's a forum page
162 * @uses bbp_is_single_topic() To check if it's a topic page
163 * @uses bbp_get_topic_forum_id() To get the topic forum id
164 * @uses get_post_field() To get the post's post type
165 * @uses apply_filters() Calls 'bbp_get_forum_id' with the forum id and
166 * supplied forum id
167 * @return int The forum id
168 */
169 function bbp_get_forum_id( $forum_id = 0 ) {
170 global $bbp, $wp_query;
171
172 // Easy empty checking
173 if ( !empty( $forum_id ) && is_numeric( $forum_id ) )
174 $bbp_forum_id = $bbp->current_forum_id = $forum_id;
175
176 // Currently inside a forum loop
177 elseif ( !empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) )
178 $bbp_forum_id = $bbp->current_forum_id = $bbp->forum_query->post->ID;
179
180 // Currently viewing a forum
181 elseif ( bbp_is_single_forum() && isset( $wp_query->post->ID ) )
182 $bbp_forum_id = $bbp->current_forum_id = $wp_query->post->ID;
183
184 // Currently viewing a topic
185 elseif ( bbp_is_single_topic() )
186 $bbp_forum_id = $bbp->current_forum_id = bbp_get_topic_forum_id();
187
188 // Fallback
189 else
190 $bbp_forum_id = 0;
191
192 return apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
193 }
194
195 /**
196 * Gets a forum
197 *
198 * @since bbPress (r2787)
199 *
200 * @param int|object $forum forum id or forum object
201 * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
202 * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
203 * @uses get_post() To get the forum
204 * @uses apply_filters() Calls 'bbp_get_forum' with the forum, output type and
205 * sanitation filter
206 * @return mixed Null if error or forum (in specified form) if success
207 */
208 function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) {
209 if ( empty( $forum ) || is_numeric( $forum ) )
210 $forum = bbp_get_forum_id( $forum );
211
212 if ( !$forum = get_post( $forum, OBJECT, $filter ) )
213 return $forum;
214
215 if ( $forum->post_type !== bbp_get_forum_post_type() )
216 return null;
217
218 if ( $output == OBJECT ) {
219 return $forum;
220
221 } elseif ( $output == ARRAY_A ) {
222 $_forum = get_object_vars( $forum );
223 return $_forum;
224
225 } elseif ( $output == ARRAY_N ) {
226 $_forum = array_values( get_object_vars( $forum ) );
227 return $_forum;
228
229 }
230
231 return apply_filters( 'bbp_get_forum', $forum, $output, $filter );
232 }
233
234 /**
235 * Output the link to the forum
236 *
237 * @since bbPress (r2464)
238 *
239 * @param int $forum_id Optional. Forum id
240 * @uses bbp_get_forum_permalink() To get the permalink
241 */
242 function bbp_forum_permalink( $forum_id = 0 ) {
243 echo bbp_get_forum_permalink( $forum_id );
244 }
245 /**
246 * Return the link to the forum
247 *
248 * @since bbPress (r2464)
249 *
250 * @param int $forum_id Optional. Forum id
251 * @uses bbp_get_forum_id() To get the forum id
252 * @uses get_permalink() Get the permalink of the forum
253 * @uses apply_filters() Calls 'bbp_get_forum_permalink' with the forum
254 * link
255 * @return string Permanent link to forum
256 */
257 function bbp_get_forum_permalink( $forum_id = 0 ) {
258 $forum_id = bbp_get_forum_id( $forum_id );
259 return apply_filters( 'bbp_get_forum_permalink', get_permalink( $forum_id ) );
260 }
261
262 /**
263 * Output the title of the forum
264 *
265 * @since bbPress (r2464)
266 *
267 * @param int $forum_id Optional. Forum id
268 * @uses bbp_get_forum_title() To get the forum title
269 */
270 function bbp_forum_title( $forum_id = 0 ) {
271 echo bbp_get_forum_title( $forum_id );
272 }
273 /**
274 * Return the title of the forum
275 *
276 * @since bbPress (r2464)
277 *
278 * @param int $forum_id Optional. Forum id
279 * @uses bbp_get_forum_id() To get the forum id
280 * @uses get_the_title() To get the forum title
281 * @uses apply_filters() Calls 'bbp_get_forum_title' with the title
282 * @return string Title of forum
283 */
284 function bbp_get_forum_title( $forum_id = 0 ) {
285 $forum_id = bbp_get_forum_id( $forum_id );
286
287 return apply_filters( 'bbp_get_forum_title', get_the_title( $forum_id ) );
288 }
289
290 /**
291 * Output the forum archive title
292 *
293 * @since bbPress (r3249)
294 *
295 * @param string $title Default text to use as title
296 */
297 function bbp_forum_archive_title( $title = '' ) {
298 echo bbp_get_forum_archive_title( $title );
299 }
300 /**
301 * Return the forum archive title
302 *
303 * @since bbPress (r3249)
304 *
305 * @global bbPress $bbp The main bbPress class
306 * @param string $title Default text to use as title
307 *
308 * @uses bbp_get_page_by_path() Check if page exists at root path
309 * @uses get_the_title() Use the page title at the root path
310 * @uses get_post_type_object() Load the post type object
311 * @uses bbp_get_forum_post_type() Get the forum post type ID
312 * @uses get_post_type_labels() Get labels for forum post type
313 * @uses apply_filters() Allow output to be manipulated
314 *
315 * @return string The forum archive title
316 */
317 function bbp_get_forum_archive_title( $title = '' ) {
318 global $bbp;
319
320 // If no title was passed
321 if ( empty( $title ) ) {
322
323 // Set root text to page title
324 if ( $page = bbp_get_page_by_path( $bbp->root_slug ) ) {
325 $title = get_the_title( $page->ID );
326
327 // Default to forum post type name label
328 } else {
329 $fto = get_post_type_object( bbp_get_forum_post_type() );
330 $title = $fto->labels->name;
331 }
332 }
333
334 return apply_filters( 'bbp_get_forum_archive_title', $title );
335 }
336
337 /**
338 * Output the content of the forum
339 *
340 * @since bbPress (r2780)
341 *
342 * @param int $forum_id Optional. Topic id
343 * @uses bbp_get_forum_content() To get the forum content
344 */
345 function bbp_forum_content( $forum_id = 0 ) {
346 echo bbp_get_forum_content( $forum_id );
347 }
348 /**
349 * Return the content of the forum
350 *
351 * @since bbPress (r2780)
352 *
353 * @param int $forum_id Optional. Topic id
354 * @uses bbp_get_forum_id() To get the forum id
355 * @uses post_password_required() To check if the forum requires pass
356 * @uses get_the_password_form() To get the password form
357 * @uses get_post_field() To get the content post field
358 * @uses apply_filters() Calls 'bbp_get_forum_content' with the content
359 * and forum id
360 * @return string Content of the forum
361 */
362 function bbp_get_forum_content( $forum_id = 0 ) {
363 $forum_id = bbp_get_forum_id( $forum_id );
364
365 // Check if password is required
366 if ( post_password_required( $forum_id ) )
367 return get_the_password_form();
368
369 $content = get_post_field( 'post_content', $forum_id );
370
371 return apply_filters( 'bbp_get_forum_content', $content, $forum_id );
372 }
373
374 /**
375 * Output the forums last active ID
376 *
377 * @since bbPress (r2860)
378 *
379 * @uses bbp_get_forum_last_active_id() To get the forum's last active id
380 * @param int $forum_id Optional. Forum id
381 */
382 function bbp_forum_last_active_id( $forum_id = 0 ) {
383 echo bbp_get_forum_last_active_id( $forum_id );
384 }
385 /**
386 * Return the forums last active ID
387 *
388 * @since bbPress (r2860)
389 *
390 * @param int $forum_id Optional. Forum id
391 * @uses bbp_get_forum_id() To get the forum id
392 * @uses get_post_meta() To get the forum's last active id
393 * @uses apply_filters() Calls 'bbp_get_forum_last_active_id' with
394 * the last active id and forum id
395 * @return int Forum's last active id
396 */
397 function bbp_get_forum_last_active_id( $forum_id = 0 ) {
398 $forum_id = bbp_get_forum_id( $forum_id );
399 $active_id = get_post_meta( $forum_id, '_bbp_last_active_id', true );
400
401 return apply_filters( 'bbp_get_forum_last_active_id', (int) $active_id, $forum_id );
402 }
403
404 /**
405 * Output the forums last update date/time (aka freshness)
406 *
407 * @since bbPress (r2464)
408 *
409 * @uses bbp_get_forum_last_active_time() To get the forum freshness
410 * @param int $forum_id Optional. Forum id
411 */
412 function bbp_forum_last_active_time( $forum_id = 0 ) {
413 echo bbp_get_forum_last_active_time( $forum_id );
414 }
415 /**
416 * Return the forums last update date/time (aka freshness)
417 *
418 * @since bbPress (r2464)
419 *
420 * @param int $forum_id Optional. Forum id
421 * @uses bbp_get_forum_id() To get the forum id
422 * @uses get_post_meta() To retrieve forum last active meta
423 * @uses bbp_get_forum_last_reply_id() To get forum's last reply id
424 * @uses get_post_field() To get the post date of the reply
425 * @uses bbp_get_forum_last_topic_id() To get forum's last topic id
426 * @uses bbp_get_topic_last_active_time() To get time when the topic was
427 * last active
428 * @uses bbp_convert_date() To convert the date
429 * @uses bbp_get_time_since() To get time in since format
430 * @uses apply_filters() Calls 'bbp_get_forum_last_active' with last
431 * active time and forum id
432 * @return string Forum last update date/time (freshness)
433 */
434 function bbp_get_forum_last_active_time( $forum_id = 0 ) {
435 $forum_id = bbp_get_forum_id( $forum_id );
436
437 if ( !$last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true ) ) {
438 if ( $reply_id = bbp_get_forum_last_reply_id( $forum_id ) ) {
439 $last_active = get_post_field( 'post_date', $reply_id );
440 } else {
441 if ( $topic_id = bbp_get_forum_last_topic_id( $forum_id ) ) {
442 $last_active = bbp_get_topic_last_active_time( $topic_id );
443 }
444 }
445 }
446
447 $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
448
449 return apply_filters( 'bbp_get_forum_last_active', $last_active, $forum_id );
450 }
451
452 /**
453 * Output link to the most recent activity inside a forum.
454 *
455 * Outputs a complete link with attributes and content.
456 *
457 * @since bbPress (r2625)
458 *
459 * @param int $forum_id Optional. Forum id
460 * @uses bbp_get_forum_freshness_link() To get the forum freshness link
461 */
462 function bbp_forum_freshness_link( $forum_id = 0) {
463 echo bbp_get_forum_freshness_link( $forum_id );
464 }
465 /**
466 * Returns link to the most recent activity inside a forum.
467 *
468 * Returns a complete link with attributes and content.
469 *
470 * @since bbPress (r2625)
471 *
472 * @param int $forum_id Optional. Forum id
473 * @uses bbp_get_forum_id() To get the forum id
474 * @uses bbp_get_forum_last_active_id() To get the forum last active id
475 * @uses bbp_get_forum_last_reply_id() To get the forum last reply id
476 * @uses bbp_get_forum_last_topic_id() To get the forum last topic id
477 * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
478 * @uses bbp_get_forum_last_reply_title() To get the forum last reply
479 * title
480 * @uses bbp_get_forum_last_topic_permalink() To get the forum last
481 * topic permalink
482 * @uses bbp_get_forum_last_topic_title() To get the forum last topic
483 * title
484 * @uses bbp_get_forum_last_active_time() To get the time when the forum
485 * was last active
486 * @uses apply_filters() Calls 'bbp_get_forum_freshness_link' with the
487 * link and forum id
488 */
489 function bbp_get_forum_freshness_link( $forum_id = 0 ) {
490 $forum_id = bbp_get_forum_id( $forum_id );
491 $active_id = bbp_get_forum_last_active_id( $forum_id );
492
493 if ( empty( $active_id ) )
494 $active_id = bbp_get_forum_last_reply_id( $forum_id );
495
496 if ( empty( $active_id ) )
497 $active_id = bbp_get_forum_last_topic_id( $forum_id );
498
499 if ( bbp_is_topic( $active_id ) ) {
500 $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
501 $title = bbp_get_forum_last_topic_title( $forum_id );
502 } elseif ( bbp_is_reply( $active_id ) ) {
503 $link_url = bbp_get_forum_last_reply_url( $forum_id );
504 $title = bbp_get_forum_last_reply_title( $forum_id );
505 }
506
507 $time_since = bbp_get_forum_last_active_time( $forum_id );
508
509 if ( !empty( $time_since ) && !empty( $link_url ) )
510 $anchor = '<a href="' . $link_url . '" title="' . esc_attr( $title ) . '">' . $time_since . '</a>';
511 else
512 $anchor = __( 'No Topics', 'bbpress' );
513
514 return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id );
515 }
516
517 /**
518 * Return ID of forum parent, if exists
519 *
520 * @since bbPress (r2625)
521 *
522 * @param int $forum_id Optional. Forum id
523 * @uses bbp_get_forum_id() To get the forum id
524 * @uses get_post_field() To get the forum parent
525 * @uses apply_filters() Calls 'bbp_get_forum_parent' with the parent & forum id
526 * @return int Forum parent
527 */
528 function bbp_get_forum_parent( $forum_id = 0 ) {
529 $forum_id = bbp_get_forum_id( $forum_id );
530 $parent_id = get_post_field( 'post_parent', $forum_id );
531
532 return apply_filters( 'bbp_get_forum_parent', (int) $parent_id, $forum_id );
533 }
534
535 /**
536 * Return array of parent forums
537 *
538 * @since bbPress (r2625)
539 *
540 * @param int $forum_id Optional. Forum id
541 * @uses bbp_get_forum_id() To get the forum id
542 * @uses bbp_get_forum() To get the forum
543 * @uses apply_filters() Calls 'bbp_get_forum_ancestors' with the ancestors
544 * and forum id
545 * @return array Forum ancestors
546 */
547 function bbp_get_forum_ancestors( $forum_id = 0 ) {
548 $forum_id = bbp_get_forum_id( $forum_id );
549 $ancestors = array();
550
551 if ( $forum = bbp_get_forum( $forum_id ) ) {
552 while ( 0 !== $forum->post_parent ) {
553 $ancestors[] = $forum->post_parent;
554 $forum = bbp_get_forum( $forum->post_parent );
555 }
556 }
557
558 return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id );
559 }
560
561 /**
562 * Return subforums of given forum
563 *
564 * @since bbPress (r2747)
565 *
566 * @param mixed $args All the arguments supported by {@link WP_Query}
567 * @uses bbp_get_forum_id() To get the forum id
568 * @uses current_user_can() To check if the current user is capable of
569 * reading private forums
570 * @uses get_posts() To get the subforums
571 * @uses apply_filters() Calls 'bbp_forum_get_subforums' with the subforums
572 * and the args
573 * @return mixed false if none, array of subs if yes
574 */
575 function bbp_forum_get_subforums( $args = '' ) {
576
577 // Use passed integer as post_parent
578 if ( is_numeric( $args ) )
579 $args = array( 'post_parent' => $args );
580
581 // Setup possible post__not_in array
582 $post_stati[] = 'publish';
583
584 // Super admin get whitelisted post statuses
585 if ( is_super_admin() ) {
586 $post_stati = array( 'publish', 'private', 'hidden' );
587
588 // Not a super admin, so check caps
589 } else {
590
591 // Check if user can read private forums
592 if ( current_user_can( 'read_private_forums' ) )
593 $post_stati[] = 'private';
594
595 // Check if user can read hidden forums
596 if ( current_user_can( 'read_hidden_forums' ) )
597 $post_stati[] = 'hidden';
598 }
599
600 $default = array(
601 'post_parent' => 0,
602 'post_type' => bbp_get_forum_post_type(),
603 'post_status' => implode( ',', $post_stati ),
604 'posts_per_page' => get_option( '_bbp_forums_per_page', 15 ),
605 'sort_column' => 'menu_order, post_title',
606 'order' => 'ASC'
607 );
608
609 $r = wp_parse_args( $args, $default );
610 $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
611
612 // No forum passed
613 $sub_forums = !empty( $r['post_parent'] ) ? get_posts( $r ) : '';
614
615 return apply_filters( 'bbp_forum_get_sub_forums', (array) $sub_forums, $args );
616 }
617
618 /**
619 * Output a list of forums (can be used to list subforums)
620 *
621 * @param mixed $args The function supports these args:
622 * - before: To put before the output. Defaults to '<ul class="bbp-forums">'
623 * - after: To put after the output. Defaults to '</ul>'
624 * - link_before: To put before every link. Defaults to '<li class="bbp-forum">'
625 * - link_after: To put after every link. Defaults to '</li>'
626 * - separator: Separator. Defaults to ', '
627 * - forum_id: Forum id. Defaults to ''
628 * - show_topic_count - To show forum topic count or not. Defaults to true
629 * - show_reply_count - To show forum reply count or not. Defaults to true
630 * @uses bbp_forum_get_subforums() To check if the forum has subforums or not
631 * @uses bbp_get_forum_permalink() To get forum permalink
632 * @uses bbp_get_forum_title() To get forum title
633 * @uses bbp_is_forum_category() To check if a forum is a category
634 * @uses bbp_get_forum_topic_count() To get forum topic count
635 * @uses bbp_get_forum_reply_count() To get forum reply count
636 */
637 function bbp_list_forums( $args = '' ) {
638 global $bbp;
639
640 // Define used variables
641 $output = $sub_forums = $topic_count = $reply_count = $counts = '';
642 $i = 0;
643 $count = array();
644
645 // Defaults and arguments
646 $defaults = array (
647 'before' => '<ul class="bbp-forums">',
648 'after' => '</ul>',
649 'link_before' => '<li class="bbp-forum">',
650 'link_after' => '</li>',
651 'count_before' => ' (',
652 'count_after' => ')',
653 'count_sep' => ', ',
654 'separator' => ', ',
655 'forum_id' => '',
656 'show_topic_count' => true,
657 'show_reply_count' => true,
658 );
659 $r = wp_parse_args( $args, $defaults );
660 extract( $r, EXTR_SKIP );
661
662 // Bail if there are no subforums
663 if ( !bbp_get_forum_subforum_count( $forum_id ) )
664 return;
665
666 // Loop through forums and create a list
667 if ( $sub_forums = bbp_forum_get_subforums( $forum_id ) ) {
668
669 // Total count (for separator)
670 $total_subs = count( $sub_forums );
671 foreach ( $sub_forums as $sub_forum ) {
672 $i++; // Separator count
673
674 // Get forum details
675 $count = array();
676 $show_sep = $total_subs > $i ? $separator : '';
677 $permalink = bbp_get_forum_permalink( $sub_forum->ID );
678 $title = bbp_get_forum_title( $sub_forum->ID );
679
680 // Show topic count
681 if ( !empty( $show_topic_count ) && !bbp_is_forum_category( $sub_forum->ID ) )
682 $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
683
684 // Show reply count
685 if ( !empty( $show_reply_count ) && !bbp_is_forum_category( $sub_forum->ID ) )
686 $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
687
688 // Counts to show
689 if ( !empty( $count ) )
690 $counts = $count_before . implode( $count_sep, $count ) . $count_after;
691
692 // Build this sub forums link
693 $output .= $link_before . '<a href="' . $permalink . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $link_after;
694 }
695
696 // Output the list
697 echo $before . $output . $after;
698 }
699 }
700
701 /** Forum Last Topic **********************************************************/
702
703 /**
704 * Output the forum's last topic id
705 *
706 * @since bbPress (r2464)
707 *
708 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
709 * @param int $forum_id Optional. Forum id
710 */
711 function bbp_forum_last_topic_id( $forum_id = 0 ) {
712 echo bbp_get_forum_last_topic_id( $forum_id );
713 }
714 /**
715 * Return the forum's last topic id
716 *
717 * @since bbPress (r2464)
718 *
719 * @param int $forum_id Optional. Forum id
720 * @uses bbp_get_forum_id() To get the forum id
721 * @uses get_post_meta() To get the forum's last topic id
722 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_id' with the
723 * forum and topic id
724 * @return int Forum's last topic id
725 */
726 function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
727 $forum_id = bbp_get_forum_id( $forum_id );
728 $topic_id = get_post_meta( $forum_id, '_bbp_last_topic_id', true );
729
730 return apply_filters( 'bbp_get_forum_last_topic_id', (int) $topic_id, $forum_id );
731 }
732
733 /**
734 * Output the title of the last topic inside a forum
735 *
736 * @since bbPress (r2625)
737 *
738 * @param int $forum_id Optional. Forum id
739 * @uses bbp_get_forum_last_topic_title() To get the forum's last topic's title
740 */
741 function bbp_forum_last_topic_title( $forum_id = 0 ) {
742 echo bbp_get_forum_last_topic_title( $forum_id );
743 }
744 /**
745 * Return the title of the last topic inside a forum
746 *
747 * @since bbPress (r2625)
748 *
749 * @param int $forum_id Optional. Forum id
750 * @uses bbp_get_forum_id() To get the forum id
751 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
752 * @uses bbp_get_topic_title() To get the topic's title
753 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_title' with the
754 * topic title and forum id
755 * @return string Forum's last topic's title
756 */
757 function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
758 $forum_id = bbp_get_forum_id( $forum_id );
759 return apply_filters( 'bbp_get_forum_last_topic_title', bbp_get_topic_title( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
760 }
761
762 /**
763 * Output the link to the last topic in a forum
764 *
765 * @since bbPress (r2464)
766 *
767 * @param int $forum_id Optional. Forum id
768 * @uses bbp_get_forum_last_topic_permalink() To get the forum's last topic's
769 * permanent link
770 */
771 function bbp_forum_last_topic_permalink( $forum_id = 0 ) {
772 echo bbp_get_forum_last_topic_permalink( $forum_id );
773 }
774 /**
775 * Return the link to the last topic in a forum
776 *
777 * @since bbPress (r2464)
778 *
779 * @param int $forum_id Optional. Forum id
780 * @uses bbp_get_forum_id() To get the forum id
781 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
782 * @uses bbp_get_topic_permalink() To get the topic's permalink
783 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_permalink' with
784 * the topic link and forum id
785 * @return string Permanent link to topic
786 */
787 function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
788 $forum_id = bbp_get_forum_id( $forum_id );
789 return apply_filters( 'bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink( bbp_get_forum_last_topic_id( $forum_id ) ), $forum_id );
790 }
791
792 /**
793 * Return the author ID of the last topic of a forum
794 *
795 * @since bbPress (r2625)
796 *
797 * @param int $forum_id Optional. Forum id
798 * @uses bbp_get_forum_id() To get the forum id
799 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
800 * @uses bbp_get_topic_author_id() To get the topic's author id
801 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author' with the author
802 * id and forum id
803 * @return int Forum's last topic's author id
804 */
805 function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
806 $forum_id = bbp_get_forum_id( $forum_id );
807 $author_id = bbp_get_topic_author_id( bbp_get_forum_last_topic_id( $forum_id ) );
808 return apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id );
809 }
810
811 /**
812 * Output link to author of last topic of forum
813 *
814 * @since bbPress (r2625)
815 *
816 * @param int $forum_id Optional. Forum id
817 * @uses bbp_get_forum_last_topic_author_link() To get the forum's last topic's
818 * author link
819 */
820 function bbp_forum_last_topic_author_link( $forum_id = 0 ) {
821 echo bbp_get_forum_last_topic_author_link( $forum_id );
822 }
823 /**
824 * Return link to author of last topic of forum
825 *
826 * @since bbPress (r2625)
827 *
828 * @param int $forum_id Optional. Forum id
829 * @uses bbp_get_forum_id() To get the forum id
830 * @uses bbp_get_forum_last_topic_author_id() To get the forum's last
831 * topic's author id
832 * @uses bbp_get_user_profile_link() To get the author's profile link
833 * @uses apply_filters() Calls 'bbp_get_forum_last_topic_author_link'
834 * with the author link and forum id
835 * @return string Forum's last topic's author link
836 */
837 function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
838 $forum_id = bbp_get_forum_id( $forum_id );
839 $author_id = bbp_get_forum_last_topic_author_id( $forum_id );
840 $author_link = bbp_get_user_profile_link( $author_id );
841 return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
842 }
843
844 /** Forum Last Reply **********************************************************/
845
846 /**
847 * Output the forums last reply id
848 *
849 * @since bbPress (r2464)
850 *
851 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
852 * @param int $forum_id Optional. Forum id
853 */
854 function bbp_forum_last_reply_id( $forum_id = 0 ) {
855 echo bbp_get_forum_last_reply_id( $forum_id );
856 }
857 /**
858 * Return the forums last reply id
859 *
860 * @since bbPress (r2464)
861 *
862 * @param int $forum_id Optional. Forum id
863 * @uses bbp_get_forum_id() To get the forum id
864 * @uses get_post_meta() To get the forum's last reply id
865 * @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
866 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_id' with
867 * the last reply id and forum id
868 * @return int Forum's last reply id
869 */
870 function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
871 $forum_id = bbp_get_forum_id( $forum_id );
872 $reply_id = get_post_meta( $forum_id, '_bbp_last_reply_id', true );
873
874 if ( empty( $reply_id ) )
875 $reply_id = bbp_get_forum_last_topic_id( $forum_id );
876
877 return apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
878 }
879
880 /**
881 * Output the title of the last reply inside a forum
882 *
883 * @param int $forum_id Optional. Forum id
884 * @uses bbp_get_forum_last_reply_title() To get the forum's last reply's title
885 */
886 function bbp_forum_last_reply_title( $forum_id = 0 ) {
887 echo bbp_get_forum_last_reply_title( $forum_id );
888 }
889 /**
890 * Return the title of the last reply inside a forum
891 *
892 * @param int $forum_id Optional. Forum id
893 * @uses bbp_get_forum_id() To get the forum id
894 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
895 * @uses bbp_get_reply_title() To get the reply title
896 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_title' with the
897 * reply title and forum id
898 * @return string
899 */
900 function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
901 $forum_id = bbp_get_forum_id( $forum_id );
902 return apply_filters( 'bbp_get_forum_last_reply_title', bbp_get_reply_title( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
903 }
904
905 /**
906 * Output the link to the last reply in a forum
907 *
908 * @since bbPress (r2464)
909 *
910 * @param int $forum_id Optional. Forum id
911 * @uses bbp_get_forum_last_reply_permalink() To get the forum last reply link
912 */
913 function bbp_forum_last_reply_permalink( $forum_id = 0 ) {
914 echo bbp_get_forum_last_reply_permalink( $forum_id );
915 }
916 /**
917 * Return the link to the last reply in a forum
918 *
919 * @since bbPress (r2464)
920 *
921 * @param int $forum_id Optional. Forum id
922 * @uses bbp_get_forum_id() To get the forum id
923 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
924 * @uses bbp_get_reply_permalink() To get the reply permalink
925 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_permalink' with
926 * the reply link and forum id
927 * @return string Permanent link to the forum's last reply
928 */
929 function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
930 $forum_id = bbp_get_forum_id( $forum_id );
931 return apply_filters( 'bbp_get_forum_last_reply_permalink', bbp_get_reply_permalink( bbp_get_forum_last_reply_id( $forum_id ) ), $forum_id );
932 }
933
934 /**
935 * Output the url to the last reply in a forum
936 *
937 * @since bbPress (r2683)
938 *
939 * @param int $forum_id Optional. Forum id
940 * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
941 */
942 function bbp_forum_last_reply_url( $forum_id = 0 ) {
943 echo bbp_get_forum_last_reply_url( $forum_id );
944 }
945 /**
946 * Return the url to the last reply in a forum
947 *
948 * @since bbPress (r2683)
949 *
950 * @param int $forum_id Optional. Forum id
951 * @uses bbp_get_forum_id() To get the forum id
952 * @uses bbp_get_forum_last_reply_id() To get the forum's last reply id
953 * @uses bbp_get_reply_url() To get the reply url
954 * @uses bbp_get_forum_last_topic_permalink() To get the forum's last
955 * topic's permalink
956 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_url' with the
957 * reply url and forum id
958 * @return string Paginated URL to latest reply
959 */
960 function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
961 $forum_id = bbp_get_forum_id( $forum_id );
962
963 // If forum has replies, get the last reply and use its url
964 if ( $reply_id = bbp_get_forum_last_reply_id( $forum_id ) ) {
965 $reply_url = bbp_get_reply_url( $reply_id );
966
967 // No replies, so look for topics and use last permalink
968 } else {
969 if ( !$reply_url = bbp_get_forum_last_topic_permalink( $forum_id ) ) {
970 // No topics either, so set $reply_url as empty
971 $reply_url = '';
972 }
973 }
974
975 // Filter and return
976 return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id );
977 }
978
979 /**
980 * Output author ID of last reply of forum
981 *
982 * @since bbPress (r2625)
983 *
984 * @param int $forum_id Optional. Forum id
985 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last reply
986 * author id
987 */
988 function bbp_forum_last_reply_author_id( $forum_id = 0 ) {
989 echo bbp_get_forum_last_reply_author_id( $forum_id );
990 }
991 /**
992 * Return author ID of last reply of forum
993 *
994 * @since bbPress (r2625)
995 *
996 * @param int $forum_id Optional. Forum id
997 * @uses bbp_get_forum_id() To get the forum id
998 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
999 * reply's author id
1000 * @uses bbp_get_reply_author_id() To get the reply's author id
1001 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_id' with
1002 * the author id and forum id
1003 * @return int Forum's last reply author id
1004 */
1005 function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
1006 $forum_id = bbp_get_forum_id( $forum_id );
1007 $author_id = bbp_get_reply_author_id( bbp_get_forum_last_reply_id( $forum_id ) );
1008 return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id );
1009 }
1010
1011 /**
1012 * Output link to author of last reply of forum
1013 *
1014 * @since bbPress (r2625)
1015 *
1016 * @param int $forum_id Optional. Forum id
1017 * @uses bbp_get_forum_last_reply_author_link() To get the forum's last reply's
1018 * author link
1019 */
1020 function bbp_forum_last_reply_author_link( $forum_id = 0 ) {
1021 echo bbp_get_forum_last_reply_author_link( $forum_id );
1022 }
1023 /**
1024 * Return link to author of last reply of forum
1025 *
1026 * @since bbPress (r2625)
1027 *
1028 * @param int $forum_id Optional. Forum id
1029 * @uses bbp_get_forum_id() To get the forum id
1030 * @uses bbp_get_forum_last_reply_author_id() To get the forum's last
1031 * reply's author id
1032 * @uses bbp_get_user_profile_link() To get the reply's author's profile
1033 * link
1034 * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_link'
1035 * with the author link and forum id
1036 * @return string Link to author of last reply of forum
1037 */
1038 function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
1039 $forum_id = bbp_get_forum_id( $forum_id );
1040 $author_id = bbp_get_forum_last_reply_author_id( $forum_id );
1041 $author_link = bbp_get_user_profile_link( $author_id );
1042 return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id );
1043 }
1044
1045 /** Forum Counts **************************************************************/
1046
1047 /**
1048 * Output the topics link of the forum
1049 *
1050 * @since bbPress (r2883)
1051 *
1052 * @param int $forum_id Optional. Topic id
1053 * @uses bbp_get_forum_topics_link() To get the forum topics link
1054 */
1055 function bbp_forum_topics_link( $forum_id = 0 ) {
1056 echo bbp_get_forum_topics_link( $forum_id );
1057 }
1058
1059 /**
1060 * Return the topics link of the forum
1061 *
1062 * @since bbPress (r2883)
1063 *
1064 * @param int $forum_id Optional. Topic id
1065 * @uses bbp_get_forum_id() To get the forum id
1066 * @uses bbp_get_forum() To get the forum
1067 * @uses bbp_get_forum_topic_count() To get the forum topic count
1068 * @uses bbp_get_forum_permalink() To get the forum permalink
1069 * @uses remove_query_arg() To remove args from the url
1070 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden
1071 * topic count
1072 * @uses current_user_can() To check if the current user can edit others
1073 * topics
1074 * @uses add_query_arg() To add custom args to the url
1075 * @uses apply_filters() Calls 'bbp_get_forum_topics_link' with the
1076 * topics link and forum id
1077 */
1078 function bbp_get_forum_topics_link( $forum_id = 0 ) {
1079 global $bbp;
1080
1081 $forum = bbp_get_forum( bbp_get_forum_id( (int) $forum_id ) );
1082 $forum_id = $forum->ID;
1083 $topics = bbp_get_forum_topic_count( $forum_id );
1084 $topics = sprintf( _n( '%s topic', '%s topics', $topics, 'bbpress' ), $topics );
1085 $retval = '';
1086
1087 // First link never has view=all
1088 if ( bbp_get_view_all( 'edit_others_topics' ) )
1089 $retval .= "<a href='" . esc_url( bbp_remove_view_all( bbp_get_forum_permalink( $forum_id ) ) ) . "'>$topics</a>";
1090 else
1091 $retval .= $topics;
1092
1093 // This forum has hidden topics
1094 if ( current_user_can( 'edit_others_topics' ) && ( $deleted = bbp_get_forum_topic_count_hidden( $forum_id ) ) ) {
1095
1096 // Extra text
1097 $extra = sprintf( __( ' (+ %d hidden)', 'bbpress' ), $deleted );
1098
1099 // No link
1100 if ( bbp_get_view_all() )
1101 $retval .= " $extra";
1102
1103 // Link
1104 else
1105 $retval .= " <a href='" . esc_url( bbp_add_view_all( bbp_get_forum_permalink( $forum_id ), true ) ) . "'>$extra</a>";
1106 }
1107
1108 return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
1109 }
1110
1111 /**
1112 * Output total sub-forum count of a forum
1113 *
1114 * @since bbPress (r2464)
1115 *
1116 * @uses bbp_get_forum_subforum_count() To get the forum's subforum count
1117 * @param int $forum_id Optional. Forum id to check
1118 */
1119 function bbp_forum_subforum_count( $forum_id = 0 ) {
1120 echo bbp_get_forum_subforum_count( $forum_id );
1121 }
1122 /**
1123 * Return total subforum count of a forum
1124 *
1125 * @since bbPress (r2464)
1126 *
1127 * @param int $forum_id Optional. Forum id
1128 * @uses bbp_get_forum_id() To get the forum id
1129 * @uses get_post_meta() To get the subforum count
1130 * @uses apply_filters() Calls 'bbp_get_forum_subforum_count' with the
1131 * subforum count and forum id
1132 * @return int Forum's subforum count
1133 */
1134 function bbp_get_forum_subforum_count( $forum_id = 0 ) {
1135 $forum_id = bbp_get_forum_id( $forum_id );
1136 $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
1137
1138 return apply_filters( 'bbp_get_forum_subforum_count', (int) $forum_count, $forum_id );
1139 }
1140
1141 /**
1142 * Output total topic count of a forum
1143 *
1144 * @since bbPress (r2464)
1145 *
1146 * @param int $forum_id Optional. Forum id
1147 * @param bool $total_count Optional. To get the total count or normal count?
1148 * @uses bbp_get_forum_topic_count() To get the forum topic count
1149 */
1150 function bbp_forum_topic_count( $forum_id = 0, $total_count = true ) {
1151 echo bbp_get_forum_topic_count( $forum_id );
1152 }
1153 /**
1154 * Return total topic count of a forum
1155 *
1156 * @since bbPress (r2464)
1157 *
1158 * @param int $forum_id Optional. Forum id
1159 * @param bool $total_count Optional. To get the total count or normal
1160 * count? Defaults to total.
1161 * @uses bbp_get_forum_id() To get the forum id
1162 * @uses get_post_meta() To get the forum topic count
1163 * @uses apply_filters() Calls 'bbp_get_forum_topic_count' with the
1164 * topic count and forum id
1165 * @return int Forum topic count
1166 */
1167 function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true ) {
1168 $forum_id = bbp_get_forum_id( $forum_id );
1169 $topics = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count', true );
1170
1171 return apply_filters( 'bbp_get_forum_topic_count', (int) $topics, $forum_id );
1172 }
1173
1174 /**
1175 * Output total reply count of a forum
1176 *
1177 * @since bbPress (r2464)
1178 *
1179 * @param int $forum_id Optional. Forum id
1180 * @param bool $total_count Optional. To get the total count or normal count?
1181 * @uses bbp_get_forum_reply_count() To get the forum reply count
1182 */
1183 function bbp_forum_reply_count( $forum_id = 0, $total_count = true ) {
1184 echo bbp_get_forum_reply_count( $forum_id, $total_count );
1185 }
1186 /**
1187 * Return total post count of a forum
1188 *
1189 * @since bbPress (r2464)
1190 *
1191 * @param int $forum_id Optional. Forum id
1192 * @param bool $total_count Optional. To get the total count or normal
1193 * count?
1194 * @uses bbp_get_forum_id() To get the forum id
1195 * @uses get_post_meta() To get the forum reply count
1196 * @uses apply_filters() Calls 'bbp_get_forum_reply_count' with the
1197 * reply count and forum id
1198 * @return int Forum reply count
1199 */
1200 function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true ) {
1201 $forum_id = bbp_get_forum_id( $forum_id );
1202 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true );
1203
1204 return apply_filters( 'bbp_get_forum_reply_count', (int) $replies, $forum_id );
1205 }
1206
1207 /**
1208 * Output total post count of a forum
1209 *
1210 * @since bbPress (r2954)
1211 *
1212 * @param int $forum_id Optional. Forum id
1213 * @param bool $total_count Optional. To get the total count or normal count?
1214 * @uses bbp_get_forum_post_count() To get the forum post count
1215 */
1216 function bbp_forum_post_count( $forum_id = 0, $total_count = true ) {
1217 echo bbp_get_forum_post_count( $forum_id, $total_count );
1218 }
1219 /**
1220 * Return total post count of a forum
1221 *
1222 * @since bbPress (r2954)
1223 *
1224 * @param int $forum_id Optional. Forum id
1225 * @param bool $total_count Optional. To get the total count or normal
1226 * count?
1227 * @uses bbp_get_forum_id() To get the forum id
1228 * @uses get_post_meta() To get the forum post count
1229 * @uses apply_filters() Calls 'bbp_get_forum_post_count' with the
1230 * post count and forum id
1231 * @return int Forum post count
1232 */
1233 function bbp_get_forum_post_count( $forum_id = 0, $total_count = true ) {
1234 $forum_id = bbp_get_forum_id( $forum_id );
1235 $topics = bbp_get_forum_topic_count( $forum_id, $total_count );
1236 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true );
1237
1238 return apply_filters( 'bbp_get_forum_post_count', (int) $replies + (int) $topics, $forum_id );
1239 }
1240
1241 /**
1242 * Output total hidden topic count of a forum (hidden includes trashed and
1243 * spammed topics)
1244 *
1245 * @since bbPress (r2883)
1246 *
1247 * @param int $forum_id Optional. Topic id
1248 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count
1249 */
1250 function bbp_forum_topic_count_hidden( $forum_id = 0 ) {
1251 echo bbp_get_forum_topic_count_hidden( $forum_id );
1252 }
1253 /**
1254 * Return total hidden topic count of a forum (hidden includes trashed
1255 * and spammed topics)
1256 *
1257 * @since bbPress (r2883)
1258 *
1259 * @param int $forum_id Optional. Topic id
1260 * @uses bbp_get_forum_id() To get the forum id
1261 * @uses get_post_meta() To get the hidden topic count
1262 * @uses apply_filters() Calls 'bbp_get_forum_topic_count_hidden' with
1263 * the hidden topic count and forum id
1264 * @return int Topic hidden topic count
1265 */
1266 function bbp_get_forum_topic_count_hidden( $forum_id = 0 ) {
1267 $forum_id = bbp_get_forum_id( $forum_id );
1268 $topics = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true );
1269
1270 return apply_filters( 'bbp_get_forum_topic_count_hidden', (int) $topics, $forum_id );
1271 }
1272
1273 /**
1274 * Output the status of the forum
1275 *
1276 * @since bbPress (r2667)
1277 *
1278 * @param int $forum_id Optional. Forum id
1279 * @uses bbp_get_forum_status() To get the forum status
1280 */
1281 function bbp_forum_status( $forum_id = 0 ) {
1282 echo bbp_get_forum_status( $forum_id );
1283 }
1284 /**
1285 * Return the status of the forum
1286 *
1287 * @since bbPress (r2667)
1288 *
1289 * @param int $forum_id Optional. Forum id
1290 * @uses bbp_get_forum_id() To get the forum id
1291 * @uses get_post_status() To get the forum's status
1292 * @uses apply_filters() Calls 'bbp_get_forum_status' with the status
1293 * and forum id
1294 * @return string Status of forum
1295 */
1296 function bbp_get_forum_status( $forum_id = 0 ) {
1297 $forum_id = bbp_get_forum_id( $forum_id );
1298
1299 return apply_filters( 'bbp_get_forum_status', get_post_meta( $forum_id, '_bbp_status', true ), $forum_id );
1300 }
1301
1302 /**
1303 * Output the visibility of the forum
1304 *
1305 * @since bbPress (r2997)
1306 *
1307 * @param int $forum_id Optional. Forum id
1308 * @uses bbp_get_forum_visibility() To get the forum visibility
1309 */
1310 function bbp_forum_visibility( $forum_id = 0 ) {
1311 echo bbp_get_forum_visibility( $forum_id );
1312 }
1313 /**
1314 * Return the visibility of the forum
1315 *
1316 * @since bbPress (r2997)
1317 *
1318 * @param int $forum_id Optional. Forum id
1319 * @uses bbp_get_forum_id() To get the forum id
1320 * @uses get_post_visibility() To get the forum's visibility
1321 * @uses apply_filters() Calls 'bbp_get_forum_visibility' with the visibility
1322 * and forum id
1323 * @return string Status of forum
1324 */
1325 function bbp_get_forum_visibility( $forum_id = 0 ) {
1326 $forum_id = bbp_get_forum_id( $forum_id );
1327
1328 return apply_filters( 'bbp_get_forum_visibility', get_post_status( $forum_id ), $forum_id );
1329 }
1330
1331 /**
1332 * Is the forum a category?
1333 *
1334 * @since bbPress (r2746)
1335 *
1336 * @param int $forum_id Optional. Forum id
1337 * @uses get_post_meta() To get the forum category meta
1338 * @return bool Whether the forum is a category or not
1339 */
1340 function bbp_is_forum_category( $forum_id = 0 ) {
1341 $forum_id = bbp_get_forum_id( $forum_id );
1342 $type = get_post_meta( $forum_id, '_bbp_forum_type', true );
1343 $retval = ( !empty( $type ) && 'category' == $type );
1344
1345 return apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id );
1346 }
1347
1348 /**
1349 * Is the forum open?
1350 *
1351 * @since bbPress (r2746)
1352 * @param int $forum_id Optional. Forum id
1353 *
1354 * @param int $forum_id Optional. Forum id
1355 * @uses bbp_is_forum_closed() To check if the forum is closed or not
1356 * @return bool Whether the forum is open or not
1357 */
1358 function bbp_is_forum_open( $forum_id = 0 ) {
1359 return !bbp_is_forum_closed( $forum_id );
1360 }
1361
1362 /**
1363 * Is the forum closed?
1364 *
1365 * @since bbPress (r2746)
1366 *
1367 * @param int $forum_id Optional. Forum id
1368 * @param bool $check_ancestors Check if the ancestors are closed (only
1369 * if they're a category)
1370 * @uses bbp_get_forum_status() To get the forum status
1371 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1372 * @uses bbp_is_forum_category() To check if the forum is a category
1373 * @uses bbp_is_forum_closed() To check if the forum is closed
1374 * @return bool True if closed, false if not
1375 */
1376 function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
1377 global $bbp;
1378
1379 $forum_id = bbp_get_forum_id( $forum_id );
1380 $retval = ( $bbp->closed_status_id == bbp_get_forum_status( $forum_id ) );
1381
1382 if ( !empty( $check_ancestors ) ) {
1383 $ancestors = bbp_get_forum_ancestors( $forum_id );
1384
1385 foreach ( (array) $ancestors as $ancestor ) {
1386 if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) {
1387 $retval = true;
1388 }
1389 }
1390 }
1391
1392 return apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
1393 }
1394
1395 /**
1396 * Is the forum public?
1397 *
1398 * @since bbPress (r2997)
1399 *
1400 * @param int $forum_id Optional. Forum id
1401 * @param bool $check_ancestors Check if the ancestors are public (only if
1402 * they're a category)
1403 * @uses get_post_meta() To get the forum public meta
1404 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1405 * @uses bbp_is_forum_category() To check if the forum is a category
1406 * @uses bbp_is_forum_closed() To check if the forum is closed
1407 * @return bool True if closed, false if not
1408 */
1409 function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
1410 global $bbp;
1411
1412 $forum_id = bbp_get_forum_id( $forum_id );
1413 $visibility = bbp_get_forum_visibility( $forum_id );
1414
1415 // If post status is public, return true
1416 $retval = ( 'publish' == $visibility );
1417
1418 // Check ancestors and inherit their privacy setting for display
1419 if ( !empty( $check_ancestors ) ) {
1420 $ancestors = bbp_get_forum_ancestors( $forum_id );
1421
1422 foreach ( (array) $ancestors as $ancestor ) {
1423 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) {
1424 $retval = true;
1425 }
1426 }
1427 }
1428
1429 return apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors );
1430 }
1431
1432 /**
1433 * Is the forum private?
1434 *
1435 * @since bbPress (r2746)
1436 *
1437 * @param int $forum_id Optional. Forum id
1438 * @param bool $check_ancestors Check if the ancestors are private (only if
1439 * they're a category)
1440 * @uses get_post_meta() To get the forum private meta
1441 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1442 * @uses bbp_is_forum_category() To check if the forum is a category
1443 * @uses bbp_is_forum_closed() To check if the forum is closed
1444 * @return bool True if closed, false if not
1445 */
1446 function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
1447 global $bbp;
1448
1449 $forum_id = bbp_get_forum_id( $forum_id );
1450 $visibility = bbp_get_forum_visibility( $forum_id );
1451
1452 // If post status is private, return true
1453 $retval = ( 'private' == $visibility );
1454
1455 // Check ancestors and inherit their privacy setting for display
1456 if ( !empty( $check_ancestors ) ) {
1457 $ancestors = bbp_get_forum_ancestors( $forum_id );
1458
1459 foreach ( (array) $ancestors as $ancestor ) {
1460 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_private( $ancestor, false ) ) {
1461 $retval = true;
1462 }
1463 }
1464 }
1465
1466 return apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors );
1467 }
1468
1469 /**
1470 * Is the forum hidden?
1471 *
1472 * @since bbPress (r2997)
1473 *
1474 * @param int $forum_id Optional. Forum id
1475 * @param bool $check_ancestors Check if the ancestors are private (only if
1476 * they're a category)
1477 * @uses get_post_meta() To get the forum private meta
1478 * @uses bbp_get_forum_ancestors() To get the forum ancestors
1479 * @uses bbp_is_forum_category() To check if the forum is a category
1480 * @uses bbp_is_forum_closed() To check if the forum is closed
1481 * @return bool True if closed, false if not
1482 */
1483 function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
1484 global $bbp;
1485
1486 $forum_id = bbp_get_forum_id( $forum_id );
1487 $visibility = bbp_get_forum_visibility( $forum_id );
1488
1489 // If post status is private, return true
1490 $retval = ( 'hidden' == $visibility );
1491
1492 // Check ancestors and inherit their privacy setting for display
1493 if ( !empty( $check_ancestors ) ) {
1494 $ancestors = bbp_get_forum_ancestors( $forum_id );
1495
1496 foreach ( (array) $ancestors as $ancestor ) {
1497 if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) {
1498 $retval = true;
1499 }
1500 }
1501 }
1502
1503 return apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
1504 }
1505
1506 /**
1507 * Replace forum meta details for users that cannot view them.
1508 *
1509 * @since bbPress (r3162)
1510 *
1511 * @param string $retval
1512 * @param int $forum_id
1513 *
1514 * @uses bbp_is_forum_private()
1515 * @uses current_user_can()
1516 *
1517 * @return string
1518 */
1519 function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
1520 if ( bbp_is_forum_private( $forum_id, false ) && !current_user_can( 'read_private_forums' ) )
1521 $retval = '-';
1522
1523 return apply_filters( 'bbp_suppress_private_forum_meta', $retval );
1524 }
1525
1526 /**
1527 * Replace forum author details for users that cannot view them.
1528 *
1529 * @since bbPress (r3162)
1530 *
1531 * @param string $retval
1532 * @param int $forum_id
1533 *
1534 * @uses bbp_is_forum_private()
1535 * @uses get_post_field()
1536 * @uses bbp_get_topic_post_type()
1537 * @uses bbp_is_forum_private()
1538 * @uses bbp_get_topic_forum_id()
1539 * @uses bbp_get_reply_post_type()
1540 * @uses bbp_get_reply_forum_id()
1541 *
1542 * @return string
1543 */
1544 function bbp_suppress_private_author_link( $author_link, $args ) {
1545
1546 // Assume the author link is the return value
1547 $retval = $author_link;
1548
1549 // Show the normal author link
1550 if ( !empty( $args['post_id'] ) && !current_user_can( 'read_private_forums' ) ) {
1551
1552 // What post type are we looking at?
1553 $post_type = get_post_field( 'post_type', $args['post_id'] );
1554
1555 switch ( $post_type ) {
1556
1557 // Topic
1558 case bbp_get_topic_post_type() :
1559 if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) )
1560 $retval = '';
1561
1562 break;
1563
1564 // Reply
1565 case bbp_get_reply_post_type() :
1566 if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) )
1567 $retval = '';
1568
1569 break;
1570
1571 // Post
1572 default :
1573 if ( bbp_is_forum_private( $args['post_id'] ) )
1574 $retval = '';
1575
1576 break;
1577 }
1578 }
1579
1580 return apply_filters( 'bbp_suppress_private_author_link', $retval );
1581 }
1582
1583 /**
1584 * Output the row class of a forum
1585 *
1586 * @since bbPress (r2667)
1587 *
1588 * @uses bbp_get_forum_class() To get the row class of the forum
1589 */
1590 function bbp_forum_class() {
1591 echo bbp_get_forum_class();
1592 }
1593 /**
1594 * Return the row class of a forum
1595 *
1596 * @since bbPress (r2667)
1597 *
1598 * @uses post_class() To get all the classes including ours
1599 * @uses apply_filters() Calls 'bbp_get_forum_class' with the classes
1600 * @return string Row class of the forum
1601 */
1602 function bbp_get_forum_class() {
1603 global $bbp;
1604
1605 $classes = array();
1606 $classes[] = $bbp->forum_query->current_post % 2 ? 'even' : 'odd';
1607 $classes[] = bbp_is_forum_category() ? 'status-category' : '';
1608 $classes[] = bbp_is_forum_private() ? 'status-private' : '';
1609 $classes = array_filter( $classes );
1610
1611 $post = post_class( $classes );
1612
1613 return apply_filters( 'bbp_get_forum_class', $post );
1614 }
1615
1616 /** Single Forum **************************************************************/
1617
1618 /**
1619 * Output a fancy description of the current forum, including total topics,
1620 * total replies, and last activity.
1621 *
1622 * @since bbPress (r2860)
1623 *
1624 * @param array $args Arguments passed to alter output
1625 * @uses bbp_get_single_forum_description() Return the eventual output
1626 */
1627 function bbp_single_forum_description( $args = '' ) {
1628 echo bbp_get_single_forum_description( $args );
1629 }
1630 /**
1631 * Return a fancy description of the current forum, including total
1632 * topics, total replies, and last activity.
1633 *
1634 * @since bbPress (r2860)
1635 *
1636 * @param mixed $args This function supports these arguments:
1637 * - topic_id: Topic id
1638 * - before: Before the text
1639 * - after: After the text
1640 * - size: Size of the avatar
1641 * @uses bbp_get_forum_id() To get the forum id
1642 * @uses bbp_get_forum_topic_count() To get the forum topic count
1643 * @uses bbp_get_forum_reply_count() To get the forum reply count
1644 * @uses bbp_get_forum_subforum_count() To get the forum subforum count
1645 * @uses bbp_get_forum_freshness_link() To get the forum freshness link
1646 * @uses bbp_get_forum_last_active_id() To get the forum last active id
1647 * @uses bbp_get_author_link() To get the author link
1648 * @uses add_filter() To add the 'view all' filter back
1649 * @uses apply_filters() Calls 'bbp_get_single_forum_description' with
1650 * the description and args
1651 * @return string Filtered forum description
1652 */
1653 function bbp_get_single_forum_description( $args = '' ) {
1654 // Default arguments
1655 $defaults = array (
1656 'forum_id' => 0,
1657 'before' => '<div class="bbp-template-notice info"><p class="post-meta description">',
1658 'after' => '</p></div>',
1659 'size' => 14,
1660 'feed' => true
1661 );
1662 $r = wp_parse_args( $args, $defaults );
1663 extract( $r );
1664
1665 // Validate forum_id
1666 $forum_id = bbp_get_forum_id( $forum_id );
1667
1668 // Unhook the 'view all' query var adder
1669 remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1670
1671 // Build the forum description
1672 $topic_count = bbp_get_forum_topics_link ( $forum_id );
1673 $reply_count = bbp_get_forum_reply_count ( $forum_id );
1674 $subforum_count = bbp_get_forum_subforum_count( $forum_id );
1675 $time_since = bbp_get_forum_freshness_link( $forum_id );
1676
1677 // Singlular/Plural
1678 $reply_count = sprintf( _n( '%s reply', '%s replies', $reply_count, 'bbpress' ), $reply_count );
1679
1680 // Forum has posts
1681 if ( $last_reply = bbp_get_forum_last_active_id( $forum_id ) ) {
1682
1683 // Freshness author
1684 $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $size ) );
1685
1686 // Category
1687 if ( bbp_is_forum_category( $forum_id ) )
1688 $retstr = sprintf( __( 'This category contains %1$s and %2$s, and was last updated by %3$s %4$s ago.', 'bbpress' ), $topic_count, $reply_count, $last_updated_by, $time_since );
1689
1690 // Forum
1691 else
1692 $retstr = sprintf( __( 'This forum contains %1$s and %2$s, and was last updated by %3$s %4$s ago.', 'bbpress' ), $topic_count, $reply_count, $last_updated_by, $time_since );
1693
1694 // Forum has no last active data
1695 } else {
1696
1697 // Category
1698 if ( bbp_is_forum_category( $forum_id ) )
1699 $retstr = sprintf( __( 'This category contains %1$s and %2$s.', 'bbpress' ), $topic_count, $reply_count );
1700
1701 // Forum
1702 else
1703 $retstr = sprintf( __( 'This forum contains %1$s and %2$s.', 'bbpress' ), $topic_count, $reply_count );
1704 }
1705
1706 // Add feeds
1707 $feed_links = ( !empty( $feed ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : '';
1708
1709 // Add the 'view all' filter back
1710 add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1711
1712 // Combine the elements together
1713 $retstr = $before . $retstr . $after;
1714
1715 // Return filtered result
1716 return apply_filters( 'bbp_get_single_forum_description', $retstr, $args );
1717 }
1718
1719 /** Feeds *********************************************************************/
1720
1721 /**
1722 * Output the link for the forum feed
1723 *
1724 * @since bbPress (r3172)
1725 *
1726 * @param type $forum_id Optional. Forum ID.
1727 *
1728 * @uses bbp_get_forum_topics_feed_link()
1729 */
1730 function bbp_forum_topics_feed_link( $forum_id = 0 ) {
1731 echo bbp_get_forum_topics_feed_link( $forum_id );
1732 }
1733 /**
1734 * Retrieve the link for the forum feed
1735 *
1736 * @since bbPress (r3172)
1737 *
1738 * @param int $forum_id Optional. Forum ID.
1739 *
1740 * @uses bbp_get_forum_id()
1741 * @uses get_option()
1742 * @uses trailingslashit()
1743 * @uses bbp_get_forum_permalink()
1744 * @uses user_trailingslashit()
1745 * @uses bbp_get_forum_post_type()
1746 * @uses get_post_field()
1747 * @uses apply_filters()
1748 *
1749 * @return string
1750 */
1751 function bbp_get_forum_topics_feed_link( $forum_id = 0 ) {
1752
1753 // Validate forum id
1754 $forum_id = bbp_get_forum_id( $forum_id );
1755
1756 // Forum is valid
1757 if ( !empty( $forum_id ) ) {
1758
1759 // Define local variable(s)
1760 $link = '';
1761
1762 // Pretty permalinks
1763 if ( get_option( 'permalink_structure' ) ) {
1764
1765 // Forum link
1766 $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
1767 $url = user_trailingslashit( $url, 'single_feed' );
1768
1769 // Unpretty permalinks
1770 } else {
1771 $url = home_url( add_query_arg( array(
1772 'feed' => 'rss2',
1773 bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
1774 ) ) );
1775 }
1776
1777 $link = '<a href="' . $url . '" class="bbp-forum-rss-link topics"><span>' . __( 'Topics', 'bbpress' ) . '</span></a>';
1778 }
1779
1780 return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id );
1781 }
1782
1783 /**
1784 * Output the link for the forum replies feed
1785 *
1786 * @since bbPress (r3172)
1787 *
1788 * @param type $forum_id Optional. Forum ID.
1789 *
1790 * @uses bbp_get_forum_replies_feed_link()
1791 */
1792 function bbp_forum_replies_feed_link( $forum_id = 0 ) {
1793 echo bbp_get_forum_replies_feed_link( $forum_id );
1794 }
1795 /**
1796 * Retrieve the link for the forum replies feed
1797 *
1798 * @since bbPress (r3172)
1799 *
1800 * @param int $forum_id Optional. Forum ID.
1801 *
1802 * @uses bbp_get_forum_id()
1803 * @uses get_option()
1804 * @uses trailingslashit()
1805 * @uses bbp_get_forum_permalink()
1806 * @uses user_trailingslashit()
1807 * @uses bbp_get_forum_post_type()
1808 * @uses get_post_field()
1809 * @uses apply_filters()
1810 *
1811 * @return string
1812 */
1813 function bbp_get_forum_replies_feed_link( $forum_id = 0 ) {
1814
1815 // Validate forum id
1816 $forum_id = bbp_get_forum_id( $forum_id );
1817
1818 // Forum is valid
1819 if ( !empty( $forum_id ) ) {
1820
1821 // Define local variable(s)
1822 $link = '';
1823
1824 // Pretty permalinks
1825 if ( get_option( 'permalink_structure' ) ) {
1826
1827 // Forum link
1828 $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
1829 $url = user_trailingslashit( $url, 'single_feed' );
1830 $url = add_query_arg( array( 'type' => 'reply' ), $url );
1831
1832 // Unpretty permalinks
1833 } else {
1834 $url = home_url( add_query_arg( array(
1835 'type' => 'reply',
1836 'feed' => 'rss2',
1837 bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
1838 ) ) );
1839 }
1840
1841 $link = '<a href="' . $url . '" class="bbp-forum-rss-link replies"><span>' . __( 'Replies', 'bbpress' ) . '</span></a>';
1842 }
1843
1844 return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id );
1845 }
1846
1847 ?>
1848