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-common-template.php

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

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