PluginProbe
bbPress / 2.0-rc-2
bbPress v2.0-rc-2
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-2, at bbp-includes/bbp-common-template.php

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