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

bbp-common-template.php in bbPress 2.0-beta-3, at bbp-includes/bbp-common-template.php

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