PluginProbe
bbPress / 2.1-beta-1
bbPress v2.1-beta-1
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.1-beta-1, at bbp-includes/bbp-common-template.php

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