PluginProbe
bbPress / 2.1
bbPress v2.1
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / bbp-includes / bbp-common-template.php

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

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