PluginProbe
bbPress / 2.0.3
bbPress v2.0.3
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 2.2.2 All 71 releases
bbpress / bbp-includes / bbp-common-template.php

bbp-common-template.php in bbPress 2.0.3, at bbp-includes/bbp-common-template.php

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