PluginProbe
bbPress / 2.0-rc-5
bbPress v2.0-rc-5
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-common-template.php

bbp-common-template.php in bbPress 2.0-rc-5, at bbp-includes/bbp-common-template.php

1,885 lines 51.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 Common Template Tags
5 *
6 * @package bbPress
7 * @subpackage TemplateTags
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Add-on Actions ************************************************************/
14
15 /**
16 * Add our custom head action to wp_head
17 *
18 * @since bbPress (r2464)
19 *
20 * @uses do_action() Calls 'bbp_head'
21 */
22 function bbp_head() {
23 do_action( 'bbp_head' );
24 }
25
26 /**
27 * Add our custom head action to wp_head
28 *
29 * @since bbPress (r2464)
30 *
31 * @uses do_action() Calls 'bbp_footer'
32 */
33 function bbp_footer() {
34 do_action( 'bbp_footer' );
35 }
36
37 /** is_ ***********************************************************************/
38
39 /**
40 * Check if current site is public
41 *
42 * @since bbPress (r3398)
43 *
44 * @param int $site_id
45 * @uses get_current_blog_id()
46 * @uses get_blog_option()
47 * @uses apply_filters()
48 * @return bool True if site is public, false if private
49 */
50 function bbp_is_site_public( $site_id = 0 ) {
51
52 // Get the current site ID
53 if ( empty( $site_id ) )
54 $site_id = get_current_blog_id();
55
56 // Get the site visibility setting
57 $public = get_blog_option( $site_id, 'blog_public', 1 );
58
59 return (bool) apply_filters( 'bbp_is_site_public', $public, $site_id );
60 }
61
62 /**
63 * Check if current page is a bbPress forum
64 *
65 * @since bbPress (r2549)
66 *
67 * @param int $post_id Possible post_id to check
68 * @uses bbp_get_forum_post_type() To get the forum post type
69 * @return bool True if it's a forum page, false if not
70 */
71 function bbp_is_forum( $post_id = 0 ) {
72
73 // Assume false
74 $retval = false;
75
76 // Supplied ID is a forum
77 if ( !empty( $post_id ) && ( bbp_get_forum_post_type() == get_post_type( $post_id ) ))
78 $retval = true;
79
80 return (bool) apply_filters( 'bbp_is_forum', $retval, $post_id );
81 }
82
83 /**
84 * Check if we are viewing a forum archive.
85 *
86 * @since bbPress (r3251)
87 *
88 * @uses is_post_type_archive() To check if we are looking at the forum archive
89 * @uses bbp_get_forum_post_type() To get the forum post type ID
90 *
91 * @return bool
92 */
93 function bbp_is_forum_archive() {
94
95 // Default to false
96 $retval = false;
97
98 // In forum archive
99 if ( is_post_type_archive( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_forum_archive' ) )
100 $retval = true;
101
102 return (bool) apply_filters( 'bbp_is_forum_archive', $retval );
103 }
104
105 /**
106 * Viewing a single forum
107 *
108 * @since bbPress (r3338)
109 *
110 * @uses is_single()
111 * @uses bbp_get_forum_post_type()
112 * @uses get_post_type()
113 * @uses apply_filters()
114 *
115 * @return bool
116 */
117 function bbp_is_single_forum() {
118
119 // Assume false
120 $retval = false;
121
122 // Single and a match
123 if ( is_singular( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_single_forum' ) )
124 $retval = true;
125
126 return (bool) apply_filters( 'bbp_is_single_forum', $retval );
127 }
128
129 /**
130 * Check if current page is a bbPress topic
131 *
132 * @since bbPress (r2549)
133 *
134 * @param int $post_id Possible post_id to check
135 * @uses bbp_get_topic_post_type() To get the topic post type
136 * @uses get_post_type() To get the post type of the post id
137 * @return bool True if it's a topic page, false if not
138 */
139 function bbp_is_topic( $post_id = 0 ) {
140
141 // Assume false
142 $retval = false;
143
144 // Supplied ID is a topic
145 if ( !empty( $post_id ) && ( bbp_get_topic_post_type() == get_post_type( $post_id ) ) )
146 $retval = true;
147
148 return (bool) apply_filters( 'bbp_is_topic', $retval, $post_id );
149 }
150
151 /**
152 * Viewing a single topic
153 *
154 * @since bbPress (r3338)
155 *
156 * @uses is_single()
157 * @uses bbp_get_topic_post_type()
158 * @uses get_post_type()
159 * @uses apply_filters()
160 *
161 * @return bool
162 */
163 function bbp_is_single_topic() {
164
165 // Assume false
166 $retval = false;
167
168 // Single and a match
169 if ( is_singular( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_single_topic' ) )
170 $retval = true;
171
172 return (bool) apply_filters( 'bbp_is_single_topic', $retval );
173 }
174
175 /**
176 * Check if we are viewing a topic archive.
177 *
178 * @since bbPress (r3251)
179 *
180 * @uses is_post_type_archive() To check if we are looking at the topic archive
181 * @uses bbp_get_topic_post_type() To get the topic post type ID
182 *
183 * @return bool
184 */
185 function bbp_is_topic_archive() {
186
187 // Default to false
188 $retval = false;
189
190 // In topic archive
191 if ( is_post_type_archive( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_topic_archive' ) )
192 $retval = true;
193
194 return (bool) apply_filters( 'bbp_is_topic_archive', $retval );
195 }
196
197 /**
198 * Check if current page is a topic edit page
199 *
200 * @since bbPress (r2753)
201 *
202 * @uses WP_Query Checks if WP_Query::bbp_is_topic_edit is true
203 * @return bool True if it's the topic edit page, false if not
204 */
205 function bbp_is_topic_edit() {
206 global $wp_query;
207
208 if ( !empty( $wp_query->bbp_is_topic_edit ) && ( $wp_query->bbp_is_topic_edit == true ) )
209 return true;
210
211 return false;
212 }
213
214 /**
215 * Check if current page is a topic merge page
216 *
217 * @since bbPress (r2756)
218 *
219 * @uses bbp_is_topic_edit() To check if it's a topic edit page
220 * @return bool True if it's the topic merge page, false if not
221 */
222 function bbp_is_topic_merge() {
223
224 if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'merge' == $_GET['action'] ) )
225 return true;
226
227 return false;
228 }
229
230 /**
231 * Check if current page is a topic split page
232 *
233 * @since bbPress (r2756)
234 *
235 * @uses bbp_is_topic_edit() To check if it's a topic edit page
236 * @return bool True if it's the topic split page, false if not
237 */
238 function bbp_is_topic_split() {
239
240 if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'split' == $_GET['action'] ) )
241 return true;
242
243 return false;
244 }
245
246 /**
247 * Check if the current page is a topic tag
248 *
249 * @since bbPress (r3311)
250 *
251 * @global bbPress $bbp
252 * @return bool True if it's a topic tag, false if not
253 */
254 function bbp_is_topic_tag() {
255 global $bbp, $wp_query;
256
257 // Return false if editing a topic tag
258 if ( bbp_is_topic_tag_edit() )
259 return false;
260
261 if ( is_tax( bbp_get_topic_tag_tax_id() ) || !empty( $bbp->topic_query->is_tax ) || get_query_var( 'bbp_topic_tag' ) )
262 return true;
263
264 return false;
265 }
266
267 /**
268 * Check if the current page is editing a topic tag
269 *
270 * @since bbPress (r3346)
271 *
272 * @uses WP_Query Checks if WP_Query::bbp_is_topic_tag_edit is true
273 * @return bool True if editing a topic tag, false if not
274 */
275 function bbp_is_topic_tag_edit() {
276 global $wp_query;
277
278 if ( !empty( $wp_query->bbp_is_topic_tag_edit ) && ( true == $wp_query->bbp_is_topic_tag_edit ) )
279 return true;
280
281 return false;
282 }
283
284 /**
285 * Check if the current post type is one of bbPress's
286 *
287 * @since bbPress (r3311)
288 *
289 * @uses get_post_type()
290 * @uses bbp_get_forum_post_type()
291 * @uses bbp_get_topic_post_type()
292 * @uses bbp_get_reply_post_type()
293 *
294 * @return bool
295 */
296 function bbp_is_custom_post_type() {
297
298 // Current post type
299 $post_type = get_post_type();
300
301 // bbPress post types
302 $bbp_post_types = array(
303 bbp_get_forum_post_type(),
304 bbp_get_topic_post_type(),
305 bbp_get_reply_post_type()
306 );
307
308 // Viewing one of the bbPress post types
309 if ( in_array( $post_type, $bbp_post_types ) )
310 return true;
311
312 return false;
313 }
314
315 /**
316 * Check if current page is a bbPress reply
317 *
318 * @since bbPress (r2549)
319 *
320 * @param int $post_id Possible post_id to check
321 * @uses bbp_get_reply_post_type() To get the reply post type
322 * @uses get_post_type() To get the post type of the post id
323 * @return bool True if it's a reply page, false if not
324 */
325 function bbp_is_reply( $post_id = 0 ) {
326
327 // Assume false
328 $retval = false;
329
330 // Supplied ID is a reply
331 if ( !empty( $post_id ) && ( bbp_get_reply_post_type() == get_post_type( $post_id ) ) )
332 $retval = true;
333
334 return (bool) apply_filters( 'bbp_is_reply', $retval, $post_id );
335 }
336
337 /**
338 * Check if current page is a reply edit page
339 *
340 * @since bbPress (r2753)
341 *
342 * @uses WP_Query Checks if WP_Query::bbp_is_reply_edit is true
343 * @return bool True if it's the reply edit page, false if not
344 */
345 function bbp_is_reply_edit() {
346 global $wp_query;
347
348 if ( !empty( $wp_query->bbp_is_reply_edit ) && ( true == $wp_query->bbp_is_reply_edit ) )
349 return true;
350
351 return false;
352 }
353
354 /**
355 * Viewing a single reply
356 *
357 * @since bbPress (r3344)
358 *
359 * @uses is_single()
360 * @uses bbp_get_reply_post_type()
361 * @uses get_post_type()
362 * @uses apply_filters()
363 *
364 * @return bool
365 */
366 function bbp_is_single_reply() {
367
368 // Assume false
369 $retval = false;
370
371 // Single and a match
372 if ( is_singular( bbp_get_reply_post_type() ) || ( bbp_is_query_name( 'bbp_single_reply' ) ) )
373 $retval = true;
374
375 return (bool) apply_filters( 'bbp_is_single_reply', $retval );
376 }
377
378 /**
379 * Check if current page is a bbPress user's favorites page (profile page)
380 *
381 * @since bbPress (r2652)
382 *
383 * @uses bbp_get_query_name() To get the query name
384 * @return bool True if it's the favorites page, false if not
385 */
386 function bbp_is_favorites() {
387
388 $retval = bbp_is_query_name( 'bbp_user_profile_favorites' );
389
390 return (bool) apply_filters( 'bbp_is_favorites', $retval );
391 }
392
393 /**
394 * Check if current page is a bbPress user's subscriptions page (profile page)
395 *
396 * @since bbPress (r2652)
397 *
398 * @uses bbp_get_query_name() To get the query name
399 * @return bool True if it's the subscriptions page, false if not
400 */
401 function bbp_is_subscriptions() {
402
403 $retval = bbp_is_query_name( 'bbp_user_profile_subscriptions' );
404
405 return (bool) apply_filters( 'bbp_is_subscriptions', $retval );
406 }
407
408 /**
409 * Check if current page shows the topics created by a bbPress user (profile
410 * page)
411 *
412 * @since bbPress (r2688)
413 *
414 * @uses bbp_get_query_name() To get the query name
415 * @return bool True if it's the topics created page, false if not
416 */
417 function bbp_is_topics_created() {
418
419 $retval = bbp_is_query_name( 'bbp_user_profile_topics_created' );
420
421 return (bool) apply_filters( 'bbp_is_topics_created', $retval );
422 }
423
424 /**
425 * Check if current page is the currently logged in users author page
426 *
427 * @since bbPress (r2688)
428 *
429 * @uses bbPres Checks if bbPress::displayed_user is set and if
430 * bbPress::displayed_user::ID equals bbPress::current_user::ID
431 * or not
432 * @return bool True if it's the user's home, false if not
433 */
434 function bbp_is_user_home() {
435 global $bbp;
436
437 if ( empty( $bbp->displayed_user ) )
438 return false;
439
440 return (bool) ( bbp_get_displayed_user_id() == bbp_get_current_user_id() );
441 }
442
443 /**
444 * Check if current page is a user profile page
445 *
446 * @since bbPress (r2688)
447 *
448 * @uses WP_Query Checks if WP_Query::bbp_is_single_user is set to true
449 * @return bool True if it's a user's profile page, false if not
450 */
451 function bbp_is_single_user() {
452 global $wp_query;
453
454 if ( !empty( $wp_query->bbp_is_single_user ) && ( true == $wp_query->bbp_is_single_user ) )
455 return true;
456
457 return false;
458 }
459
460 /**
461 * Check if current page is a user profile edit page
462 *
463 * @since bbPress (r2688)
464 *
465 * @uses WP_Query Checks if WP_Query::bbp_is_single_user_edit is set to true
466 * @return bool True if it's a user's profile edit page, false if not
467 */
468 function bbp_is_single_user_edit() {
469 global $wp_query;
470
471 if ( !empty( $wp_query->bbp_is_single_user_edit ) && ( true == $wp_query->bbp_is_single_user_edit ) )
472 return true;
473
474 return false;
475 }
476
477 /**
478 * Check if current page is a view page
479 *
480 * @since bbPress (r2789)
481 *
482 * @uses WP_Query Checks if WP_Query::bbp_is_view is true
483 * @return bool Is it a view page?
484 */
485 function bbp_is_single_view() {
486 global $wp_query;
487
488 if ( !empty( $wp_query->bbp_is_view ) && ( true == $wp_query->bbp_is_view ) )
489 return true;
490
491 return false;
492 }
493
494 /**
495 * Use the above is_() functions to output a body class for each scenario
496 *
497 * @since bbPress (r2926)
498 *
499 * @param array $wp_classes
500 * @param array $custom_classes
501 * @uses bbp_is_single_forum()
502 * @uses bbp_is_single_topic()
503 * @uses bbp_is_topic_edit()
504 * @uses bbp_is_topic_merge()
505 * @uses bbp_is_topic_split()
506 * @uses bbp_is_single_reply()
507 * @uses bbp_is_reply_edit()
508 * @uses bbp_is_reply_edit()
509 * @uses bbp_is_single_view()
510 * @uses bbp_is_single_user_edit()
511 * @uses bbp_is_single_user()
512 * @uses bbp_is_user_home()
513 * @uses bbp_is_subscriptions()
514 * @uses bbp_is_favorites()
515 * @uses bbp_is_topics_created()
516 * @return array Body Classes
517 */
518 function bbp_body_class( $wp_classes, $custom_classes = false ) {
519
520 $bbp_classes = array();
521
522 /** Archives **************************************************************/
523
524 if ( bbp_is_forum_archive() )
525 $bbp_classes[] = bbp_get_forum_post_type() . '-archive';
526
527 if ( bbp_is_topic_archive() )
528 $bbp_classes[] = bbp_get_topic_post_type() . '-archive';
529
530 /** Components ************************************************************/
531
532 if ( bbp_is_single_forum() )
533 $bbp_classes[] = bbp_get_forum_post_type();
534
535 if ( bbp_is_single_topic() )
536 $bbp_classes[] = bbp_get_topic_post_type();
537
538 if ( bbp_is_single_reply() )
539 $bbp_classes[] = bbp_get_reply_post_type();
540
541 if ( bbp_is_topic_edit() )
542 $bbp_classes[] = bbp_get_topic_post_type() . '-edit';
543
544 if ( bbp_is_topic_merge() )
545 $bbp_classes[] = bbp_get_topic_post_type() . '-merge';
546
547 if ( bbp_is_topic_split() )
548 $bbp_classes[] = bbp_get_topic_post_type() . '-split';
549
550 if ( bbp_is_reply_edit() )
551 $bbp_classes[] = bbp_get_reply_post_type() . '-edit';
552
553 if ( bbp_is_single_view() )
554 $bbp_classes[] = 'bbp-view';
555
556 /** User ******************************************************************/
557
558 if ( bbp_is_single_user_edit() ) {
559 $bbp_classes[] = 'bbp-user-edit';
560 $bbp_classes[] = 'single';
561 $bbp_classes[] = 'singular';
562 }
563
564 if ( bbp_is_single_user() ) {
565 $bbp_classes[] = 'bbp-user-page';
566 $bbp_classes[] = 'single';
567 $bbp_classes[] = 'singular';
568 }
569
570 if ( bbp_is_user_home() ) {
571 $bbp_classes[] = 'bbp-user-home';
572 $bbp_classes[] = 'single';
573 $bbp_classes[] = 'singular';
574 }
575
576 if ( bbp_is_topics_created() ) {
577 $bbp_classes[] = 'bbp-topics-created';
578 $bbp_classes[] = 'single';
579 $bbp_classes[] = 'singular';
580 }
581
582 if ( bbp_is_favorites() ) {
583 $bbp_classes[] = 'bbp-favorites';
584 $bbp_classes[] = 'single';
585 $bbp_classes[] = 'singular';
586 }
587
588 if ( bbp_is_subscriptions() ) {
589 $bbp_classes[] = 'bbp-subscriptions';
590 $bbp_classes[] = 'single';
591 $bbp_classes[] = 'singular';
592 }
593
594 /** Clean up **************************************************************/
595
596 // Add bbPress class if we are within a bbPress page
597 if ( !empty( $bbp_classes ) )
598 $bbp_classes[] = 'bbPress';
599
600 // Merge WP classes with bbPress classes
601 $classes = array_merge( (array) $bbp_classes, (array) $wp_classes );
602
603 // Remove any duplicates
604 $classes = array_unique( $classes );
605
606 return apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
607 }
608
609 /**
610 * Use the above is_() functions to return if in any bbPress page
611 *
612 * @since bbPress (r3344)
613 *
614 * @uses bbp_is_single_forum()
615 * @uses bbp_is_single_topic()
616 * @uses bbp_is_topic_edit()
617 * @uses bbp_is_topic_merge()
618 * @uses bbp_is_topic_split()
619 * @uses bbp_is_single_reply()
620 * @uses bbp_is_reply_edit()
621 * @uses bbp_is_reply_edit()
622 * @uses bbp_is_single_view()
623 * @uses bbp_is_single_user_edit()
624 * @uses bbp_is_single_user()
625 * @uses bbp_is_user_home()
626 * @uses bbp_is_subscriptions()
627 * @uses bbp_is_favorites()
628 * @uses bbp_is_topics_created()
629 * @return bool In a bbPress page
630 */
631 function is_bbpress() {
632
633 // Defalt to false
634 $retval = false;
635
636 /** Archives **************************************************************/
637
638 if ( bbp_is_forum_archive() )
639 $retval = true;
640
641 elseif ( bbp_is_topic_archive() )
642 $retval = true;
643
644 /** Topic Tags ************************************************************/
645
646 elseif ( bbp_is_topic_tag() )
647 $retval = true;
648
649 elseif ( bbp_is_topic_tag_edit() )
650 $retval = true;
651
652 /** Components ************************************************************/
653
654 elseif ( bbp_is_single_forum() )
655 $retval = true;
656
657 elseif ( bbp_is_single_topic() )
658 $retval = true;
659
660 elseif ( bbp_is_single_reply() )
661 $retval = true;
662
663 elseif ( bbp_is_topic_edit() )
664 $retval = true;
665
666 elseif ( bbp_is_topic_merge() )
667 $retval = true;
668
669 elseif ( bbp_is_topic_split() )
670 $retval = true;
671
672 elseif ( bbp_is_reply_edit() )
673 $retval = true;
674
675 elseif ( bbp_is_single_view() )
676 $retval = true;
677
678 /** User ******************************************************************/
679
680 elseif ( bbp_is_single_user_edit() )
681 $retval = true;
682
683 elseif ( bbp_is_single_user() )
684 $retval = true;
685
686 elseif ( bbp_is_user_home() )
687 $retval = true;
688
689 elseif ( bbp_is_topics_created() )
690 $retval = true;
691
692 elseif ( bbp_is_favorites() )
693 $retval = true;
694
695 elseif ( bbp_is_subscriptions() )
696 $retval = true;
697
698 /** Done ******************************************************************/
699
700 return apply_filters( 'is_bbpress', $retval );
701 }
702
703 /** Forms *********************************************************************/
704
705 /**
706 * Output the login form action url
707 *
708 * @since bbPress (r2815)
709 *
710 * @param string $url Pass a URL to redirect to
711 * @uses add_query_arg() To add a arg to the url
712 * @uses site_url() Toget the site url
713 * @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args
714 */
715 function bbp_wp_login_action( $args = '' ) {
716 $defaults = array (
717 'action' => '',
718 'context' => ''
719 );
720 $r = wp_parse_args( $args, $defaults );
721 extract( $r );
722
723 if ( !empty( $action ) )
724 $login_url = add_query_arg( array( 'action' => $action ), 'wp-login.php' );
725 else
726 $login_url = 'wp-login.php';
727
728 $login_url = site_url( $login_url, $context );
729
730 echo apply_filters( 'bbp_wp_login_action', $login_url, $args );
731 }
732
733 /**
734 * Output hidden request URI field for user forms.
735 *
736 * The referer link is the current Request URI from the server super global. The
737 * input name is '_wp_http_referer', in case you wanted to check manually.
738 *
739 * @since bbPress (r2815)
740 *
741 * @param string $url Pass a URL to redirect to
742 * @uses wp_get_referer() To get the referer
743 * @uses esc_attr() To escape the url
744 * @uses apply_filters() Calls 'bbp_redirect_to_field' with the referer field
745 * and url
746 */
747 function bbp_redirect_to_field( $redirect_to = '' ) {
748
749 // Rejig the $redirect_to
750 if ( !isset( $_SERVER['REDIRECT_URL'] ) || ( !$redirect_to = home_url( $_SERVER['REDIRECT_URL'] ) ) )
751 $redirect_to = wp_get_referer();
752
753 // Make sure we are directing somewhere
754 if ( empty( $redirect_to ) )
755 $redirect_to = home_url( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' );
756
757 // Remove loggedout query arg if it's there
758 $redirect_to = (string) esc_attr( remove_query_arg( 'loggedout', $redirect_to ) );
759 $redirect_field = '<input type="hidden" name="redirect_to" value="' . $redirect_to . '" />';
760
761 echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to );
762 }
763
764 /**
765 * Echo sanitized $_REQUEST value.
766 *
767 * Use the $input_type parameter to properly process the value. This
768 * ensures correct sanitization of the value for the receiving input.
769 *
770 * @since bbPress (r2815)
771 *
772 * @param string $request Name of $_REQUEST to look for
773 * @param string $input_type Type of input. Default: text. Accepts:
774 * textarea|password|select|radio|checkbox
775 * @uses bbp_get_sanitize_val() To sanitize the value.
776 */
777 function bbp_sanitize_val( $request = '', $input_type = 'text' ) {
778 echo bbp_get_sanitize_val( $request, $input_type );
779 }
780 /**
781 * Return sanitized $_REQUEST value.
782 *
783 * Use the $input_type parameter to properly process the value. This
784 * ensures correct sanitization of the value for the receiving input.
785 *
786 * @since bbPress (r2815)
787 *
788 * @param string $request Name of $_REQUEST to look for
789 * @param string $input_type Type of input. Default: text. Accepts:
790 * textarea|password|select|radio|checkbox
791 * @uses esc_attr() To escape the string
792 * @uses apply_filters() Calls 'bbp_get_sanitize_val' with the sanitized
793 * value, request and input type
794 * @return string Sanitized value ready for screen display
795 */
796 function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) {
797
798 // Check that requested
799 if ( empty( $_REQUEST[$request] ) )
800 return false;
801
802 // Set request varaible
803 $pre_ret_val = $_REQUEST[$request];
804
805 // Treat different kinds of fields in different ways
806 switch ( $input_type ) {
807 case 'text' :
808 case 'textarea' :
809 $retval = esc_attr( stripslashes( $pre_ret_val ) );
810 break;
811
812 case 'password' :
813 case 'select' :
814 case 'radio' :
815 case 'checkbox' :
816 default :
817 $retval = esc_attr( $pre_ret_val );
818 break;
819 }
820
821 return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type );
822 }
823
824 /**
825 * Output the current tab index of a given form
826 *
827 * Use this function to handle the tab indexing of user facing forms within a
828 * template file. Calling this function will automatically increment the global
829 * tab index by default.
830 *
831 * @since bbPress (r2810)
832 *
833 * @param int $auto_increment Optional. Default true. Set to false to prevent
834 * increment
835 */
836 function bbp_tab_index( $auto_increment = true ) {
837 echo bbp_get_tab_index( $auto_increment );
838 }
839
840 /**
841 * Output the current tab index of a given form
842 *
843 * Use this function to handle the tab indexing of user facing forms
844 * within a template file. Calling this function will automatically
845 * increment the global tab index by default.
846 *
847 * @since bbPress (r2810)
848 *
849 * @uses apply_filters Allows return value to be filtered
850 * @param int $auto_increment Optional. Default true. Set to false to
851 * prevent the increment
852 * @return int $bbp->tab_index The global tab index
853 */
854 function bbp_get_tab_index( $auto_increment = true ) {
855 global $bbp;
856
857 if ( true === $auto_increment )
858 ++$bbp->tab_index;
859
860 return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
861 }
862
863 /**
864 * Output a select box allowing to pick which forum/topic a new topic/reply
865 * belongs in.
866 *
867 * Can be used for any post type, but is mostly used for topics and forums.
868 *
869 * @since bbPress (r2746)
870 *
871 * @param mixed $args See {@link bbp_get_dropdown()} for arguments
872 */
873 function bbp_dropdown( $args = '' ) {
874 echo bbp_get_dropdown( $args );
875 }
876 /**
877 * Output a select box allowing to pick which forum/topic a new
878 * topic/reply belongs in.
879 *
880 * @since bbPress (r2746)
881 *
882 * @param mixed $args The function supports these args:
883 * - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
884 * - selected: Selected ID, to not have any value as selected, pass
885 * anything smaller than 0 (due to the nature of select
886 * box, the first value would of course be selected -
887 * though you can have that as none (pass 'show_none' arg))
888 * - sort_column: Sort by? Defaults to 'menu_order, post_title'
889 * - child_of: Child of. Defaults to 0
890 * - post_status: Which all post_statuses to find in? Can be an array
891 * or CSV of publish, category, closed, private, spam,
892 * trash (based on post type) - if not set, these are
893 * automatically determined based on the post_type
894 * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
895 * all posts
896 * - walker: Which walker to use? Defaults to
897 * {@link BBP_Walker_Dropdown}
898 * - select_id: ID of the select box. Defaults to 'bbp_forum_id'
899 * - tab: Tabindex value. False or integer
900 * - options_only: Show only <options>? No <select>?
901 * - show_none: False or something like __( '(No Forum)', 'bbpress' ),
902 * will have value=""
903 * - none_found: False or something like
904 * __( 'No forums to post to!', 'bbpress' )
905 * - disable_categories: Disable forum categories and closed forums?
906 * Defaults to true. Only for forums and when
907 * the category option is displayed.
908 * @uses BBP_Walker_Dropdown() As the default walker to generate the
909 * dropdown
910 * @uses current_user_can() To check if the current user can read
911 * private forums
912 * @uses bbp_get_forum_post_type() To get the forum post type
913 * @uses bbp_get_topic_post_type() To get the topic post type
914 * @uses walk_page_dropdown_tree() To generate the dropdown using the
915 * walker
916 * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
917 * and args
918 * @return string The dropdown
919 */
920 function bbp_get_dropdown( $args = '' ) {
921
922 /** Arguments *********************************************************/
923
924 $defaults = array (
925 'post_type' => bbp_get_forum_post_type(),
926 'selected' => 0,
927 'sort_column' => 'menu_order',
928 'child_of' => '0',
929 'numberposts' => -1,
930 'orderby' => 'menu_order',
931 'order' => 'ASC',
932 'walker' => '',
933
934 // Output-related
935 'select_id' => 'bbp_forum_id',
936 'tab' => bbp_get_tab_index(),
937 'options_only' => false,
938 'show_none' => false,
939 'none_found' => false,
940 'disable_categories' => true
941 );
942
943 $r = wp_parse_args( $args, $defaults );
944
945 if ( empty( $r['walker'] ) ) {
946 $r['walker'] = new BBP_Walker_Dropdown();
947 $r['walker']->tree_type = $r['post_type'];
948 }
949
950 // Force 0
951 if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 )
952 $r['selected'] = 0;
953
954 extract( $r );
955
956 // Unset the args not needed for WP_Query to avoid any possible conflicts.
957 // Note: walker and disable_categories are not unset
958 unset( $r['select_id'], $r['tab'], $r['options_only'], $r['show_none'], $r['none_found'] );
959
960 /** Post Status *******************************************************/
961
962 // Public
963 $post_stati[] = bbp_get_public_status_id();
964
965 // Forums
966 if ( bbp_get_forum_post_type() == $post_type ) {
967
968 // Private forums
969 if ( current_user_can( 'read_private_forums' ) )
970 $post_stati[] = bbp_get_private_status_id();
971
972 // Hidden forums
973 if ( current_user_can( 'read_hidden_forums' ) )
974 $post_stati[] = bbp_get_hidden_status_id();
975 }
976
977 // Setup the post statuses
978 $r['post_status'] = implode( ',', $post_stati );
979
980 /** Setup variables ***************************************************/
981
982 $name = esc_attr( $select_id );
983 $select_id = $name;
984 $tab = (int) $tab;
985 $retval = '';
986 $posts = get_posts( $r );
987
988 /** Drop Down *********************************************************/
989
990 // Items found
991 if ( !empty( $posts ) ) {
992 if ( empty( $options_only ) ) {
993 $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
994 $retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . '>' . "\n";
995 }
996
997 $retval .= !empty( $show_none ) ? "\t<option value=\"\" class=\"level-0\">" . $show_none . '</option>' : '';
998 $retval .= walk_page_dropdown_tree( $posts, 0, $r );
999
1000 if ( empty( $options_only ) )
1001 $retval .= '</select>';
1002
1003 // No items found - Display feedback if no custom message was passed
1004 } elseif ( empty( $none_found ) ) {
1005
1006 // Switch the response based on post type
1007 switch ( $post_type ) {
1008
1009 // Topics
1010 case bbp_get_topic_post_type() :
1011 $retval = __( 'No topics available', 'bbpress' );
1012 break;
1013
1014 // Forums
1015 case bbp_get_forum_post_type() :
1016 $retval = __( 'No forums available', 'bbpress' );
1017 break;
1018
1019 // Any other
1020 default :
1021 $retval = __( 'None available', 'bbpress' );
1022 break;
1023 }
1024 }
1025
1026 return apply_filters( 'bbp_get_dropdown', $retval, $args );
1027 }
1028
1029 /**
1030 * Output the required hidden fields when creating/editing a topic
1031 *
1032 * @since bbPress (r2753)
1033 *
1034 * @uses bbp_is_topic_edit() To check if it's the topic edit page
1035 * @uses wp_nonce_field() To generate hidden nonce fields
1036 * @uses bbp_topic_id() To output the topic id
1037 * @uses bbp_is_single_forum() To check if it's a forum page
1038 * @uses bbp_forum_id() To output the forum id
1039 */
1040 function bbp_topic_form_fields() {
1041
1042 if ( bbp_is_topic_edit() ) : ?>
1043
1044 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" />
1045 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
1046
1047 <?php
1048
1049 if ( current_user_can( 'unfiltered_html' ) )
1050 wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false );
1051
1052 ?>
1053
1054 <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() );
1055
1056 else :
1057
1058 if ( bbp_is_single_forum() ) : ?>
1059
1060 <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
1061
1062 <?php endif; ?>
1063
1064 <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" />
1065
1066 <?php
1067
1068 if ( current_user_can( 'unfiltered_html' ) )
1069 wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false );
1070
1071 ?>
1072
1073 <?php wp_nonce_field( 'bbp-new-topic' );
1074
1075 endif;
1076 }
1077
1078 /**
1079 * Output the required hidden fields when creating/editing a reply
1080 *
1081 * @since bbPress (r2753)
1082 *
1083 * @uses bbp_is_reply_edit() To check if it's the reply edit page
1084 * @uses wp_nonce_field() To generate hidden nonce fields
1085 * @uses bbp_reply_id() To output the reply id
1086 * @uses bbp_topic_id() To output the topic id
1087 * @uses bbp_forum_id() To output the forum id
1088 */
1089 function bbp_reply_form_fields() {
1090
1091 if ( bbp_is_reply_edit() ) { ?>
1092
1093 <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" maxlength="<?php bbp_get_title_max_length(); ?>" />
1094 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" />
1095 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" />
1096
1097 <?php
1098
1099 if ( current_user_can( 'unfiltered_html' ) )
1100 wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false );
1101
1102 ?>
1103
1104 <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() );
1105
1106 } else {
1107
1108 ?>
1109
1110 <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" maxlength="<?php bbp_get_title_max_length(); ?>" />
1111 <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
1112 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
1113 <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" />
1114
1115 <?php
1116
1117 if ( current_user_can( 'unfiltered_html' ) )
1118 wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false );
1119
1120 ?>
1121
1122 <?php
1123
1124 wp_nonce_field( 'bbp-new-reply' );
1125
1126 // Show redirect field if not viewing a specific topic
1127 if ( bbp_is_query_name( 'bbp_single_topic' ) ) : ?>
1128
1129 <input type="hidden" name="redirect_to" id="bbp_redirect_to" value="<?php the_permalink(); ?>" />
1130
1131 <?php endif;
1132
1133 }
1134 }
1135
1136 /**
1137 * Output the required hidden fields when editing a user
1138 *
1139 * @since bbPress (r2690)
1140 *
1141 * @uses bbp_displayed_user_id() To output the displayed user id
1142 * @uses wp_nonce_field() To generate a hidden nonce field
1143 * @uses wp_referer_field() To generate a hidden referer field
1144 */
1145 function bbp_edit_user_form_fields() {
1146 ?>
1147
1148 <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" />
1149 <input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" />
1150
1151 <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() );
1152 }
1153
1154 /**
1155 * Merge topic form fields
1156 *
1157 * Output the required hidden fields when merging a topic
1158 *
1159 * @since bbPress (r2756)
1160 *
1161 * @uses wp_nonce_field() To generate a hidden nonce field
1162 * @uses bbp_topic_id() To output the topic id
1163 */
1164 function bbp_merge_topic_form_fields() {
1165 ?>
1166
1167 <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" />
1168 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
1169
1170 <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() );
1171 }
1172
1173 /**
1174 * Split topic form fields
1175 *
1176 * Output the required hidden fields when splitting a topic
1177 *
1178 * @since bbPress (r2756)
1179 *
1180 * @uses wp_nonce_field() To generete a hidden nonce field
1181 */
1182 function bbp_split_topic_form_fields() {
1183 ?>
1184
1185 <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" />
1186 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" />
1187
1188 <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() );
1189 }
1190
1191 /** Views *********************************************************************/
1192
1193 /**
1194 * Output the view id
1195 *
1196 * @since bbPress (r2789)
1197 *
1198 * @param string $view Optional. View id
1199 * @uses bbp_get_view_id() To get the view id
1200 */
1201 function bbp_view_id( $view = '' ) {
1202 echo bbp_get_view_id( $view );
1203 }
1204
1205 /**
1206 * Get the view id
1207 *
1208 * If a view id is supplied, that is used. Otherwise the 'bbp_view'
1209 * query var is checked for.
1210 *
1211 * @since bbPress (r2789)
1212 *
1213 * @param string $view Optional. View id.
1214 * @uses sanitize_title() To sanitize the view id
1215 * @uses get_query_var() To get the view id from query var 'bbp_view'
1216 * @return bool|string ID on success, false on failure
1217 */
1218 function bbp_get_view_id( $view = '' ) {
1219 global $bbp;
1220
1221 $view = !empty( $view ) ? sanitize_title( $view ) : get_query_var( 'bbp_view' );
1222
1223 if ( array_key_exists( $view, $bbp->views ) )
1224 return $view;
1225
1226 return false;
1227 }
1228
1229 /**
1230 * Output the view name aka title
1231 *
1232 * @since bbPress (r2789)
1233 *
1234 * @param string $view Optional. View id
1235 * @uses bbp_get_view_title() To get the view title
1236 */
1237 function bbp_view_title( $view = '' ) {
1238 echo bbp_get_view_title( $view );
1239 }
1240
1241 /**
1242 * Get the view name aka title
1243 *
1244 * If a view id is supplied, that is used. Otherwise the bbp_view
1245 * query var is checked for.
1246 *
1247 * @since bbPress (r2789)
1248 *
1249 * @param string $view Optional. View id
1250 * @uses bbp_get_view_id() To get the view id
1251 * @return bool|string Title on success, false on failure
1252 */
1253 function bbp_get_view_title( $view = '' ) {
1254 global $bbp;
1255
1256 if ( !$view = bbp_get_view_id( $view ) )
1257 return false;
1258
1259 return $bbp->views[$view]['title'];
1260 }
1261
1262 /**
1263 * Output the view url
1264 *
1265 * @since bbPress (r2789)
1266 *
1267 * @param string $view Optional. View id
1268 * @uses bbp_get_view_url() To get the view url
1269 */
1270 function bbp_view_url( $view = false ) {
1271 echo bbp_get_view_url( $view );
1272 }
1273 /**
1274 * Return the view url
1275 *
1276 * @since bbPress (r2789)
1277 *
1278 * @param string $view Optional. View id
1279 * @uses sanitize_title() To sanitize the view id
1280 * @uses home_url() To get blog home url
1281 * @uses add_query_arg() To add custom args to the url
1282 * @uses apply_filters() Calls 'bbp_get_view_url' with the view url,
1283 * used view id
1284 * @return string View url (or home url if the view was not found)
1285 */
1286 function bbp_get_view_url( $view = false ) {
1287 global $bbp, $wp_rewrite;
1288
1289 if ( !$view = bbp_get_view_id( $view ) )
1290 return home_url();
1291
1292 // Pretty permalinks
1293 if ( $wp_rewrite->using_permalinks() ) {
1294 $url = $wp_rewrite->root . $bbp->view_slug . '/' . $view;
1295 $url = home_url( user_trailingslashit( $url ) );
1296
1297 // Unpretty permalinks
1298 } else {
1299 $url = add_query_arg( array( 'bbp_view' => $view ), home_url( '/' ) );
1300 }
1301
1302 return apply_filters( 'bbp_get_view_link', $url, $view );
1303 }
1304
1305 /** Query *********************************************************************/
1306
1307 /**
1308 * Check the passed parameter against the current _bbp_query_name
1309 *
1310 * @since bbPress (r2980)
1311 *
1312 * @uses bbp_get_query_name() Get the query var '_bbp_query_name'
1313 * @return bool True if match, false if not
1314 */
1315 function bbp_is_query_name( $query_name ) {
1316
1317 // No empties
1318 if ( empty( $query_name ) )
1319 return false;
1320
1321 // Check if query var matches
1322 if ( bbp_get_query_name() == $query_name )
1323 return true;
1324
1325 // No match
1326 return false;
1327 }
1328
1329 /**
1330 * Get the '_bbp_query_name' setting
1331 *
1332 * @since bbPress (r2695)
1333 *
1334 * @uses get_query_var() To get the query var '_bbp_query_name'
1335 * @return string To return the query var value
1336 */
1337 function bbp_get_query_name() {
1338 return get_query_var( '_bbp_query_name' );
1339 }
1340
1341 /**
1342 * Set the '_bbp_query_name' setting to $name
1343 *
1344 * @since bbPress (r2692)
1345 *
1346 * @param string $name What to set the query var to
1347 * @uses set_query_var() To set the query var '_bbp_query_name'
1348 */
1349 function bbp_set_query_name( $name = '' ) {
1350 set_query_var( '_bbp_query_name', $name );
1351 }
1352
1353 /**
1354 * Used to clear the '_bbp_query_name' setting
1355 *
1356 * @since bbPress (r2692)
1357 *
1358 * @uses bbp_set_query_name() To set the query var '_bbp_query_name' value to ''
1359 */
1360 function bbp_reset_query_name() {
1361 bbp_set_query_name();
1362 }
1363
1364 /** Breadcrumbs ***************************************************************/
1365
1366 /**
1367 * Output the page title as a breadcrumb
1368 *
1369 * @since bbPress (r2589)
1370 *
1371 * @param string $sep Separator. Defaults to '&larr;'
1372 * @param bool $current_page Include the current item
1373 * @param bool $root Include the root page if one exists
1374 * @uses bbp_get_breadcrumb() To get the breadcrumb
1375 */
1376 function bbp_title_breadcrumb( $args = array() ) {
1377 echo bbp_get_breadcrumb( $args );
1378 }
1379
1380 /**
1381 * Output a breadcrumb
1382 *
1383 * @since bbPress (r2589)
1384 *
1385 * @param string $sep Separator. Defaults to '&larr;'
1386 * @param bool $current_page Include the current item
1387 * @param bool $root Include the root page if one exists
1388 * @uses bbp_get_breadcrumb() To get the breadcrumb
1389 */
1390 function bbp_breadcrumb( $args = array() ) {
1391 echo bbp_get_breadcrumb( $args );
1392 }
1393 /**
1394 * Return a breadcrumb ( forum -> topic -> reply )
1395 *
1396 * @since bbPress (r2589)
1397 *
1398 * @param string $sep Separator. Defaults to '&larr;'
1399 * @param bool $current_page Include the current item
1400 * @param bool $root Include the root page if one exists
1401 *
1402 * @uses get_post() To get the post
1403 * @uses bbp_get_forum_permalink() To get the forum link
1404 * @uses bbp_get_topic_permalink() To get the topic link
1405 * @uses bbp_get_reply_permalink() To get the reply link
1406 * @uses get_permalink() To get the permalink
1407 * @uses bbp_get_forum_post_type() To get the forum post type
1408 * @uses bbp_get_topic_post_type() To get the topic post type
1409 * @uses bbp_get_reply_post_type() To get the reply post type
1410 * @uses bbp_get_forum_title() To get the forum title
1411 * @uses bbp_get_topic_title() To get the topic title
1412 * @uses bbp_get_reply_title() To get the reply title
1413 * @uses get_the_title() To get the title
1414 * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs
1415 * @return string Breadcrumbs
1416 */
1417 function bbp_get_breadcrumb( $args = array() ) {
1418 global $bbp;
1419
1420 // Turn off breadcrumbs
1421 if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) )
1422 return;
1423
1424 // Define variables
1425 $front_id = $root_id = 0;
1426 $ancestors = $breadcrumbs = array();
1427 $pre_root_text = $pre_front_text = $pre_current_text = '';
1428 $pre_include_root = $pre_include_home = $pre_include_current = true;
1429
1430 /** Home Text *********************************************************/
1431
1432 // No custom home text
1433 if ( empty( $args['home_text'] ) ) {
1434
1435 // Set home text to page title
1436 if ( $front_id = get_option( 'page_on_front' ) ) {
1437 $pre_front_text = get_the_title( $front_id );
1438
1439 // Default to 'Home'
1440 } else {
1441 $pre_front_text = __( 'Home', 'bbpress' );
1442 }
1443 }
1444
1445 /** Root Text *********************************************************/
1446
1447 // No custom root text
1448 if ( empty( $args['root_text'] ) ) {
1449 if ( $page = bbp_get_page_by_path( $bbp->root_slug ) ) {
1450 $root_id = $page->ID;
1451 }
1452 $pre_root_text = bbp_get_forum_archive_title();
1453 }
1454
1455 /** Includes **********************************************************/
1456
1457 // Root slug is also the front page
1458 if ( !empty( $front_id ) && ( $front_id == $root_id ) )
1459 $pre_include_root = false;
1460
1461 // Don't show root if viewing forum archive
1462 if ( bbp_is_forum_archive() )
1463 $pre_include_root = false;
1464
1465 // Don't show root if viewing page in place of forum archive
1466 if ( !empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id == get_the_ID() ) ) )
1467 $pre_include_root = false;
1468
1469 /** Current Text ******************************************************/
1470
1471 // Forum archive
1472 if ( bbp_is_forum_archive() ) {
1473 $pre_current_text = bbp_get_forum_archive_title();
1474
1475 // Topic archive
1476 } elseif ( bbp_is_topic_archive() ) {
1477 $pre_current_text = bbp_get_topic_archive_title();
1478
1479 // View
1480 } elseif ( bbp_is_single_view() ) {
1481 $pre_current_text = bbp_get_view_title();
1482
1483 // Single Forum
1484 } elseif ( bbp_is_single_forum() ) {
1485 $pre_current_text = bbp_get_forum_title();
1486
1487 // Single Topic
1488 } elseif ( bbp_is_single_topic() ) {
1489 $pre_current_text = bbp_get_topic_title();
1490
1491 // Single Topic
1492 } elseif ( bbp_is_single_reply() ) {
1493 $pre_current_text = bbp_get_reply_title();
1494
1495 // Topic Tag (or theme compat topic tag)
1496 } elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && !bbp_is_topic_tag_edit() ) ) {
1497
1498 // Always include the tag name
1499 $tag_data[] = bbp_get_topic_tag_name();
1500
1501 // If capable, include a link to edit the tag
1502 if ( current_user_can( 'manage_topic_tags' ) ) {
1503 $tag_data[] = '<a href="' . bbp_get_topic_tag_edit_link() . '" class="bbp-edit-topic-tag-link">' . __( '(Edit)', 'bbpress' ) . '</a>';
1504 }
1505
1506 // Implode the results of the tag data
1507 $pre_current_text = sprintf( __( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) );
1508
1509 // Edit Topic Tag
1510 } elseif ( bbp_is_topic_tag_edit() ) {
1511 $pre_current_text = __( 'Edit', 'bbpress' );
1512
1513 // Single
1514 } else {
1515 $pre_current_text = get_the_title();
1516 }
1517
1518 /** Parse Args ********************************************************/
1519
1520 // Parse args
1521 $defaults = array(
1522
1523 // HTML
1524 'before' => '<div class="bbp-breadcrumb"><p>',
1525 'after' => '</p></div>',
1526 'sep' => is_rtl() ? __( '&lsaquo;', 'bbpress' ) : __( '&rsaquo;', 'bbpress' ),
1527 'pad_sep' => 1,
1528
1529 // Home
1530 'include_home' => $pre_include_home,
1531 'home_text' => $pre_front_text,
1532
1533 // Forum root
1534 'include_root' => $pre_include_root,
1535 'root_text' => $pre_root_text,
1536
1537 // Current
1538 'include_current' => $pre_include_current,
1539 'current_text' => $pre_current_text
1540 );
1541 $r = apply_filters( 'bbp_get_breadcrumb_pre', wp_parse_args( $args, $defaults ) );
1542 extract( $r );
1543
1544 /** Ancestors *********************************************************/
1545
1546 // Get post ancestors
1547 if ( is_page() || is_single() || bbp_is_topic_edit() || bbp_is_reply_edit() )
1548 $ancestors = array_reverse( get_post_ancestors( get_the_ID() ) );
1549
1550 // Do we want to include a link to home?
1551 if ( !empty( $include_home ) || empty( $home_text ) )
1552 $breadcrumbs[] = '<a href="' . trailingslashit( home_url() ) . '" class="bbp-breadcrumb-home">' . $home_text . '</a>';
1553
1554 // Do we want to include a link to the forum root?
1555 if ( !empty( $include_root ) || empty( $root_text ) ) {
1556
1557 // Page exists at root slug path, so use its permalink
1558 if ( $page = bbp_get_page_by_path( $bbp->root_slug ) ) {
1559 $root_url = get_permalink( $page->ID );
1560
1561 // Use the root slug
1562 } else {
1563 $root_url = get_post_type_archive_link( bbp_get_forum_post_type() );
1564 }
1565
1566 // Add the breadcrumb
1567 $breadcrumbs[] = '<a href="' . $root_url . '" class="bbp-breadcrumb-root">' . $root_text . '</a>';
1568 }
1569
1570 // Ancestors exist
1571 if ( !empty( $ancestors ) ) {
1572
1573 // Loop through parents
1574 foreach( (array) $ancestors as $parent_id ) {
1575
1576 // Parents
1577 $parent = get_post( $parent_id );
1578
1579 // Switch through post_type to ensure correct filters are applied
1580 switch ( $parent->post_type ) {
1581 // Forum
1582 case bbp_get_forum_post_type() :
1583 $breadcrumbs[] = '<a href="' . bbp_get_forum_permalink( $parent->ID ) . '">' . bbp_get_forum_title( $parent->ID ) . '</a>';
1584 break;
1585
1586 // Topic
1587 case bbp_get_topic_post_type() :
1588 $breadcrumbs[] = '<a href="' . bbp_get_topic_permalink( $parent->ID ) . '">' . bbp_get_topic_title( $parent->ID ) . '</a>';
1589 break;
1590
1591 // Reply (Note: not in most themes)
1592 case bbp_get_reply_post_type() :
1593 $breadcrumbs[] = '<a href="' . bbp_get_reply_permalink( $parent->ID ) . '">' . bbp_get_reply_title( $parent->ID ) . '</a>';
1594 break;
1595
1596 // WordPress Post/Page/Other
1597 default :
1598 $breadcrumbs[] = '<a href="' . get_permalink( $parent->ID ) . '">' . get_the_title( $parent->ID ) . '</a>';
1599 break;
1600 }
1601 }
1602
1603 // Edit topic tag
1604 } elseif ( bbp_is_topic_tag_edit() ) {
1605 $breadcrumbs[] = '<a href="' . get_term_link( bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id() ) . '">' . sprintf( __( 'Topic Tag: %s', 'bbpress' ), bbp_get_topic_tag_name() ) . '</a>';
1606 }
1607
1608 /** Current ***********************************************************/
1609
1610 // Add current page to breadcrumb
1611 if ( !empty( $include_current ) || empty( $pre_current_text ) )
1612 $breadcrumbs[] = '<span class="bbp-breadcrumb-current">' . $current_text . '</span>';
1613
1614 /** Finish Up *********************************************************/
1615
1616 // Pad the separator
1617 if ( !empty( $pad_sep ) )
1618 $sep = str_pad( $sep, strlen( $sep ) + ( (int) $pad_sep * 2 ), ' ', STR_PAD_BOTH );
1619
1620 // Allow the separator of the breadcrumb to be easily changed
1621 $sep = apply_filters( 'bbp_breadcrumb_separator', $sep );
1622
1623 // Right to left support
1624 if ( is_rtl() )
1625 $breadcrumbs = apply_filters( 'bbp_breadcrumbs', array_reverse( $breadcrumbs ) );
1626
1627 // Build the trail
1628 $trail = !empty( $breadcrumbs ) ? $before . implode( $sep, $breadcrumbs ) . $after: '';
1629
1630 return apply_filters( 'bbp_get_breadcrumb', $trail, $breadcrumbs, $r );
1631 }
1632
1633 /** Topic Tags ***************************************************************/
1634
1635 /**
1636 * Output all of the allowed tags in HTML format with attributes.
1637 *
1638 * This is useful for displaying in the post area, which elements and
1639 * attributes are supported. As well as any plugins which want to display it.
1640 *
1641 * @since bbPress (r2780)
1642 *
1643 * @uses bbp_get_allowed_tags()
1644 */
1645 function bbp_allowed_tags() {
1646 echo bbp_get_allowed_tags();
1647 }
1648 /**
1649 * Display all of the allowed tags in HTML format with attributes.
1650 *
1651 * This is useful for displaying in the post area, which elements and
1652 * attributes are supported. As well as any plugins which want to display it.
1653 *
1654 * @since bbPress (r2780)
1655 *
1656 * @uses allowed_tags() To get the allowed tags
1657 * @uses apply_filters() Calls 'bbp_allowed_tags' with the tags
1658 * @return string HTML allowed tags entity encoded.
1659 */
1660 function bbp_get_allowed_tags() {
1661 return apply_filters( 'bbp_get_allowed_tags', allowed_tags() );
1662 }
1663
1664 /** Errors & Messages *********************************************************/
1665
1666 /**
1667 * Display possible errors & messages inside a template file
1668 *
1669 * @since bbPress (r2688)
1670 *
1671 * @uses WP_Error bbPress::errors::get_error_codes() To get the error codes
1672 * @uses WP_Error bbPress::errors::get_error_data() To get the error data
1673 * @uses WP_Error bbPress::errors::get_error_messages() To get the error
1674 * messages
1675 * @uses is_wp_error() To check if it's a {@link WP_Error}
1676 */
1677 function bbp_template_notices() {
1678 global $bbp;
1679
1680 // Bail if no notices or errors
1681 if ( !bbp_has_errors() )
1682 return;
1683
1684 // Define local variable(s)
1685 $errors = $messages = array();
1686
1687 // Loop through notices
1688 foreach ( $bbp->errors->get_error_codes() as $code ) {
1689
1690 // Get notice severity
1691 $severity = $bbp->errors->get_error_data( $code );
1692
1693 // Loop through notices and separate errors from messages
1694 foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
1695 if ( 'message' == $severity ) {
1696 $messages[] = $error;
1697 } else {
1698 $errors[] = $error;
1699 }
1700 }
1701 }
1702
1703 // Display errors first...
1704 if ( !empty( $errors ) ) : ?>
1705
1706 <div class="bbp-template-notice error">
1707 <p>
1708 <?php echo implode( "</p>\n<p>", $errors ); ?>
1709 </p>
1710 </div>
1711
1712 <?php endif;
1713
1714 // ...and messages last
1715 if ( !empty( $messages ) ) : ?>
1716
1717 <div class="bbp-template-notice">
1718 <p>
1719 <?php echo implode( "</p>\n<p>", $messages ); ?>
1720 </p>
1721 </div>
1722
1723 <?php endif;
1724 }
1725
1726 /** Login/logout/register/lost pass *******************************************/
1727
1728 /**
1729 * Output the logout link
1730 *
1731 * @since bbPress (r2827)
1732 *
1733 * @param string $redirect_to Redirect to url
1734 * @uses bbp_get_logout_link() To get the logout link
1735 */
1736 function bbp_logout_link( $redirect_to = '' ) {
1737 echo bbp_get_logout_link( $redirect_to );
1738 }
1739 /**
1740 * Return the logout link
1741 *
1742 * @since bbPress (r2827)
1743 *
1744 * @param string $redirect_to Redirect to url
1745 * @uses wp_logout_url() To get the logout url
1746 * @uses apply_filters() Calls 'bbp_get_logout_link' with the logout link and
1747 * redirect to url
1748 * @return string The logout link
1749 */
1750 function bbp_get_logout_link( $redirect_to = '' ) {
1751 return apply_filters( 'bbp_get_logout_link', '<a href="' . wp_logout_url( $redirect_to ) . '" class="button logout-link">' . __( 'Log Out', 'bbpress' ) . '</a>', $redirect_to );
1752 }
1753
1754 /** Title *********************************************************************/
1755
1756 /**
1757 * Custom page title for bbPress pages
1758 *
1759 * @since bbPress (r2788)
1760 *
1761 * @param string $title Optional. The title (not used).
1762 * @param string $sep Optional, default is '&raquo;'. How to separate the
1763 * various items within the page title.
1764 * @param string $seplocation Optional. Direction to display title, 'right'.
1765 * @uses bbp_is_single_user() To check if it's a user profile page
1766 * @uses bbp_is_single_user_edit() To check if it's a user profile edit page
1767 * @uses bbp_is_user_home() To check if the profile page is of the current user
1768 * @uses get_query_var() To get the user id
1769 * @uses get_userdata() To get the user data
1770 * @uses bbp_is_single_forum() To check if it's a forum
1771 * @uses bbp_get_forum_title() To get the forum title
1772 * @uses bbp_is_single_topic() To check if it's a topic
1773 * @uses bbp_get_topic_title() To get the topic title
1774 * @uses bbp_is_single_reply() To check if it's a reply
1775 * @uses bbp_get_reply_title() To get the reply title
1776 * @uses is_tax() To check if it's the tag page
1777 * @uses get_queried_object() To get the queried object
1778 * @uses bbp_is_single_view() To check if it's a view
1779 * @uses bbp_get_view_title() To get the view title
1780 * @uses apply_filters() Calls 'bbp_raw_title' with the title
1781 * @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title,
1782 * separator and separator location
1783 * @return string The tite
1784 */
1785 function bbp_title( $title = '', $sep = '&raquo;', $seplocation = '' ) {
1786
1787 // Store original title to compare
1788 $_title = $title;
1789
1790 /** Archives **************************************************************/
1791
1792 // Forum Archive
1793 if ( bbp_is_forum_archive() ) {
1794 $title = bbp_get_forum_archive_title();
1795
1796 // Topic Archive
1797 } elseif ( bbp_is_topic_archive() ) {
1798 $title = bbp_get_topic_archive_title();
1799
1800 /** Singles ***************************************************************/
1801
1802 // Forum page
1803 } elseif ( bbp_is_single_forum() ) {
1804 $title = sprintf( __( 'Forum: %s', 'bbpress' ), bbp_get_forum_title() );
1805
1806 // Topic page
1807 } elseif ( bbp_is_single_topic() ) {
1808 $title = sprintf( __( 'Topic: %s', 'bbpress' ), bbp_get_topic_title() );
1809
1810 // Replies
1811 } elseif ( bbp_is_single_reply() ) {
1812 $title = bbp_get_reply_title();
1813
1814 // Topic tag page (or edit)
1815 } elseif ( bbp_is_topic_tag() || bbp_is_topic_tag_edit() || get_query_var( 'bbp_topic_tag' ) ) {
1816 $term = get_queried_object();
1817 $title = sprintf( __( 'Topic Tag: %s', 'bbpress' ), $term->name );
1818
1819 /** Users *****************************************************************/
1820
1821 // Profile page
1822 } elseif ( bbp_is_single_user() ) {
1823
1824 // Current users profile
1825 if ( bbp_is_user_home() ) {
1826 $title = __( 'Your Profile', 'bbpress' );
1827
1828 // Other users profile
1829 } else {
1830 $userdata = get_userdata( get_query_var( 'bbp_user_id' ) );
1831 $title = sprintf( __( '%s\'s Profile', 'bbpress' ), $userdata->display_name );
1832 }
1833
1834 // Profile edit page
1835 } elseif ( bbp_is_single_user_edit() ) {
1836
1837 // Current users profile
1838 if ( bbp_is_user_home() ) {
1839 $title = __( 'Edit Your Profile', 'bbpress' );
1840
1841 // Other users profile
1842 } else {
1843 $userdata = get_userdata( get_query_var( 'bbp_user_id' ) );
1844 $title = sprintf( __( 'Edit %s\'s Profile', 'bbpress' ), $userdata->display_name );
1845 }
1846
1847 /** Views *****************************************************************/
1848
1849 // Views
1850 } elseif ( bbp_is_single_view() ) {
1851 $title = sprintf( __( 'View: %s', 'bbpress' ), bbp_get_view_title() );
1852 }
1853
1854 // Filter the raw title
1855 $title = apply_filters( 'bbp_raw_title', $title, $sep, $seplocation );
1856
1857 // Compare new title with original title
1858 if ( $title == $_title )
1859 return $title;
1860
1861 // Temporary separator, for accurate flipping, if necessary
1862 $t_sep = '%WP_TITILE_SEP%';
1863 $prefix = '';
1864
1865 if ( !empty( $title ) )
1866 $prefix = " $sep ";
1867
1868 // sep on right, so reverse the order
1869 if ( 'right' == $seplocation ) {
1870 $title_array = explode( $t_sep, $title );
1871 $title_array = array_reverse( $title_array );
1872 $title = implode( " $sep ", $title_array ) . $prefix;
1873
1874 // sep on left, do not reverse
1875 } else {
1876 $title_array = explode( $t_sep, $title );
1877 $title = $prefix . implode( " $sep ", $title_array );
1878 }
1879
1880 // Filter and return
1881 return apply_filters( 'bbp_title', $title, $sep, $seplocation );
1882 }
1883
1884 ?>
1885