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

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