PluginProbe
bbPress / 2.0-beta-2b
bbPress v2.0-beta-2b
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-general-template.php

bbp-general-template.php in bbPress 2.0-beta-2b, at bbp-includes/bbp-general-template.php

1,483 lines 42.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress General Template Tags
5 *
6 * @package bbPress
7 * @subpackage TemplateTags
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Add-on Actions ************************************************************/
14
15 /**
16 * Add our custom head action to wp_head
17 *
18 * @since bbPress (r2464)
19 *
20 * @uses do_action() Calls 'bbp_head'
21 */
22 function bbp_head() {
23 do_action( 'bbp_head' );
24 }
25
26 /**
27 * Add our custom head action to wp_head
28 *
29 * @since bbPress (r2464)
30 *
31 * @uses do_action() Calls 'bbp_footer'
32 */
33 function bbp_footer() {
34 do_action( 'bbp_footer' );
35 }
36
37 /** is_ ***********************************************************************/
38
39 /**
40 * Check if current page is a bbPress forum
41 *
42 * @since bbPress (r2549)
43 *
44 * @param int $post_id Possible post_id to check
45 * @uses bbp_get_forum_post_type() To get the forum post type
46 * @uses is_singular() To check if it's the single post page
47 * @uses get_post_field() To get the post type of the post id
48 * @return bool True if it's a forum page, false if not
49 */
50 function bbp_is_forum( $post_id = 0 ) {
51 global $bbp, $wp_query;
52
53 if ( empty( $post_id ) ) {
54
55 if ( is_singular( bbp_get_forum_post_type() ) )
56 return true;
57
58 if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_forum_post_type() === $wp_query->query_vars['post_type'] ) )
59 return true;
60
61 if ( isset( $bbp->forum_query->post->post_type ) && ( bbp_get_forum_post_type() === $bbp->forum_query->post->post_type ) )
62 return true;
63
64 if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_forum_post_type() === $_GET['post_type'] ) )
65 return true;
66
67 } elseif ( !empty( $post_id ) && ( bbp_get_forum_post_type() == get_post_field( 'post_type', $post_id ) ) )
68 return true;
69
70 return false;
71 }
72
73 /**
74 * Check if current page is a bbPress topic
75 *
76 * @since bbPress (r2549)
77 *
78 * @param int $post_id Possible post_id to check
79 * @uses bbp_is_topic_edit() To return false if it's a topic edit page
80 * @uses bbp_get_topic_post_type() To get the topic post type
81 * @uses is_singular() To check if it's the single post page
82 * @uses get_post_field() To get the post type of the post id
83 * @return bool True if it's a topic page, false if not
84 */
85 function bbp_is_topic( $post_id = 0 ) {
86 global $bbp, $wp_query;
87
88 // Return false if it's a edit topic page
89 if ( bbp_is_topic_edit() )
90 return false;
91
92 if ( empty( $post_id ) ) {
93
94 if ( is_singular( bbp_get_topic_post_type() ) )
95 return true;
96
97 if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_topic_post_type() === $wp_query->query_vars['post_type'] ) )
98 return true;
99
100 if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_topic_post_type() === $_GET['post_type'] ) )
101 return true;
102
103 } elseif ( !empty( $post_id ) && ( bbp_get_topic_post_type() == get_post_field( 'post_type', $post_id ) ) )
104 return true;
105
106 return false;
107 }
108
109 /**
110 * Check if current page is a topic edit page
111 *
112 * @since bbPress (r2753)
113 *
114 * @uses WP_Query Checks if WP_Query::bbp_is_topic_edit is true
115 * @return bool True if it's the topic edit page, false if not
116 */
117 function bbp_is_topic_edit() {
118 global $wp_query;
119
120 if ( !empty( $wp_query->bbp_is_topic_edit ) && $wp_query->bbp_is_topic_edit == true )
121 return true;
122
123 return false;
124 }
125
126 /**
127 * Check if current page is a topic merge page
128 *
129 * @since bbPress (r2756)
130 *
131 * @uses bbp_is_topic_edit() To check if it's a topic edit page
132 * @return bool True if it's the topic merge page, false if not
133 */
134 function bbp_is_topic_merge() {
135
136 if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'merge' == $_GET['action'] ) )
137 return true;
138
139 return false;
140 }
141
142 /**
143 * Check if current page is a topic split page
144 *
145 * @since bbPress (r2756)
146 *
147 * @uses bbp_is_topic_edit() To check if it's a topic edit page
148 * @return bool True if it's the topic split page, false if not
149 */
150 function bbp_is_topic_split() {
151
152 if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'split' == $_GET['action'] ) )
153 return true;
154
155 return false;
156 }
157
158 /**
159 * Check if current page is a bbPress reply
160 *
161 * @since bbPress (r2549)
162 *
163 * @param int $post_id Possible post_id to check
164 * @uses bbp_is_reply_edit() To return false if it's a reply edit page
165 * @uses bbp_get_reply_post_type() To get the reply post type
166 * @uses is_singular() To check if it's the single post page
167 * @uses get_post_field() To get the post type of the post id
168 * @return bool True if it's a reply page, false if not
169 */
170 function bbp_is_reply( $post_id = 0 ) {
171 global $bbp, $wp_query;
172
173 // Return false if it's a edit reply page
174 if ( bbp_is_reply_edit() )
175 return false;
176
177 if ( empty( $post_id ) ) {
178
179 if ( is_singular( bbp_get_reply_post_type() ) )
180 return true;
181
182 if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_reply_post_type() === $wp_query->query_vars['post_type'] ) )
183 return true;
184
185 if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_reply_post_type() === $_GET['post_type'] ) )
186 return true;
187
188 } elseif ( !empty( $post_id ) && ( bbp_get_reply_post_type() == get_post_field( 'post_type', $post_id ) ) )
189 return true;
190
191 return false;
192 }
193
194 /**
195 * Check if current page is a reply edit page
196 *
197 * @since bbPress (r2753)
198 *
199 * @uses WP_Query Checks if WP_Query::bbp_is_reply_edit is true
200 * @return bool True if it's the reply edit page, false if not
201 */
202 function bbp_is_reply_edit() {
203 global $wp_query;
204
205 if ( !empty( $wp_query->bbp_is_reply_edit ) && ( true == $wp_query->bbp_is_reply_edit ) )
206 return true;
207
208 return false;
209 }
210
211 /**
212 * Check if current page is a bbPress user's favorites page (profile page)
213 *
214 * @since bbPress (r2652)
215 *
216 * @param bool $query_name_check Optional. Check the query name
217 * (_bbp_query_name query var), if it is
218 * 'bbp_user_profile_favorites' or not. Defaults
219 * to true.
220 * @uses bbp_is_user_profile_page() To check if it's the user profile page
221 * @uses bbp_get_query_name() To get the query name
222 * @return bool True if it's the favorites page, false if not
223 */
224 function bbp_is_favorites( $query_name_check = true ) {
225 if ( !bbp_is_user_profile_page() )
226 return false;
227
228 if ( !empty( $query_name_check ) && ( !bbp_is_query_name( 'bbp_user_profile_favorites' ) ) )
229 return false;
230
231 return true;
232 }
233
234 /**
235 * Check if current page is a bbPress user's subscriptions page (profile page)
236 *
237 * @since bbPress (r2652)
238 *
239 * @param bool $query_name_check Optional. Check the query name
240 * (_bbp_query_name query var), if it is
241 * 'bbp_user_profile_favorites' or not. Defaults
242 * to true.
243 * @uses bbp_is_user_profile_page() To check if it's the user profile page
244 * @uses bbp_get_query_name() To get the query name
245 * @return bool True if it's the subscriptions page, false if not
246 */
247 function bbp_is_subscriptions( $query_name_check = true ) {
248 if ( !bbp_is_user_profile_page() )
249 return false;
250
251 if ( !empty( $query_name_check ) && ( !bbp_is_query_name( 'bbp_user_profile_subscriptions' ) ) )
252 return false;
253
254 return true;
255 }
256
257 /**
258 * Check if current page shows the topics created by a bbPress user (profile
259 * page)
260 *
261 * @since bbPress (r2688)
262 *
263 * @param bool $query_name_check Optional. Check the query name
264 * (_bbp_query_name query var), if it is
265 * 'bbp_user_profile_favorites' or not. Defaults
266 * to true.
267 * @uses bbp_is_user_profile_page() To check if it's the user profile page
268 * @uses bbp_get_query_name() To get the query name
269 * @return bool True if it's the topics created page, false if not
270 */
271 function bbp_is_topics_created( $query_name_check = true ) {
272 if ( !bbp_is_user_profile_page() )
273 return false;
274
275 if ( !empty( $query_name_check ) && ( !bbp_is_query_name( 'bbp_user_profile_topics_created' ) ) )
276 return false;
277
278 return true;
279 }
280
281 /**
282 * Check if current page is the currently logged in users author page
283 *
284 * @since bbPress (r2688)
285 *
286 * @uses bbPres Checks if bbPress::displayed_user is set and if
287 * bbPress::displayed_user::ID equals bbPress::current_user::ID
288 * or not
289 * @return bool True if it's the user's home, false if not
290 */
291 function bbp_is_user_home() {
292 global $bbp;
293
294 if ( !isset( $bbp->displayed_user ) )
295 return false;
296
297 return $bbp->current_user->ID == $bbp->displayed_user->ID;
298 }
299
300 /**
301 * Check if current page is a user profile page
302 *
303 * @since bbPress (r2688)
304 *
305 * @uses WP_Query Checks if WP_Query::bbp_is_user_profile_page is set to true
306 * @return bool True if it's a user's profile page, false if not
307 */
308 function bbp_is_user_profile_page() {
309 global $wp_query;
310
311 if ( !empty( $wp_query->bbp_is_user_profile_page ) && ( true == $wp_query->bbp_is_user_profile_page ) )
312 return true;
313
314 return false;
315 }
316
317 /**
318 * Check if current page is a user profile edit page
319 *
320 * @since bbPress (r2688)
321 *
322 * @uses WP_Query Checks if WP_Query::bbp_is_user_profile_edit is set to true
323 * @return bool True if it's a user's profile edit page, false if not
324 */
325 function bbp_is_user_profile_edit() {
326 global $wp_query;
327
328 if ( !empty( $wp_query->bbp_is_user_profile_edit ) && ( true == $wp_query->bbp_is_user_profile_edit ) )
329 return true;
330
331 return false;
332 }
333
334 /**
335 * Check if current page is a view page
336 *
337 * @since bbPress (r2789)
338 *
339 * @uses WP_Query Checks if WP_Query::bbp_is_view is true
340 * @return bool Is it a view page?
341 */
342 function bbp_is_view() {
343 global $wp_query;
344
345 if ( !empty( $wp_query->bbp_is_view ) && ( true == $wp_query->bbp_is_view ) )
346 return true;
347
348 return false;
349 }
350
351 /**
352 * Use the above is_() functions to output a body class for each scenario
353 *
354 * @since bbPress (r2926)
355 *
356 * @param array $wp_classes
357 * @param array $custom_classes
358 * @uses bbp_is_forum()
359 * @uses bbp_is_topic()
360 * @uses bbp_is_topic_edit()
361 * @uses bbp_is_topic_merge()
362 * @uses bbp_is_topic_split()
363 * @uses bbp_is_reply()
364 * @uses bbp_is_reply_edit()
365 * @uses bbp_is_reply_edit()
366 * @uses bbp_is_view()
367 * @uses bbp_is_user_profile_edit()
368 * @uses bbp_is_user_profile_page()
369 * @uses bbp_is_user_home()
370 * @uses bbp_is_subscriptions()
371 * @uses bbp_is_favorites()
372 * @uses bbp_is_topics_created()
373 * @return array Body Classes
374 */
375 function bbp_body_class( $wp_classes, $custom_classes = false ) {
376
377 $bbp_classes = array();
378
379 /** Components ********************************************************/
380
381 if ( bbp_is_forum() )
382 $bbp_classes[] = bbp_get_forum_post_type();
383
384 if ( bbp_is_topic() )
385 $bbp_classes[] = bbp_get_topic_post_type();
386
387 if ( bbp_is_topic_edit() )
388 $bbp_classes[] = bbp_get_topic_post_type() . '-edit';
389
390 if ( bbp_is_topic_merge() )
391 $bbp_classes[] = bbp_get_topic_post_type() . '-merge';
392
393 if ( bbp_is_topic_split() )
394 $bbp_classes[] = bbp_get_topic_post_type() . '-split';
395
396 if ( bbp_is_reply() )
397 $bbp_classes[] = bbp_get_reply_post_type();
398
399 if ( bbp_is_reply_edit() )
400 $bbp_classes[] = bbp_get_reply_post_type() . '-edit';
401
402 if ( bbp_is_view() )
403 $bbp_classes[] = 'bbp-view';
404
405 /** User **************************************************************/
406
407 if ( bbp_is_user_profile_edit() ) {
408 $bbp_classes[] = 'bbp-user-edit';
409 $bbp_classes[] = 'single';
410 $bbp_classes[] = 'singular';
411 }
412
413 if ( bbp_is_user_profile_page() ) {
414 $bbp_classes[] = 'bbp-user-page';
415 $bbp_classes[] = 'single';
416 $bbp_classes[] = 'singular';
417 }
418
419 if ( bbp_is_user_home() ) {
420 $bbp_classes[] = 'bbp-user-home';
421 $bbp_classes[] = 'single';
422 $bbp_classes[] = 'singular';
423 }
424
425 if ( bbp_is_topics_created() ) {
426 $bbp_classes[] = 'bbp-topics-created';
427 $bbp_classes[] = 'single';
428 $bbp_classes[] = 'singular';
429 }
430
431 if ( bbp_is_favorites() ) {
432 $bbp_classes[] = 'bbp-favorites';
433 $bbp_classes[] = 'single';
434 $bbp_classes[] = 'singular';
435 }
436
437 if ( bbp_is_subscriptions() ) {
438 $bbp_classes[] = 'bbp-subscriptions';
439 $bbp_classes[] = 'single';
440 $bbp_classes[] = 'singular';
441 }
442
443 /** Clean up **********************************************************/
444
445 // Add bbPress class if we are within a bbPress page
446 if ( !empty( $bbp_classes ) )
447 $bbp_classes[] = 'bbPress';
448
449 // Merge WP classes with bbPress classes
450 $classes = array_merge( (array) $bbp_classes, (array) $wp_classes );
451
452 // Remove any duplicates
453 $classes = array_unique( $classes );
454
455 return apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
456 }
457
458 /** Forms *********************************************************************/
459
460 /**
461 * Output the login form action url
462 *
463 * @since bbPress (r2815)
464 *
465 * @param string $url Pass a URL to redirect to
466 * @uses add_query_arg() To add a arg to the url
467 * @uses site_url() Toget the site url
468 * @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args
469 */
470 function bbp_wp_login_action( $args = '' ) {
471 $defaults = array (
472 'action' => '',
473 'context' => ''
474 );
475 $r = wp_parse_args( $args, $defaults );
476 extract( $r );
477
478 if ( !empty( $action ) )
479 $login_url = add_query_arg( array( 'action' => $action ), 'wp-login.php' );
480 else
481 $login_url = 'wp-login.php';
482
483 $login_url = site_url( $login_url, $context );
484
485 echo apply_filters( 'bbp_wp_login_action', $login_url, $args );
486 }
487
488 /**
489 * Output hidden request URI field for user forms.
490 *
491 * The referer link is the current Request URI from the server super global. The
492 * input name is '_wp_http_referer', in case you wanted to check manually.
493 *
494 * @since bbPress (r2815)
495 *
496 * @param string $url Pass a URL to redirect to
497 * @uses wp_get_referer() To get the referer
498 * @uses esc_attr() To escape the url
499 * @uses apply_filters() Calls 'bbp_redirect_to_field' with the referer field
500 * and url
501 */
502 function bbp_redirect_to_field( $url = '' ) {
503 // If no URL is passed, try to get the referer and then the request uri
504 if ( empty( $url ) && ( !$url = wp_get_referer() ) && ( !empty( $_SERVER['REQUEST_URI'] ) ) )
505 $url = $_SERVER['REQUEST_URI'];
506
507 // Remove loggedout query arg if it's there
508 $url = (string) esc_attr( remove_query_arg( 'loggedout', $url ) );
509
510 $referer_field = '<input type="hidden" name="redirect_to" value="' . $url . '" />';
511
512 echo apply_filters( 'bbp_redirect_to_field', $referer_field, $url );
513 }
514
515 /**
516 * Echo sanitized $_REQUEST value.
517 *
518 * Use the $input_type parameter to properly process the value. This
519 * ensures correct sanitization of the value for the receiving input.
520 *
521 * @since bbPress (r2815)
522 *
523 * @param string $request Name of $_REQUEST to look for
524 * @param string $input_type Type of input the value is for
525 * @uses bbp_get_sanitize_val() To sanitize the value
526 */
527 function bbp_sanitize_val( $request = '', $input_type = 'text' ) {
528 echo bbp_get_sanitize_val( $request, $input_type );
529 }
530 /**
531 * Return sanitized $_REQUEST value.
532 *
533 * Use the $input_type parameter to properly process the value. This
534 * ensures correct sanitization of the value for the receiving input.
535 *
536 * @since bbPress (r2815)
537 *
538 * @param string $request Name of $_REQUEST to look for
539 * @param string $input_type Type of input the value is for
540 * @uses esc_attr() To escape the string
541 * @uses apply_filters() Calls 'bbp_get_sanitize_val' with the sanitized
542 * value, request and input type
543 * @return string Sanitized value ready for screen display
544 */
545 function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) {
546
547 // Check that requested
548 if ( empty( $_REQUEST[$request] ) )
549 return false;
550
551 // Set request varaible
552 $pre_ret_val = $_REQUEST[$request];
553
554 // Treat different kinds of fields in different ways
555 switch ( $input_type ) {
556 case 'text' :
557 case 'textarea' :
558 $retval = esc_attr( stripslashes( $pre_ret_val ) );
559 break;
560
561 case 'password' :
562 case 'select' :
563 case 'radio' :
564 case 'checkbox' :
565 default :
566 $retval = esc_attr( $pre_ret_val );
567 break;
568 }
569
570 return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type );
571 }
572
573 /**
574 * Output the current tab index of a given form
575 *
576 * Use this function to handle the tab indexing of user facing forms within a
577 * template file. Calling this function will automatically increment the global
578 * tab index by default.
579 *
580 * @since bbPress (r2810)
581 *
582 * @param int $auto_increment Optional. Default true. Set to false to prevent
583 * increment
584 */
585 function bbp_tab_index( $auto_increment = true ) {
586 echo bbp_get_tab_index( $auto_increment );
587 }
588
589 /**
590 * Output the current tab index of a given form
591 *
592 * Use this function to handle the tab indexing of user facing forms
593 * within a template file. Calling this function will automatically
594 * increment the global tab index by default.
595 *
596 * @since bbPress (r2810)
597 *
598 * @uses apply_filters Allows return value to be filtered
599 * @param int $auto_increment Optional. Default true. Set to false to
600 * prevent the increment
601 * @return int $bbp->tab_index The global tab index
602 */
603 function bbp_get_tab_index( $auto_increment = true ) {
604 global $bbp;
605
606 if ( true === $auto_increment )
607 ++$bbp->tab_index;
608
609 return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
610 }
611
612 /**
613 * Output a select box allowing to pick which forum/topic a new topic/reply
614 * belongs in.
615 *
616 * Can be used for any post type, but is mostly used for topics and forums.
617 *
618 * @since bbPress (r2746)
619 *
620 * @param mixed $args See {@link bbp_get_dropdown()} for arguments
621 */
622 function bbp_dropdown( $args = '' ) {
623 echo bbp_get_dropdown( $args );
624 }
625 /**
626 * Output a select box allowing to pick which forum/topic a new
627 * topic/reply belongs in.
628 *
629 * @since bbPress (r2746)
630 *
631 * @param mixed $args The function supports these args:
632 * - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
633 * - selected: Selected ID, to not have any value as selected, pass
634 * anything smaller than 0 (due to the nature of select
635 * box, the first value would of course be selected -
636 * though you can have that as none (pass 'show_none' arg))
637 * - sort_column: Sort by? Defaults to 'menu_order, post_title'
638 * - child_of: Child of. Defaults to 0
639 * - post_status: Which all post_statuses to find in? Can be an array
640 * or CSV of publish, category, closed, private, spam,
641 * trash (based on post type) - if not set, these are
642 * automatically determined based on the post_type
643 * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
644 * all posts
645 * - walker: Which walker to use? Defaults to
646 * {@link BBP_Walker_Dropdown}
647 * - select_id: ID of the select box. Defaults to 'bbp_forum_id'
648 * - tab: Tabindex value. False or integer
649 * - options_only: Show only <options>? No <select>?
650 * - show_none: False or something like __( '(No Forum)', 'bbpress' ),
651 * will have value=""
652 * - none_found: False or something like
653 * __( 'No forums to post to!', 'bbpress' )
654 * - disable_categories: Disable forum categories and closed forums?
655 * Defaults to true. Only for forums and when
656 * the category option is displayed.
657 * @uses BBP_Walker_Dropdown() As the default walker to generate the
658 * dropdown
659 * @uses current_user_can() To check if the current user can read
660 * private forums
661 * @uses bbp_get_forum_post_type() To get the forum post type
662 * @uses bbp_get_topic_post_type() To get the topic post type
663 * @uses walk_page_dropdown_tree() To generate the dropdown using the
664 * walker
665 * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
666 * and args
667 * @return string The dropdown
668 */
669 function bbp_get_dropdown( $args = '' ) {
670 global $bbp;
671
672 /** Arguments *********************************************************/
673
674 $defaults = array (
675 'post_type' => bbp_get_forum_post_type(),
676 'selected' => 0,
677 'sort_column' => 'menu_order',
678 'child_of' => '0',
679 'numberposts' => -1,
680 'orderby' => 'menu_order',
681 'order' => 'ASC',
682 'walker' => '',
683
684 // Output-related
685 'select_id' => 'bbp_forum_id',
686 'tab' => bbp_get_tab_index(),
687 'options_only' => false,
688 'show_none' => false,
689 'none_found' => false,
690 'disable_categories' => true
691 );
692
693 $r = wp_parse_args( $args, $defaults );
694
695 if ( empty( $r['walker'] ) ) {
696 $r['walker'] = new BBP_Walker_Dropdown();
697 $r['walker']->tree_type = $r['post_type'];
698 }
699
700 // Force 0
701 if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 )
702 $r['selected'] = 0;
703
704 extract( $r );
705
706 // Unset the args not needed for WP_Query to avoid any possible conflicts.
707 // Note: walker and disable_categories are not unset
708 unset( $r['select_id'], $r['tab'], $r['options_only'], $r['show_none'], $r['none_found'] );
709
710 /** Post Status *******************************************************/
711
712 // Public
713 $post_stati[] = 'publish';
714
715 // Forums
716 if ( bbp_get_forum_post_type() == $post_type ) {
717
718 // Private forums
719 if ( current_user_can( 'read_private_forums' ) )
720 $post_stati[] = 'private';
721
722 // Hidden forums
723 if ( current_user_can( 'read_hidden_forums' ) )
724 $post_stati[] = $bbp->hidden_status_id;
725
726 // Topics
727 } else {
728 $r = bbp_exclude_forum_ids( $r );
729 }
730
731 // Setup the post statuses
732 $r['post_status'] = implode( ',', $post_stati );
733
734 /** Setup variables ***************************************************/
735
736 $name = esc_attr( $select_id );
737 $select_id = $name;
738 $tab = (int) $tab;
739 $retval = '';
740 $posts = get_posts( $r );
741
742 /** Drop Down *********************************************************/
743
744 // Items found
745 if ( !empty( $posts ) ) {
746 if ( empty( $options_only ) ) {
747 $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
748 $retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . '>' . "\n";
749 }
750
751 $retval .= !empty( $show_none ) ? "\t<option value=\"\" class=\"level-0\">" . $show_none . '</option>' : '';
752 $retval .= walk_page_dropdown_tree( $posts, 0, $r );
753
754 if ( empty( $options_only ) )
755 $retval .= '</select>';
756
757 // No items found - Display feedback if no custom message was passed
758 } elseif ( empty( $none_found ) ) {
759
760 // Switch the response based on post type
761 switch ( $post_type ) {
762
763 // Topics
764 case bbp_get_topic_post_type() :
765 $retval = __( 'No topics available', 'bbpress' );
766 break;
767
768 // Forums
769 case bbp_get_forum_post_type() :
770 $retval = __( 'No forums available', 'bbpress' );
771 break;
772
773 // Any other
774 default :
775 $retval = __( 'None available', 'bbpress' );
776 break;
777 }
778 }
779
780 return apply_filters( 'bbp_get_dropdown', $retval, $args );
781 }
782
783 /**
784 * Output the required hidden fields when creating/editing a topic
785 *
786 * @since bbPress (r2753)
787 *
788 * @uses bbp_is_topic_edit() To check if it's the topic edit page
789 * @uses wp_nonce_field() To generate hidden nonce fields
790 * @uses bbp_topic_id() To output the topic id
791 * @uses bbp_is_forum() To check if it's a forum page
792 * @uses bbp_forum_id() To output the forum id
793 */
794 function bbp_topic_form_fields() {
795
796 if ( bbp_is_topic_edit() ) : ?>
797
798 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" />
799 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
800
801 <?php
802
803 if ( current_user_can( 'unfiltered_html' ) )
804 wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false );
805
806 ?>
807
808 <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() );
809
810 else :
811
812 if ( bbp_is_forum() ) : ?>
813
814 <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
815
816 <?php endif; ?>
817
818 <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" />
819
820 <?php
821
822 if ( current_user_can( 'unfiltered_html' ) )
823 wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false );
824
825 ?>
826
827 <?php wp_nonce_field( 'bbp-new-topic' );
828
829 endif;
830 }
831
832 /**
833 * Output the required hidden fields when creating/editing a reply
834 *
835 * @since bbPress (r2753)
836 *
837 * @uses bbp_is_reply_edit() To check if it's the reply edit page
838 * @uses wp_nonce_field() To generate hidden nonce fields
839 * @uses bbp_reply_id() To output the reply id
840 * @uses bbp_topic_id() To output the topic id
841 * @uses bbp_forum_id() To output the forum id
842 */
843 function bbp_reply_form_fields() {
844
845 if ( bbp_is_reply_edit() ) { ?>
846
847 <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" />
848 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" />
849 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" />
850
851 <?php
852
853 if ( current_user_can( 'unfiltered_html' ) )
854 wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false );
855
856 ?>
857
858 <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() );
859
860 } else {
861
862 ?>
863
864 <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" />
865 <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
866 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
867 <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" />
868
869 <?php
870
871 if ( current_user_can( 'unfiltered_html' ) )
872 wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false );
873
874 ?>
875
876 <?php wp_nonce_field( 'bbp-new-reply' );
877 }
878 }
879
880 /**
881 * Output the required hidden fields when editing a user
882 *
883 * @since bbPress (r2690)
884 *
885 * @uses bbp_displayed_user_id() To output the displayed user id
886 * @uses wp_nonce_field() To generate a hidden nonce field
887 * @uses wp_referer_field() To generate a hidden referer field
888 */
889 function bbp_edit_user_form_fields() {
890 ?>
891
892 <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" />
893 <input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" />
894
895 <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() );
896 }
897
898 /**
899 * Merge topic form fields
900 *
901 * Output the required hidden fields when merging a topic
902 *
903 * @since bbPress (r2756)
904 *
905 * @uses wp_nonce_field() To generate a hidden nonce field
906 * @uses bbp_topic_id() To output the topic id
907 */
908 function bbp_merge_topic_form_fields() {
909 ?>
910
911 <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" />
912 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
913
914 <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() );
915 }
916
917 /**
918 * Split topic form fields
919 *
920 * Output the required hidden fields when splitting a topic
921 *
922 * @since bbPress (r2756)
923 *
924 * @uses wp_nonce_field() To generete a hidden nonce field
925 */
926 function bbp_split_topic_form_fields() {
927 ?>
928
929 <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" />
930 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" />
931
932 <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() );
933 }
934
935 /** Views *********************************************************************/
936
937 /**
938 * Output the view id
939 *
940 * @since bbPress (r2789)
941 *
942 * @param string $view Optional. View id
943 * @uses bbp_get_view_id() To get the view id
944 */
945 function bbp_view_id( $view = '' ) {
946 echo bbp_get_view_id( $view );
947 }
948
949 /**
950 * Get the view id
951 *
952 * If a view id is supplied, that is used. Otherwise the 'bbp_view'
953 * query var is checked for.
954 *
955 * @since bbPress (r2789)
956 *
957 * @param string $view Optional. View id.
958 * @uses sanitize_title() To sanitize the view id
959 * @uses get_query_var() To get the view id from query var 'bbp_view'
960 * @return bool|string ID on success, false on failure
961 */
962 function bbp_get_view_id( $view = '' ) {
963 global $bbp;
964
965 $view = !empty( $view ) ? sanitize_title( $view ) : get_query_var( 'bbp_view' );
966
967 if ( array_key_exists( $view, $bbp->views ) )
968 return $view;
969
970 return false;
971 }
972
973 /**
974 * Output the view name aka title
975 *
976 * @since bbPress (r2789)
977 *
978 * @param string $view Optional. View id
979 * @uses bbp_get_view_title() To get the view title
980 */
981 function bbp_view_title( $view = '' ) {
982 echo bbp_get_view_title( $view );
983 }
984
985 /**
986 * Get the view name aka title
987 *
988 * If a view id is supplied, that is used. Otherwise the bbp_view
989 * query var is checked for.
990 *
991 * @since bbPress (r2789)
992 *
993 * @param string $view Optional. View id
994 * @uses bbp_get_view_id() To get the view id
995 * @return bool|string Title on success, false on failure
996 */
997 function bbp_get_view_title( $view = '' ) {
998 global $bbp;
999
1000 if ( !$view = bbp_get_view_id( $view ) )
1001 return false;
1002
1003 return $bbp->views[$view]['title'];
1004 }
1005
1006 /**
1007 * Output the view url
1008 *
1009 * @since bbPress (r2789)
1010 *
1011 * @param string $view Optional. View id
1012 * @uses bbp_get_view_url() To get the view url
1013 */
1014 function bbp_view_url( $view = false ) {
1015 echo bbp_get_view_url( $view );
1016 }
1017 /**
1018 * Return the view url
1019 *
1020 * @since bbPress (r2789)
1021 *
1022 * @param string $view Optional. View id
1023 * @uses sanitize_title() To sanitize the view id
1024 * @uses home_url() To get blog home url
1025 * @uses add_query_arg() To add custom args to the url
1026 * @uses apply_filters() Calls 'bbp_get_view_url' with the view url,
1027 * used view id
1028 * @return string View url (or home url if the view was not found)
1029 */
1030 function bbp_get_view_url( $view = false ) {
1031 global $bbp, $wp_rewrite;
1032
1033 if ( !$view = bbp_get_view_id( $view ) )
1034 return home_url();
1035
1036 // Pretty permalinks
1037 if ( $wp_rewrite->using_permalinks() ) {
1038 $url = $wp_rewrite->root . $bbp->view_slug . '/' . $view;
1039 $url = home_url( user_trailingslashit( $url ) );
1040
1041 // Unpretty permalinks
1042 } else {
1043 $url = add_query_arg( array( 'bbp_view' => $view ), home_url( '/' ) );
1044 }
1045
1046 return apply_filters( 'bbp_get_view_link', $url, $view );
1047 }
1048
1049 /** Query *********************************************************************/
1050
1051 /**
1052 * Check the passed parameter against the current _bbp_query_name
1053 *
1054 * @since bbPress (r2980)
1055 *
1056 * @uses bbp_get_query_name() Get the query var '_bbp_query_name'
1057 * @return bool True if match, false if not
1058 */
1059 function bbp_is_query_name( $query_name ) {
1060
1061 // No empties
1062 if ( empty( $query_name ) )
1063 return false;
1064
1065 // Check if query var matches
1066 if ( bbp_get_query_name() == $query_name )
1067 return true;
1068
1069 // No match
1070 return false;
1071 }
1072
1073 /**
1074 * Get the '_bbp_query_name' setting
1075 *
1076 * @since bbPress (r2695)
1077 *
1078 * @uses get_query_var() To get the query var '_bbp_query_name'
1079 * @return string To return the query var value
1080 */
1081 function bbp_get_query_name() {
1082 return get_query_var( '_bbp_query_name' );
1083 }
1084
1085 /**
1086 * Set the '_bbp_query_name' setting to $name
1087 *
1088 * @since bbPress (r2692)
1089 *
1090 * @param string $name What to set the query var to
1091 * @uses set_query_var() To set the query var '_bbp_query_name'
1092 */
1093 function bbp_set_query_name( $name = '' ) {
1094 set_query_var( '_bbp_query_name', $name );
1095 }
1096
1097 /**
1098 * Used to clear the '_bbp_query_name' setting
1099 *
1100 * @since bbPress (r2692)
1101 *
1102 * @uses bbp_set_query_name() To set the query var '_bbp_query_name' value to ''
1103 */
1104 function bbp_reset_query_name() {
1105 bbp_set_query_name();
1106 }
1107
1108 /** Breadcrumbs ***************************************************************/
1109
1110 /**
1111 * Output the page title as a breadcrumb
1112 *
1113 * @since bbPress (r2589)
1114 *
1115 * @param string $sep Separator. Defaults to '&larr;'
1116 * @param bool $current_page Include the current item
1117 * @param bool $root Include the root page if one exists
1118 * @uses bbp_get_breadcrumb() To get the breadcrumb
1119 */
1120 function bbp_title_breadcrumb( $args = array() ) {
1121 echo bbp_get_breadcrumb( $args );
1122 }
1123
1124 /**
1125 * Output a breadcrumb
1126 *
1127 * @since bbPress (r2589)
1128 *
1129 * @param string $sep Separator. Defaults to '&larr;'
1130 * @param bool $current_page Include the current item
1131 * @param bool $root Include the root page if one exists
1132 * @uses bbp_get_breadcrumb() To get the breadcrumb
1133 */
1134 function bbp_breadcrumb( $args = array() ) {
1135 echo bbp_get_breadcrumb( $args );
1136 }
1137 /**
1138 * Return a breadcrumb ( forum -> topic -> reply )
1139 *
1140 * @since bbPress (r2589)
1141 *
1142 * @param string $sep Separator. Defaults to '&larr;'
1143 * @param bool $current_page Include the current item
1144 * @param bool $root Include the root page if one exists
1145 *
1146 * @uses get_post() To get the post
1147 * @uses bbp_get_forum_permalink() To get the forum link
1148 * @uses bbp_get_topic_permalink() To get the topic link
1149 * @uses bbp_get_reply_permalink() To get the reply link
1150 * @uses get_permalink() To get the permalink
1151 * @uses bbp_get_forum_post_type() To get the forum post type
1152 * @uses bbp_get_topic_post_type() To get the topic post type
1153 * @uses bbp_get_reply_post_type() To get the reply post type
1154 * @uses bbp_get_forum_title() To get the forum title
1155 * @uses bbp_get_topic_title() To get the topic title
1156 * @uses bbp_get_reply_title() To get the reply title
1157 * @uses get_the_title() To get the title
1158 * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs
1159 * @return string Breadcrumbs
1160 */
1161 function bbp_get_breadcrumb( $args = array() ) {
1162 global $bbp;
1163
1164 // Turn off breadcrumbs
1165 if ( apply_filters( 'bbp_no_breadcrumb', false ) )
1166 return;
1167
1168 // Parse args
1169 $defaults = array(
1170
1171 // HTML
1172 'before' => '<div class="bbp-breadcrumb"><p>',
1173 'after' => '</p></div>',
1174 'sep' => is_rtl() ? ' &lsaquo; ' : ' &rsaquo; ',
1175
1176 // Home
1177 'include_home' => true,
1178 'home_text' => ( $front = get_option( 'page_on_front' ) ) ? get_the_title( $front ) : __( 'Home' ),
1179
1180 // Forum root
1181 'include_root' => get_option( '_bbp_include_root' ),
1182 'root_text' => ( $page = get_page_by_path( $bbp->root_slug ) ) ? get_the_title( $page->ID ) : __( 'Forums', 'bbpress' ),
1183
1184 // Current
1185 'include_current' => true,
1186 );
1187 $r = wp_parse_args( $args, $defaults );
1188 extract( $r );
1189
1190 // Get post ancestors
1191 $ancestors = array_reverse( get_post_ancestors( get_the_ID() ) );
1192
1193 // Do we want to include a link to home?
1194 if ( !empty( $include_home ) )
1195 $breadcrumbs[] = '<a href="' . trailingslashit( home_url() ) . '" class="bbp-breadcrumb-home">' . $home_text . '</a>';
1196
1197 // Do we want to include a link to the forum root?
1198 if ( !empty( $include_root ) && ( !empty( $page ) && ( $front != $page->ID ) ) )
1199 $breadcrumbs[] = '<a href="' . trailingslashit( home_url( $bbp->root_slug ) ) . '" class="bbp-breadcrumb-root">' . $root_text . '</a>';
1200
1201 // Loop through parents
1202 foreach( $ancestors as $parent_id ) {
1203
1204 // Parents
1205 $parent = get_post( $parent_id );
1206
1207 // Switch through post_type to ensure correct filters are applied
1208 switch ( $parent->post_type ) {
1209 // Forum
1210 case bbp_get_forum_post_type() :
1211 $breadcrumbs[] = '<a href="' . bbp_get_forum_permalink( $parent->ID ) . '">' . bbp_get_forum_title( $parent->ID ) . '</a>';
1212 break;
1213
1214 // Topic
1215 case bbp_get_topic_post_type() :
1216 $breadcrumbs[] = '<a href="' . bbp_get_topic_permalink( $parent->ID ) . '">' . bbp_get_topic_title( $parent->ID ) . '</a>';
1217 break;
1218
1219 // Reply (Note: not in most themes)
1220 case bbp_get_reply_post_type() :
1221 $breadcrumbs[] = '<a href="' . bbp_get_reply_permalink( $parent->ID ) . '">' . bbp_get_reply_title( $parent->ID ) . '</a>';
1222 break;
1223
1224 // WordPress Post/Page/Other
1225 default :
1226 $breadcrumbs[] = '<a href="' . get_permalink( $parent->ID ) . '">' . get_the_title( $parent->ID ) . '</a>';
1227 break;
1228 }
1229 }
1230
1231 // Add current page to breadcrumb
1232 if ( true == $include_current )
1233 $breadcrumbs[] = '<span class="bbp-breadcrumb-current">' . get_the_title() . '</span>';
1234
1235 // Allow the separator of the breadcrumb to be easily changed
1236 $sep = apply_filters( 'bbp_breadcrumb_separator', $sep );
1237
1238 // Right to left support
1239 if ( is_rtl() )
1240 $breadcrumbs = apply_filters( 'bbp_breadcrumbs', array_reverse( $breadcrumbs ) );
1241
1242 // Build the trail
1243 $trail = !empty( $breadcrumbs ) ? $before . implode( $sep, $breadcrumbs ) . $after: '';
1244
1245 return apply_filters( 'bbp_get_breadcrumb', $trail );
1246 }
1247
1248 /** Topic Tags ***************************************************************/
1249
1250 /**
1251 * Output all of the allowed tags in HTML format with attributes.
1252 *
1253 * This is useful for displaying in the post area, which elements and
1254 * attributes are supported. As well as any plugins which want to display it.
1255 *
1256 * @since bbPress (r2780)
1257 *
1258 * @uses bbp_get_allowed_tags()
1259 */
1260 function bbp_allowed_tags() {
1261 echo bbp_get_allowed_tags();
1262 }
1263 /**
1264 * Display all of the allowed tags in HTML format with attributes.
1265 *
1266 * This is useful for displaying in the post area, which elements and
1267 * attributes are supported. As well as any plugins which want to display it.
1268 *
1269 * @since bbPress (r2780)
1270 *
1271 * @uses allowed_tags() To get the allowed tags
1272 * @uses apply_filters() Calls 'bbp_allowed_tags' with the tags
1273 * @return string HTML allowed tags entity encoded.
1274 */
1275 function bbp_get_allowed_tags() {
1276 return apply_filters( 'bbp_get_allowed_tags', allowed_tags() );
1277 }
1278
1279 /** Errors & Messages *********************************************************/
1280
1281 /**
1282 * Display possible errors & messages inside a template file
1283 *
1284 * @since bbPress (r2688)
1285 *
1286 * @uses WP_Error bbPress::errors::get_error_codes() To get the error codes
1287 * @uses WP_Error bbPress::errors::get_error_data() To get the error data
1288 * @uses WP_Error bbPress::errors::get_error_messages() To get the error
1289 * messages
1290 * @uses is_wp_error() To check if it's a {@link WP_Error}
1291 */
1292 function bbp_template_notices() {
1293 global $bbp;
1294
1295 // Bail if no notices or errors
1296 if ( !isset( $bbp->errors ) || !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() )
1297 return;
1298
1299 // Prevent debug notices
1300 $errors = $messages = array();
1301
1302 // Loop through notices
1303 foreach ( $bbp->errors->get_error_codes() as $code ) {
1304
1305 // Get notice severity
1306 $severity = $bbp->errors->get_error_data( $code );
1307
1308 // Loop through notices and separate errors from messages
1309 foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
1310 if ( 'message' == $severity ) {
1311 $messages[] = $error;
1312 } else {
1313 $errors[] = $error;
1314 }
1315 }
1316 }
1317
1318 // Display errors first...
1319 if ( !empty( $errors ) ) : ?>
1320
1321 <div class="bbp-template-notice error">
1322 <p>
1323 <?php echo implode( "</p>\n<p>", $errors ); ?>
1324 </p>
1325 </div>
1326
1327 <?php endif;
1328
1329 // ...and messages last
1330 if ( !empty( $messages ) ) : ?>
1331
1332 <div class="bbp-template-notice">
1333 <p>
1334 <?php echo implode( "</p>\n<p>", $messages ); ?>
1335 </p>
1336 </div>
1337
1338 <?php endif;
1339 }
1340
1341 /** Login/logout/register/lost pass *******************************************/
1342
1343 /**
1344 * Output the logout link
1345 *
1346 * @since bbPress (r2827)
1347 *
1348 * @param string $redirect_to Redirect to url
1349 * @uses bbp_get_logout_link() To get the logout link
1350 */
1351 function bbp_logout_link( $redirect_to = '' ) {
1352 echo bbp_get_logout_link( $redirect_to );
1353 }
1354 /**
1355 * Return the logout link
1356 *
1357 * @since bbPress (r2827)
1358 *
1359 * @param string $redirect_to Redirect to url
1360 * @uses wp_logout_url() To get the logout url
1361 * @uses apply_filters() Calls 'bbp_get_logout_link' with the logout link and
1362 * redirect to url
1363 * @return string The logout link
1364 */
1365 function bbp_get_logout_link( $redirect_to = '' ) {
1366 return apply_filters( 'bbp_get_logout_link', '<a href="' . wp_logout_url( $redirect_to ) . '" class="button logout-link">' . __( 'Log Out', 'bbpress' ) . '</a>', $redirect_to );
1367 }
1368
1369 /** Title *********************************************************************/
1370
1371 /**
1372 * Custom page title for bbPress pages
1373 *
1374 * @since bbPress (r2788)
1375 *
1376 * @param string $title Optional. The title (not used).
1377 * @param string $sep Optional, default is '&raquo;'. How to separate the
1378 * various items within the page title.
1379 * @param string $seplocation Optional. Direction to display title, 'right'.
1380 * @uses bbp_is_user_profile_page() To check if it's a user profile page
1381 * @uses bbp_is_user_profile_edit() To check if it's a user profile edit page
1382 * @uses bbp_is_user_home() To check if the profile page is of the current user
1383 * @uses get_query_var() To get the user id
1384 * @uses get_userdata() To get the user data
1385 * @uses bbp_is_forum() To check if it's a forum
1386 * @uses bbp_get_forum_title() To get the forum title
1387 * @uses bbp_is_topic() To check if it's a topic
1388 * @uses bbp_get_topic_title() To get the topic title
1389 * @uses bbp_is_reply() To check if it's a reply
1390 * @uses bbp_get_reply_title() To get the reply title
1391 * @uses is_tax() To check if it's the tag page
1392 * @uses get_queried_object() To get the queried object
1393 * @uses bbp_is_view() To check if it's a view
1394 * @uses bbp_get_view_title() To get the view title
1395 * @uses apply_filters() Calls 'bbp_raw_title' with the title
1396 * @uses apply_filters() Calls 'bbp_profile_page_wp_title' with the title,
1397 * separator and separator location
1398 * @return string The tite
1399 */
1400 function bbp_title( $title = '', $sep = '&raquo;', $seplocation = '' ) {
1401 global $bbp;
1402
1403 $_title = $title;
1404
1405 // Profile page
1406 if ( bbp_is_user_profile_page() ) {
1407
1408 if ( bbp_is_user_home() ) {
1409 $title = __( 'Your Profile', 'bbpress' );
1410 } else {
1411 $userdata = get_userdata( get_query_var( 'bbp_user_id' ) );
1412 $title = sprintf( __( '%s\'s Profile', 'bbpress' ), $userdata->display_name );
1413 }
1414
1415 // Profile edit page
1416 } elseif ( bbp_is_user_profile_edit() ) {
1417
1418 if ( bbp_is_user_home() ) {
1419 $title = __( 'Edit Your Profile', 'bbpress' );
1420 } else {
1421 $userdata = get_userdata( get_query_var( 'bbp_user_id' ) );
1422 $title = sprintf( __( 'Edit %s\'s Profile', 'bbpress' ), $userdata->display_name );
1423 }
1424
1425 // Forum page
1426 } elseif ( bbp_is_forum() ) {
1427
1428 $title = sprintf( __( 'Forum: %s', 'bbpress' ), bbp_get_forum_title() );
1429
1430 // Topic page
1431 } elseif ( bbp_is_topic() ) {
1432
1433 $title = sprintf( __( 'Topic: %s', 'bbpress' ), bbp_get_topic_title() );
1434
1435 // Replies
1436 } elseif ( bbp_is_reply() ) {
1437
1438 // Normal reply titles already have "Reply To: ", so we shouldn't add our own
1439 $title = bbp_get_reply_title();
1440
1441 // Topic tag page
1442 } elseif ( is_tax( $bbp->topic_tag_id ) ) {
1443
1444 if ( function_exists( 'get_queried_object' ) ) {
1445 $term = get_queried_object();
1446 $title = sprintf( __( 'Topic Tag: %s', 'bbpress' ), $term->name );
1447 }
1448
1449 // Views
1450 } elseif ( bbp_is_view() ) {
1451
1452 $title = sprintf( __( 'View: %s', 'bbpress' ), bbp_get_view_title() );
1453
1454 }
1455
1456 $title = apply_filters( 'bbp_raw_title', $title, $sep, $seplocation );
1457
1458 if ( $title == $_title )
1459 return $title;
1460
1461 // Temporary separator, for accurate flipping, if necessary
1462 $t_sep = '%WP_TITILE_SEP%';
1463 $prefix = '';
1464
1465 if ( !empty( $title ) )
1466 $prefix = " $sep ";
1467
1468 // Determines position of the separator and direction of the breadcrumb
1469 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
1470 $title_array = explode( $t_sep, $title );
1471 $title_array = array_reverse( $title_array );
1472 $title = implode( " $sep ", $title_array ) . $prefix;
1473 } else {
1474 $title_array = explode( $t_sep, $title );
1475 $title = $prefix . implode( " $sep ", $title_array );
1476 }
1477
1478 // Filter and return
1479 return apply_filters( 'bbp_title', $title, $sep, $seplocation );
1480 }
1481
1482 ?>
1483