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

template.php in bbPress trunk, at includes/common/template.php

2,912 lines 75.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 * Common template tags are ones that are used by more than one component, like
7 * forums, topics, replies, users, topic tags, etc...
8 */
9
10 // Exit if accessed directly
11 defined( 'ABSPATH' ) || exit;
12
13 /** URLs **********************************************************************/
14
15 /**
16 * Output the forum URL.
17 *
18 * @since 2.1.0 bbPress (r3979)
19 *
20 * @param string $path Additional path with leading slash.
21 */
22 function bbp_forums_url( $path = '/' ) {
23 echo esc_url( bbp_get_forums_url( $path ) );
24 }
25
26 /**
27 * Return the forum URL.
28 *
29 * @since 2.1.0 bbPress (r3979)
30 *
31 * @param string $path Additional path with leading slash.
32 */
33 function bbp_get_forums_url( $path = '/' ) {
34 return home_url( bbp_get_root_slug() . $path );
35 }
36
37 /**
38 * Output the forum URL.
39 *
40 * @since 2.1.0 bbPress (r3979)
41 *
42 * @param string $path Additional path with leading slash.
43 */
44 function bbp_topics_url( $path = '/' ) {
45 echo esc_url( bbp_get_topics_url( $path ) );
46 }
47
48 /**
49 * Return the forum URL.
50 *
51 * @since 2.1.0 bbPress (r3979)
52 *
53 * @param string $path Additional path with leading slash.
54 *
55 * @return The URL to the topics archive.
56 */
57 function bbp_get_topics_url( $path = '/' ) {
58 return home_url( bbp_get_topic_archive_slug() . $path );
59 }
60
61 /** Add-on Actions ************************************************************/
62
63 /**
64 * Add our custom head action to wp_head.
65 *
66 * @since 2.0.0 bbPress (r2464)
67 */
68 function bbp_head() {
69 do_action( 'bbp_head' );
70 }
71
72 /**
73 * Add our custom footer action to wp_footer.
74 *
75 * @since 2.0.0 bbPress (r2464)
76 */
77 function bbp_footer() {
78 do_action( 'bbp_footer' );
79 }
80
81 /** is_ ***********************************************************************/
82
83 /**
84 * Check if current site is public.
85 *
86 * @since 2.0.0 bbPress (r3398)
87 *
88 * @param int $site_id
89 *
90 * @return bool True if site is public, false if private.
91 */
92 function bbp_is_site_public( $site_id = 0 ) {
93
94 // Get the current site ID
95 if ( empty( $site_id ) ) {
96 $site_id = get_current_blog_id();
97 }
98
99 // Get the site visibility setting
100 $public = is_multisite()
101 ? get_blog_option( $site_id, 'blog_public', 1 )
102 : get_option( 'blog_public', 1 );
103
104 // Filter & return
105 return (bool) apply_filters( 'bbp_is_site_public', $public, $site_id );
106 }
107
108 /**
109 * Check if current page is a bbPress forum.
110 *
111 * @since 2.0.0 bbPress (r2549)
112 *
113 * @param int $post_id Possible post_id to check.
114 *
115 * @return bool True if it's a forum page, false if not.
116 */
117 function bbp_is_forum( $post_id = 0 ) {
118
119 // Assume false
120 $retval = false;
121
122 // Supplied ID is a forum
123 if ( ! empty( $post_id ) && ( bbp_get_forum_post_type() === get_post_type( $post_id ) ) ) {
124 $retval = true;
125 }
126
127 // Filter & return
128 return (bool) apply_filters( 'bbp_is_forum', $retval, $post_id );
129 }
130
131 /**
132 * Check if we are viewing a forum archive.
133 *
134 * @since 2.0.0 bbPress (r3251)
135 *
136 * @return bool
137 */
138 function bbp_is_forum_archive() {
139
140 // Default to false
141 $retval = false;
142
143 // Get the main query global
144 $wp_query = bbp_get_wp_query();
145
146 // In forum archive
147 if ( is_post_type_archive( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_forum_archive' ) || ! empty( $wp_query->bbp_show_topics_on_root ) ) {
148 $retval = true;
149 }
150
151 // Filter & return
152 return (bool) apply_filters( 'bbp_is_forum_archive', $retval );
153 }
154
155 /**
156 * Viewing a single forum.
157 *
158 * @since 2.0.0 bbPress (r3338)
159 *
160 * @return bool
161 */
162 function bbp_is_single_forum() {
163
164 // Assume false
165 $retval = false;
166
167 // Edit is not a single forum
168 if ( bbp_is_forum_edit() ) {
169 return false;
170 }
171
172 // Single and a match
173 if ( is_singular( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_single_forum' ) ) {
174 $retval = true;
175 }
176
177 // Filter & return
178 return (bool) apply_filters( 'bbp_is_single_forum', $retval );
179 }
180
181 /**
182 * Check if current page is a forum edit page.
183 *
184 * @since 2.1.0 bbPress (r3553)
185 *
186 * @global string $pagenow The filename of the current screen.
187 *
188 * @return bool True if it's the forum edit page, false if not.
189 */
190 function bbp_is_forum_edit() {
191 global $pagenow;
192
193 // Assume false
194 $retval = false;
195
196 // Get the main query global
197 $wp_query = bbp_get_wp_query();
198
199 // Check query
200 if ( ! empty( $wp_query->bbp_is_forum_edit ) && ( true === $wp_query->bbp_is_forum_edit ) ) {
201 $retval = true;
202
203 // Editing in admin
204 } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_forum_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
205 $retval = true;
206 }
207
208 // Filter & return
209 return (bool) apply_filters( 'bbp_is_forum_edit', $retval );
210 }
211
212 /**
213 * Check if current page is a bbPress topic.
214 *
215 * @since 2.0.0 bbPress (r2549)
216 *
217 * @param int $post_id Possible post_id to check.
218 *
219 * @return bool True if it's a topic page, false if not.
220 */
221 function bbp_is_topic( $post_id = 0 ) {
222
223 // Assume false
224 $retval = false;
225
226 // Supplied ID is a topic
227 if ( ! empty( $post_id ) && ( bbp_get_topic_post_type() === get_post_type( $post_id ) ) ) {
228 $retval = true;
229 }
230
231 // Filter & return
232 return (bool) apply_filters( 'bbp_is_topic', $retval, $post_id );
233 }
234
235 /**
236 * Viewing a single topic.
237 *
238 * @since 2.0.0 bbPress (r3338)
239 *
240 * @return bool
241 */
242 function bbp_is_single_topic() {
243
244 // Assume false
245 $retval = false;
246
247 // Edit is not a single topic
248 if ( bbp_is_topic_edit() ) {
249 return false;
250 }
251
252 // Single and a match
253 if ( is_singular( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_single_topic' ) ) {
254 $retval = true;
255 }
256
257 // Filter & return
258 return (bool) apply_filters( 'bbp_is_single_topic', $retval );
259 }
260
261 /**
262 * Check if we are viewing a topic archive.
263 *
264 * @since 2.0.0 bbPress (r3251)
265 *
266 * @return bool
267 */
268 function bbp_is_topic_archive() {
269
270 // Default to false
271 $retval = false;
272
273 // In topic archive
274 if ( is_post_type_archive( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_topic_archive' ) ) {
275 $retval = true;
276 }
277
278 // Filter & return
279 return (bool) apply_filters( 'bbp_is_topic_archive', $retval );
280 }
281
282 /**
283 * Check if current page is a topic edit page.
284 *
285 * @since 2.0.0 bbPress (r2753)
286 *
287 * @global string $pagenow The filename of the current screen.
288 *
289 * @return bool True if it's the topic edit page, false if not.
290 */
291 function bbp_is_topic_edit() {
292 global $pagenow;
293
294 // Assume false
295 $retval = false;
296
297 // Get the main query global
298 $wp_query = bbp_get_wp_query();
299
300 // Check query
301 if ( ! empty( $wp_query->bbp_is_topic_edit ) && ( true === $wp_query->bbp_is_topic_edit ) ) {
302 $retval = true;
303
304 // Editing in admin
305 } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_topic_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
306 $retval = true;
307 }
308
309 // Filter & return
310 return (bool) apply_filters( 'bbp_is_topic_edit', $retval );
311 }
312
313 /**
314 * Check if current page is a topic merge page.
315 *
316 * @since 2.0.0 bbPress (r2756)
317 *
318 * @return bool True if it's the topic merge page, false if not.
319 */
320 function bbp_is_topic_merge() {
321
322 // Assume false
323 $retval = false;
324
325 // Check topic edit and GET params
326 if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'merge' === $_GET['action'] ) ) {
327 return true;
328 }
329
330 // Filter & return
331 return (bool) apply_filters( 'bbp_is_topic_merge', $retval );
332 }
333
334 /**
335 * Check if current page is a topic split page.
336 *
337 * @since 2.0.0 bbPress (r2756)
338 *
339 * @return bool True if it's the topic split page, false if not.
340 */
341 function bbp_is_topic_split() {
342
343 // Assume false
344 $retval = false;
345
346 // Check topic edit and GET params
347 if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'split' === $_GET['action'] ) ) {
348 $retval = true;
349 }
350
351 // Filter & return
352 return (bool) apply_filters( 'bbp_is_topic_split', $retval );
353 }
354
355 /**
356 * Check if the current page is a topic tag.
357 *
358 * @since 2.0.0 bbPress (r3311)
359 *
360 * @return bool True if it's a topic tag, false if not.
361 */
362 function bbp_is_topic_tag() {
363
364 // Bail if topic-tags are off
365 if ( ! bbp_allow_topic_tags() ) {
366 return false;
367 }
368
369 // Return false if editing a topic tag
370 if ( bbp_is_topic_tag_edit() ) {
371 return false;
372 }
373
374 // Assume false
375 $retval = false;
376
377 // Check tax and query vars
378 if ( is_tax( bbp_get_topic_tag_tax_id() ) || ! empty( bbpress()->topic_query->is_tax ) || get_query_var( 'bbp_topic_tag' ) ) {
379 $retval = true;
380 }
381
382 // Filter & return
383 return (bool) apply_filters( 'bbp_is_topic_tag', $retval );
384 }
385
386 /**
387 * Check if the current page is editing a topic tag.
388 *
389 * @since 2.0.0 bbPress (r3346)
390 *
391 * @global string $pagenow The filename of the current screen.
392 * @global string $taxnow The taxonomy of the current screen.
393 *
394 * @return bool True if editing a topic tag, false if not.
395 */
396 function bbp_is_topic_tag_edit() {
397 global $pagenow, $taxnow;
398
399 // Bail if topic-tags are off
400 if ( ! bbp_allow_topic_tags() ) {
401 return false;
402 }
403
404 // Assume false
405 $retval = false;
406
407 // Get the main query global
408 $wp_query = bbp_get_wp_query();
409
410 // Check query
411 if ( ! empty( $wp_query->bbp_is_topic_tag_edit ) && ( true === $wp_query->bbp_is_topic_tag_edit ) ) {
412 $retval = true;
413
414 // Editing in admin
415 } elseif ( is_admin() && ( 'edit-tags.php' === $pagenow ) && ( bbp_get_topic_tag_tax_id() === $taxnow ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
416 $retval = true;
417 }
418
419 // Filter & return
420 return (bool) apply_filters( 'bbp_is_topic_tag_edit', $retval );
421 }
422
423 /**
424 * Check if the current post type is one that comes with bbPress.
425 *
426 * @since 2.0.0 bbPress (r3311)
427 *
428 * @param mixed $the_post Optional. Post object or post ID.
429 *
430 * @return bool
431 */
432 function bbp_is_custom_post_type( $the_post = false ) {
433
434 // Assume false
435 $retval = false;
436 $type = get_post_type( $the_post );
437 $types = array(
438 bbp_get_forum_post_type(),
439 bbp_get_topic_post_type(),
440 bbp_get_reply_post_type(),
441 );
442
443 // Viewing one of the bbPress post types
444 if ( in_array( $type, $types, true ) ) {
445 $retval = true;
446 }
447
448 // Filter & return
449 return (bool) apply_filters( 'bbp_is_custom_post_type', $retval, $the_post );
450 }
451
452 /**
453 * Check if current page is a bbPress reply.
454 *
455 * @since 2.0.0 bbPress (r2549)
456 *
457 * @param int $post_id Possible post_id to check.
458 *
459 * @return bool True if it's a reply page, false if not.
460 */
461 function bbp_is_reply( $post_id = 0 ) {
462
463 // Assume false
464 $retval = false;
465
466 // Supplied ID is a reply
467 if ( ! empty( $post_id ) && ( bbp_get_reply_post_type() === get_post_type( $post_id ) ) ) {
468 $retval = true;
469 }
470
471 // Filter & return
472 return (bool) apply_filters( 'bbp_is_reply', $retval, $post_id );
473 }
474
475 /**
476 * Check if current page is a reply edit page.
477 *
478 * @since 2.0.0 bbPress (r2753)
479 *
480 * @global string $pagenow The filename of the current screen.
481 *
482 * @return bool True if it's the reply edit page, false if not.
483 */
484 function bbp_is_reply_edit() {
485 global $pagenow;
486
487 // Assume false
488 $retval = false;
489
490 // Get the main query global
491 $wp_query = bbp_get_wp_query();
492
493 // Check query
494 if ( ! empty( $wp_query->bbp_is_reply_edit ) && ( true === $wp_query->bbp_is_reply_edit ) ) {
495 $retval = true;
496
497 // Editing in admin
498 } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_reply_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
499 $retval = true;
500 }
501
502 // Filter & return
503 return (bool) apply_filters( 'bbp_is_reply_edit', $retval );
504 }
505
506 /**
507 * Check if current page is a reply move page.
508 *
509 * @return bool True if it's the reply move page, false if not.
510 */
511 function bbp_is_reply_move() {
512
513 // Assume false
514 $retval = false;
515
516 // Check reply edit and GET params
517 if ( bbp_is_reply_edit() && ! empty( $_GET['action'] ) && ( 'move' === $_GET['action'] ) ) {
518 $retval = true;
519 }
520
521 // Filter & return
522 return (bool) apply_filters( 'bbp_is_reply_move', $retval );
523 }
524
525 /**
526 * Viewing a single reply.
527 *
528 * @since 2.0.0 bbPress (r3344)
529 *
530 * @return bool
531 */
532 function bbp_is_single_reply() {
533
534 // Assume false
535 $retval = false;
536
537 // Edit is not a single reply
538 if ( bbp_is_reply_edit() ) {
539 return false;
540 }
541
542 // Single and a match
543 if ( is_singular( bbp_get_reply_post_type() ) || bbp_is_query_name( 'bbp_single_reply' ) ) {
544 $retval = true;
545 }
546
547 // Filter & return
548 return (bool) apply_filters( 'bbp_is_single_reply', $retval );
549 }
550
551 /**
552 * Check if current page is a bbPress user's favorites page (profile page).
553 *
554 * @since 2.0.0 bbPress (r2652)
555 *
556 * @return bool True if it's the favorites page, false if not.
557 */
558 function bbp_is_favorites() {
559
560 // Assume false
561 $retval = false;
562
563 // Get the main query global
564 $wp_query = bbp_get_wp_query();
565
566 // Check query
567 if ( ! empty( $wp_query->bbp_is_single_user_favs ) && ( true === $wp_query->bbp_is_single_user_favs ) ) {
568 $retval = true;
569 }
570
571 // Filter & return
572 return (bool) apply_filters( 'bbp_is_favorites', $retval );
573 }
574
575 /**
576 * Check if current page is a bbPress user's subscriptions page (profile page).
577 *
578 * @since 2.0.0 bbPress (r2652)
579 *
580 * @return bool True if it's the subscriptions page, false if not.
581 */
582 function bbp_is_subscriptions() {
583
584 // Assume false
585 $retval = false;
586
587 // Get the main query global
588 $wp_query = bbp_get_wp_query();
589
590 // Check query
591 if ( ! empty( $wp_query->bbp_is_single_user_subs ) && ( true === $wp_query->bbp_is_single_user_subs ) ) {
592 $retval = true;
593 }
594
595 // Filter & return
596 return (bool) apply_filters( 'bbp_is_subscriptions', $retval );
597 }
598
599 /**
600 * Check if current page shows the topics created by a bbPress user (profile
601 * page).
602 *
603 * @since 2.0.0 bbPress (r2688)
604 *
605 * @return bool True if it's the topics created page, false if not.
606 */
607 function bbp_is_topics_created() {
608
609 // Assume false
610 $retval = false;
611
612 // Get the main query global
613 $wp_query = bbp_get_wp_query();
614
615 // Check query
616 if ( ! empty( $wp_query->bbp_is_single_user_topics ) && ( true === $wp_query->bbp_is_single_user_topics ) ) {
617 $retval = true;
618 }
619
620 // Filter & return
621 return (bool) apply_filters( 'bbp_is_topics_created', $retval );
622 }
623
624 /**
625 * Check if current page shows the replies created by a bbPress user (profile
626 * page).
627 *
628 * @since 2.2.0 bbPress (r4225)
629 *
630 * @return bool True if it's the replies created page, false if not.
631 */
632 function bbp_is_replies_created() {
633
634 // Assume false
635 $retval = false;
636
637 // Get the main query global
638 $wp_query = bbp_get_wp_query();
639
640 // Check query
641 if ( ! empty( $wp_query->bbp_is_single_user_replies ) && ( true === $wp_query->bbp_is_single_user_replies ) ) {
642 $retval = true;
643 }
644
645 // Filter & return
646 return (bool) apply_filters( 'bbp_is_replies_created', $retval );
647 }
648
649 /**
650 * Check if current page is the currently logged in users author page.
651 *
652 * @since 2.0.0 bbPress (r2688)
653 *
654 * @return bool True if it's the user's home, false if not.
655 */
656 function bbp_is_user_home() {
657
658 // Assume false
659 $retval = false;
660
661 // Get the main query global
662 $wp_query = bbp_get_wp_query();
663
664 // Check query
665 if ( ! empty( $wp_query->bbp_is_single_user_home ) && ( true === $wp_query->bbp_is_single_user_home ) ) {
666 $retval = true;
667 }
668
669 // Filter & return
670 return (bool) apply_filters( 'bbp_is_user_home', $retval );
671 }
672
673 /**
674 * Check if current page is the currently logged in users author edit page.
675 *
676 * @since 2.1.0 bbPress (r3918)
677 *
678 * @return bool True if it's the user's home, false if not.
679 */
680 function bbp_is_user_home_edit() {
681
682 // Assume false
683 $retval = false;
684
685 if ( bbp_is_user_home() && bbp_is_single_user_edit() ) {
686 $retval = true;
687 }
688
689 // Filter & return
690 return (bool) apply_filters( 'bbp_is_user_home_edit', $retval );
691 }
692
693 /**
694 * Check if current page is a user profile page.
695 *
696 * @since 2.0.0 bbPress (r2688)
697 *
698 * @return bool True if it's a user's profile page, false if not.
699 */
700 function bbp_is_single_user() {
701
702 // Assume false
703 $retval = false;
704
705 // Get the main query global
706 $wp_query = bbp_get_wp_query();
707
708 // Check query
709 if ( ! empty( $wp_query->bbp_is_single_user ) && ( true === $wp_query->bbp_is_single_user ) ) {
710 $retval = true;
711 }
712
713 // Filter & return
714 return (bool) apply_filters( 'bbp_is_single_user', $retval );
715 }
716
717 /**
718 * Check if current page is a user profile edit page.
719 *
720 * @since 2.0.0 bbPress (r2688)
721 *
722 * @return bool True if it's a user's profile edit page, false if not.
723 */
724 function bbp_is_single_user_edit() {
725
726 // Assume false
727 $retval = false;
728
729 // Get the main query global
730 $wp_query = bbp_get_wp_query();
731
732 // Check query
733 if ( ! empty( $wp_query->bbp_is_single_user_edit ) && ( true === $wp_query->bbp_is_single_user_edit ) ) {
734 $retval = true;
735 }
736
737 // Filter & return
738 return (bool) apply_filters( 'bbp_is_single_user_edit', $retval );
739 }
740
741 /**
742 * Check if current page is a user profile page.
743 *
744 * @since 2.2.0 bbPress (r4225)
745 *
746 * @return bool True if it's a user's profile page, false if not.
747 */
748 function bbp_is_single_user_profile() {
749
750 // Assume false
751 $retval = false;
752
753 // Get the main query global
754 $wp_query = bbp_get_wp_query();
755
756 // Check query
757 if ( ! empty( $wp_query->bbp_is_single_user_profile ) && ( true === $wp_query->bbp_is_single_user_profile ) ) {
758 $retval = true;
759 }
760
761 // Filter & return
762 return (bool) apply_filters( 'bbp_is_single_user_profile', $retval );
763 }
764
765 /**
766 * Check if current page is a user topics created page.
767 *
768 * @since 2.2.0 bbPress (r4225)
769 *
770 * @return bool True if it's a user's topics page, false if not.
771 */
772 function bbp_is_single_user_topics() {
773
774 // Assume false
775 $retval = false;
776
777 // Get the main query global
778 $wp_query = bbp_get_wp_query();
779
780 // Check query
781 if ( ! empty( $wp_query->bbp_is_single_user_topics ) && ( true === $wp_query->bbp_is_single_user_topics ) ) {
782 $retval = true;
783 }
784
785 // Filter & return
786 return (bool) apply_filters( 'bbp_is_single_user_topics', $retval );
787 }
788
789 /**
790 * Check if current page is a user replies created page.
791 *
792 * @since 2.2.0 bbPress (r4225)
793 *
794 * @return bool True if it's a user's replies page, false if not.
795 */
796 function bbp_is_single_user_replies() {
797
798 // Assume false
799 $retval = false;
800
801 // Get the main query global
802 $wp_query = bbp_get_wp_query();
803
804 // Check query
805 if ( ! empty( $wp_query->bbp_is_single_user_replies ) && ( true === $wp_query->bbp_is_single_user_replies ) ) {
806 $retval = true;
807 }
808
809 // Filter & return
810 return (bool) apply_filters( 'bbp_is_single_user_replies', $retval );
811 }
812
813 /**
814 * Check if current page is a user engagements page.
815 *
816 * @since 2.6.0 bbPress (r6320)
817 *
818 * @return bool True if it's a user's replies page, false if not.
819 */
820 function bbp_is_single_user_engagements() {
821
822 // Assume false
823 $retval = false;
824
825 // Get the main query global
826 $wp_query = bbp_get_wp_query();
827
828 // Check query
829 if ( ! empty( $wp_query->bbp_is_single_user_engagements ) && ( true === $wp_query->bbp_is_single_user_engagements ) ) {
830 $retval = true;
831 }
832
833 // Filter & return
834 return (bool) apply_filters( 'bbp_is_single_user_engagements', $retval );
835 }
836
837 /**
838 * Check if current page is a view page.
839 *
840 * @since 2.0.0 bbPress (r2789)
841 *
842 * @global WP_Query $wp_query To check if WP_Query::bbp_is_view is true.
843 *
844 * @return bool Is it a view page?
845 */
846 function bbp_is_single_view() {
847
848 // Assume false
849 $retval = false;
850
851 // Get the main query global
852 $wp_query = bbp_get_wp_query();
853
854 // Check query
855 if ( ! empty( $wp_query->bbp_is_view ) && ( true === $wp_query->bbp_is_view ) ) {
856 $retval = true;
857 }
858
859 // Check query name
860 if ( empty( $retval ) && bbp_is_query_name( 'bbp_single_view' ) ) {
861 $retval = true;
862 }
863
864 // Filter & return
865 return (bool) apply_filters( 'bbp_is_single_view', $retval );
866 }
867
868 /**
869 * Check if current page is a search page.
870 *
871 * @since 2.3.0 bbPress (r4579)
872 *
873 * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true.
874 *
875 * @return bool Is it a search page?
876 */
877 function bbp_is_search() {
878
879 // Bail if search is disabled
880 if ( ! bbp_allow_search() ) {
881 return false;
882 }
883
884 // Assume false
885 $retval = false;
886
887 // Get the main query global
888 $wp_query = bbp_get_wp_query();
889
890 // Get the rewrite ID (one time, to avoid repeated calls )
891 $rewrite_id = bbp_get_search_rewrite_id();
892
893 // Check query
894 if ( ! empty( $wp_query->bbp_is_search ) && ( true === $wp_query->bbp_is_search ) ) {
895 $retval = true;
896 }
897
898 // Check query name
899 if ( empty( $retval ) && bbp_is_query_name( $rewrite_id ) ) {
900 $retval = true;
901 }
902
903 // Check $_GET
904 if ( empty( $retval ) && isset( $_REQUEST[ $rewrite_id ] ) && empty( $_REQUEST[ $rewrite_id ] ) ) {
905 $retval = true;
906 }
907
908 // Filter & return
909 return (bool) apply_filters( 'bbp_is_search', $retval );
910 }
911
912 /**
913 * Check if current page is a search results page.
914 *
915 * @since 2.4.0 bbPress (r4919)
916 *
917 * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true.
918 *
919 * @return bool Is it a search page?
920 */
921 function bbp_is_search_results() {
922
923 // Bail if search is disabled
924 if ( ! bbp_allow_search() ) {
925 return false;
926 }
927
928 // Assume false
929 $retval = false;
930
931 // Get the main query global
932 $wp_query = bbp_get_wp_query();
933
934 // Check query
935 if ( ! empty( $wp_query->bbp_search_terms ) ) {
936 $retval = true;
937 }
938
939 // Check query name
940 if ( empty( $retval ) && bbp_is_query_name( 'bbp_search_results' ) ) {
941 $retval = true;
942 }
943
944 // Check $_REQUEST
945 if ( empty( $retval ) && ! empty( $_REQUEST[ bbp_get_search_rewrite_id() ] ) ) {
946 $retval = true;
947 }
948
949 // Filter & return
950 return (bool) apply_filters( 'bbp_is_search_results', $retval );
951 }
952
953 /**
954 * Check if current page is an edit page.
955 *
956 * @since 2.1.0 bbPress (r3585)
957 *
958 * @return bool True if it's the edit page, false if not.
959 */
960 function bbp_is_edit() {
961
962 // Assume false
963 $retval = false;
964
965 // Get the main query global
966 $wp_query = bbp_get_wp_query();
967
968 // Check query
969 if ( ! empty( $wp_query->bbp_is_edit ) && ( true === $wp_query->bbp_is_edit ) ) {
970 $retval = true;
971 }
972
973 // Filter & return
974 return (bool) apply_filters( 'bbp_is_edit', $retval );
975 }
976
977 /**
978 * Use the above is_() functions to output a body class for each scenario.
979 *
980 * @since 2.0.0 bbPress (r2926)
981 *
982 * @param array $wp_classes
983 * @param array $custom_classes
984 *
985 * @return array Body Classes
986 */
987 function bbp_body_class( $wp_classes = array(), $custom_classes = false ) {
988
989 // Default to no classes
990 $bbp_classes = array();
991
992 /* Archives ***************************************************************/
993
994 if ( bbp_is_forum_archive() ) {
995 $bbp_classes[] = bbp_get_forum_post_type() . '-archive';
996 } elseif ( bbp_is_topic_archive() ) {
997 $bbp_classes[] = bbp_get_topic_post_type() . '-archive';
998
999 /* Topic Tags *************************************************************/
1000 } elseif ( bbp_is_topic_tag() ) {
1001 $bbp_classes[] = bbp_get_topic_tag_tax_id();
1002 $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug();
1003 $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id();
1004 } elseif ( bbp_is_topic_tag_edit() ) {
1005 $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-edit';
1006 $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug() . '-edit';
1007 $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id() . '-edit';
1008
1009 /* Components *************************************************************/
1010 } elseif ( bbp_is_single_forum() ) {
1011 $bbp_classes[] = bbp_get_forum_post_type();
1012 } elseif ( bbp_is_single_topic() ) {
1013 $bbp_classes[] = bbp_get_topic_post_type();
1014 } elseif ( bbp_is_single_reply() ) {
1015 $bbp_classes[] = bbp_get_reply_post_type();
1016 } elseif ( bbp_is_topic_edit() ) {
1017 $bbp_classes[] = bbp_get_topic_post_type() . '-edit';
1018 } elseif ( bbp_is_topic_merge() ) {
1019 $bbp_classes[] = bbp_get_topic_post_type() . '-merge';
1020 } elseif ( bbp_is_topic_split() ) {
1021 $bbp_classes[] = bbp_get_topic_post_type() . '-split';
1022 } elseif ( bbp_is_reply_edit() ) {
1023 $bbp_classes[] = bbp_get_reply_post_type() . '-edit';
1024 } elseif ( bbp_is_reply_move() ) {
1025 $bbp_classes[] = bbp_get_reply_post_type() . '-move';
1026 } elseif ( bbp_is_single_view() ) {
1027 $bbp_classes[] = 'bbp-view';
1028 $bbp_classes[] = 'bbp-view-' . bbp_get_view_id();
1029
1030 /* User *******************************************************************/
1031 } elseif ( bbp_is_single_user_edit() ) {
1032 $bbp_classes[] = 'bbp-user-edit';
1033 $bbp_classes[] = 'single';
1034 $bbp_classes[] = 'singular';
1035 } elseif ( bbp_is_single_user() ) {
1036 $bbp_classes[] = 'bbp-user-page';
1037 $bbp_classes[] = 'single';
1038 $bbp_classes[] = 'singular';
1039 } elseif ( bbp_is_user_home() ) {
1040 $bbp_classes[] = 'bbp-user-home';
1041 $bbp_classes[] = 'single';
1042 $bbp_classes[] = 'singular';
1043 } elseif ( bbp_is_user_home_edit() ) {
1044 $bbp_classes[] = 'bbp-user-home-edit';
1045 $bbp_classes[] = 'single';
1046 $bbp_classes[] = 'singular';
1047 } elseif ( bbp_is_topics_created() ) {
1048 $bbp_classes[] = 'bbp-topics-created';
1049 $bbp_classes[] = 'single';
1050 $bbp_classes[] = 'singular';
1051 } elseif ( bbp_is_replies_created() ) {
1052 $bbp_classes[] = 'bbp-replies-created';
1053 $bbp_classes[] = 'single';
1054 $bbp_classes[] = 'singular';
1055 } elseif ( bbp_is_favorites() ) {
1056 $bbp_classes[] = 'bbp-favorites';
1057 $bbp_classes[] = 'single';
1058 $bbp_classes[] = 'singular';
1059 } elseif ( bbp_is_subscriptions() ) {
1060 $bbp_classes[] = 'bbp-subscriptions';
1061 $bbp_classes[] = 'single';
1062 $bbp_classes[] = 'singular';
1063
1064 /* Search *****************************************************************/
1065 } elseif ( bbp_is_search() ) {
1066 $bbp_classes[] = 'bbp-search';
1067 $bbp_classes[] = 'forum-search';
1068 } elseif ( bbp_is_search_results() ) {
1069 $bbp_classes[] = 'bbp-search-results';
1070 $bbp_classes[] = 'forum-search-results';
1071
1072 /* Shortcodes *************************************************************/
1073 } elseif ( bbp_has_shortcode() ) {
1074 $bbp_classes[] = 'bbp-shortcode';
1075 }
1076
1077 /* General ****************************************************************/
1078
1079 // Any page with bbPress content
1080 if ( ! empty( $bbp_classes ) ) {
1081 $bbp_classes[] = 'bbpress';
1082 $bbp_classes[] = 'no-js';
1083 }
1084
1085 /** Clean up **************************************************************/
1086
1087 // Merge WP classes with bbPress classes and remove any duplicates
1088 $classes = array_unique(array_merge( (array) $bbp_classes, (array) $wp_classes ) );
1089
1090 // Deprecated filter (do not use )
1091 $classes = apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
1092
1093 // Filter & return
1094 return (array) apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
1095 }
1096
1097 /**
1098 * Output a small piece of JavaScript to replace the "bbp-no-js" body class
1099 * with "bbp-js" to allow interactive & dynamic elements to work as intended.
1100 *
1101 * @since 2.6.10 bbPress (r7229)
1102 */
1103 function bbp_swap_no_js_body_class() {
1104 static $done = false;
1105
1106 // Bail if already done
1107 if ( true === $done ) {
1108 return;
1109 }
1110
1111 // Mark as done
1112 $done = true;
1113
1114 ?>
1115
1116 <script id="bbp-swap-no-js-body-class">
1117 document.body.className = document.body.className.replace( 'bbp-no-js', 'bbp-js' );
1118 </script>
1119
1120 <?php
1121 }
1122
1123 /**
1124 * Check if text contains a bbPress shortcode.
1125 *
1126 * Loops through registered bbPress shortcodes and keeps track of which ones
1127 * were used in a blob of text. If no text is passed, the current global post
1128 * content is assumed.
1129 *
1130 * A preliminary strpos() is performed before looping through each shortcode, to
1131 * prevent unnecessarily processing.
1132 *
1133 * @since 2.6.0
1134 *
1135 * @param string $text
1136 *
1137 * @return bool
1138 */
1139 function bbp_has_shortcode( $text = '' ) {
1140
1141 // Default return value
1142 $retval = false;
1143 $found = array();
1144
1145 // Fallback to global post_content
1146 if ( empty( $text ) && is_singular() ) {
1147 $text = bbp_get_global_post_field( 'post_content', 'raw' );
1148 }
1149
1150 // Skip if empty, or string doesn't contain the bbPress shortcode prefix
1151 if ( ! empty( $text ) && ( false !== strpos( $text, '[bbp' ) ) ) {
1152
1153 // Get possible shortcodes
1154 $codes = array_keys( bbpress()->shortcodes->codes );
1155
1156 // Loop through codes
1157 foreach ( $codes as $code ) {
1158
1159 // Looking for shortcode in text
1160 if ( has_shortcode( $text, $code ) ) {
1161 $retval = true;
1162 $found[] = $code;
1163 }
1164 }
1165 }
1166
1167 // Filter & return
1168 return (bool) apply_filters( 'bbp_has_shortcode', $retval, $found, $text );
1169 }
1170
1171 /**
1172 * Use the above is_() functions to return if in any bbPress page.
1173 *
1174 * @since 2.0.0 bbPress (r3344)
1175 *
1176 * @return bool In a bbPress page.
1177 */
1178 function is_bbpress() {
1179
1180 // Default to false
1181 $retval = false;
1182
1183 // Bail if main query has not been populated.
1184 if ( ! bbp_get_wp_query() ) {
1185 _doing_it_wrong(__FUNCTION__, esc_html__( 'Conditional query tags do not work before the query is run. Before then, they always return false.', 'bbpress' ), '2.7.0' );
1186
1187 return $retval;
1188 }
1189
1190 /* Archives ***************************************************************/
1191
1192 if ( bbp_is_forum_archive() ) {
1193 $retval = true;
1194 } elseif ( bbp_is_topic_archive() ) {
1195 $retval = true;
1196
1197 /* Topic Tags *************************************************************/
1198 } elseif ( bbp_is_topic_tag() ) {
1199 $retval = true;
1200 } elseif ( bbp_is_topic_tag_edit() ) {
1201 $retval = true;
1202
1203 /* Components *************************************************************/
1204 } elseif ( bbp_is_single_forum() ) {
1205 $retval = true;
1206 } elseif ( bbp_is_single_topic() ) {
1207 $retval = true;
1208 } elseif ( bbp_is_single_reply() ) {
1209 $retval = true;
1210 } elseif ( bbp_is_topic_edit() ) {
1211 $retval = true;
1212 } elseif ( bbp_is_topic_merge() ) {
1213 $retval = true;
1214 } elseif ( bbp_is_topic_split() ) {
1215 $retval = true;
1216 } elseif ( bbp_is_reply_edit() ) {
1217 $retval = true;
1218 } elseif ( bbp_is_reply_move() ) {
1219 $retval = true;
1220 } elseif ( bbp_is_single_view() ) {
1221 $retval = true;
1222
1223 /* User *******************************************************************/
1224 } elseif ( bbp_is_single_user_edit() ) {
1225 $retval = true;
1226 } elseif ( bbp_is_single_user() ) {
1227 $retval = true;
1228 } elseif ( bbp_is_user_home() ) {
1229 $retval = true;
1230 } elseif ( bbp_is_user_home_edit() ) {
1231 $retval = true;
1232 } elseif ( bbp_is_topics_created() ) {
1233 $retval = true;
1234 } elseif ( bbp_is_replies_created() ) {
1235 $retval = true;
1236 } elseif ( bbp_is_favorites() ) {
1237 $retval = true;
1238 } elseif ( bbp_is_subscriptions() ) {
1239 $retval = true;
1240
1241 /* Search *****************************************************************/
1242 } elseif ( bbp_is_search() ) {
1243 $retval = true;
1244 } elseif ( bbp_is_search_results() ) {
1245 $retval = true;
1246
1247 /* Shortcodes *************************************************************/
1248 } elseif ( bbp_has_shortcode() ) {
1249 $retval = true;
1250 }
1251
1252 /* Done *******************************************************************/
1253
1254 // Filter & return
1255 return (bool) apply_filters( 'is_bbpress', $retval );
1256 }
1257
1258 /** Forms *********************************************************************/
1259
1260 /**
1261 * Output the login form action url.
1262 *
1263 * @since 2.0.0 bbPress (r2815)
1264 *
1265 * @param array $args This function supports these arguments:
1266 * - action: The action being taken
1267 * - context: The context the action is being taken from
1268 */
1269 function bbp_wp_login_action( $args = array() ) {
1270 echo esc_url( bbp_get_wp_login_action( $args ) );
1271 }
1272
1273 /**
1274 * Return the login form action url.
1275 *
1276 * @since 2.6.0 bbPress (r5684)
1277 *
1278 * @param array $args This function supports these arguments:
1279 * - action: The action being taken
1280 * - context: The context the action is being taken from
1281 */
1282 function bbp_get_wp_login_action( $args = array() ) {
1283
1284 // Parse arguments against default values
1285 $r = bbp_parse_args(
1286 $args,
1287 array(
1288 'action' => '',
1289 'context' => '',
1290 'url' => 'wp-login.php',
1291 ),
1292 'login_action'
1293 );
1294
1295 // Add action as query arg
1296 $login_url = ! empty( $r['action'] )
1297 ? add_query_arg( array( 'action' => $r['action'] ), $r['url'] )
1298 : $r['url'];
1299
1300 $login_url = site_url( $login_url, $r['context'] );
1301
1302 // Filter & return
1303 return apply_filters( 'bbp_get_wp_login_action', $login_url, $r, $args );
1304 }
1305
1306 /**
1307 * Output hidden request URI field for user forms.
1308 *
1309 * The referer link is the current Request URI from the server super global. To
1310 * check the field manually, use bbp_get_redirect_to().
1311 *
1312 * @since 2.0.0 bbPress (r2815)
1313 *
1314 * @param string $redirect_to Pass a URL to redirect to.
1315 */
1316 function bbp_redirect_to_field( $redirect_to = '' ) {
1317
1318 // Make sure we are directing somewhere
1319 if ( empty( $redirect_to ) ) {
1320 if ( isset( $_SERVER['REQUEST_URI'] ) ) {
1321 $redirect_to = bbp_get_url_scheme() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1322 } else {
1323 $redirect_to = wp_get_referer();
1324 }
1325 }
1326
1327 // Remove loggedout query arg if it's there
1328 $redirect_to = remove_query_arg( 'loggedout', $redirect_to );
1329 $redirect_field = '<input type="hidden" id="bbp_redirect_to" name="redirect_to" value="' . esc_url( $redirect_to ) . '" />';
1330
1331 // Filter & return
1332 echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to );
1333 }
1334
1335 /**
1336 * Echo sanitized $_REQUEST value.
1337 *
1338 * Use the $input_type parameter to properly process the value. This
1339 * ensures correct sanitization of the value for the receiving input.
1340 *
1341 * @since 2.0.0 bbPress (r2815)
1342 *
1343 * @param string $request Name of $_REQUEST to look for
1344 * @param string $input_type Type of input. Default: text. Accepts:
1345 * textarea|password|select|radio|checkbox
1346 */
1347 function bbp_sanitize_val( $request = '', $input_type = 'text' ) {
1348 echo bbp_get_sanitize_val( $request, $input_type );
1349 }
1350
1351 /**
1352 * Return sanitized $_REQUEST value.
1353 *
1354 * Use the $input_type parameter to properly process the value. This
1355 * ensures correct sanitization of the value for the receiving input.
1356 *
1357 * @since 2.0.0 bbPress (r2815)
1358 *
1359 * @param string $request Name of $_REQUEST to look for
1360 * @param string $input_type Type of input. Default: text. Accepts:
1361 * textarea|password|select|radio|checkbox
1362 *
1363 * @return string Sanitized value ready for screen display.
1364 */
1365 function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) {
1366
1367 // Check that requested
1368 if ( empty( $_REQUEST[ $request ] ) ) {
1369 return false;
1370 }
1371
1372 // Set request varaible
1373 $pre_ret_val = $_REQUEST[ $request ];
1374
1375 // Treat different kinds of fields in different ways
1376 switch ( $input_type ) {
1377 case 'text':
1378 case 'textarea':
1379 $retval = esc_attr(wp_unslash( $pre_ret_val ) );
1380 break;
1381
1382 case 'password':
1383 case 'select':
1384 case 'radio':
1385 case 'checkbox':
1386 default:
1387 $retval = esc_attr( $pre_ret_val );
1388 break;
1389 }
1390
1391 // Filter & return
1392 return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type );
1393 }
1394
1395 /**
1396 * Output the current tab index of a given form.
1397 *
1398 * Use this function to handle the tab indexing of user facing forms within a
1399 * template file. Calling this function will automatically increment the global
1400 * tab index by default.
1401 *
1402 * @since 2.0.0 bbPress (r2810)
1403 * @deprecated 2.6.0 bbPress (r5561)
1404 * @see https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
1405 *
1406 * @param int $auto_increment Optional. Default true. Set to false to prevent
1407 * increment.
1408 */
1409 function bbp_tab_index( $auto_increment = true ) {
1410 echo bbp_get_tab_index( $auto_increment );
1411 }
1412
1413 /**
1414 * Return the current tab index of a given form.
1415 *
1416 * Use this function to handle the tab indexing of user facing forms
1417 * within a template file. Calling this function will automatically
1418 * increment the global tab index by default.
1419 *
1420 * @since 2.0.0 bbPress (r2810)
1421 * @deprecated 2.6.0 bbPress (r5561)
1422 * @see https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
1423 *
1424 * @param int $auto_increment Optional. Default true. Set to false to
1425 * prevent the increment.
1426 *
1427 * @return int $bbp->tab_index The global tab index.
1428 */
1429 function bbp_get_tab_index( $auto_increment = true ) {
1430 $bbp = bbpress();
1431
1432 if ( true === $auto_increment ) {
1433 ++$bbp->tab_index;
1434 }
1435
1436 // Filter & return
1437 return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
1438 }
1439
1440 /**
1441 * Output a "tabindex" attribute for an element, if an index was passed.
1442 *
1443 * This helper function is in use, but it is generally considered impolite to
1444 * override the "tabindex" attribute beyond what the browser naturally assigns.
1445 *
1446 * Most internal usages pass `false` which results in no attribute being used.
1447 *
1448 * @since 2.6.0 bbPress (r6424)
1449 *
1450 * @param mixed $tab False to skip, any integer to use.
1451 */
1452 function bbp_tab_index_attribute( $tab = false ) {
1453 echo bbp_get_tab_index_attribute( $tab );
1454 }
1455
1456 /**
1457 * Return a "tabindex" attribute for an element, if an index was passed.
1458 *
1459 * This helper function is in use, but it is generally considered impolite to
1460 * override the "tabindex" attribute beyond what the browser naturally assigns.
1461 *
1462 * Most internal usages pass `false` which results in no attribute being used.
1463 *
1464 * @since 2.6.0 bbPress (r6424)
1465 *
1466 * @param mixed $tab False to skip, any integer to use.
1467 *
1468 * @return string
1469 */
1470 function bbp_get_tab_index_attribute( $tab = false ) {
1471
1472 // Get attribute
1473 $attr = is_numeric( $tab )
1474 ? ' tabindex="' . (int) $tab . '"'
1475 : '';
1476
1477 // Filter & return
1478 return apply_filters( 'bbp_get_tab_index_attribute', $attr, $tab );
1479 }
1480
1481 /**
1482 * Output a select box allowing to pick which forum/topic a new topic/reply
1483 * belongs in.
1484 *
1485 * Can be used for any post type, but is mostly used for topics and forums.
1486 *
1487 * @since 2.0.0 bbPress (r2746)
1488 *
1489 * @param array $args See {@link bbp_get_dropdown()} for arguments.
1490 */
1491 function bbp_dropdown( $args = array() ) {
1492 echo bbp_get_dropdown( $args );
1493 }
1494 /**
1495 * Return a select box allowing to pick which forum/topic a new
1496 * topic/reply belongs in.
1497 *
1498 * @since 2.0.0 bbPress (r2746)
1499 *
1500 * @param array $args The function supports these args:
1501 * - post_type: Post type, defaults to bbp_get_forum_post_type() ( bbp_forum)
1502 * - selected: Selected ID, to not have any value as selected, pass
1503 * anything smaller than 0 (due to the nature of select
1504 * box, the first value would of course be selected -
1505 * though you can have that as none (pass 'show_none' arg) )
1506 * - orderby: Defaults to 'menu_order title'
1507 * - post_parent: Post parent. Defaults to 0
1508 * - post_status: Which all post_statuses to find in? Can be an array
1509 * or CSV of publish, category, closed, private, spam,
1510 * trash (based on post type ) - if not set, these are
1511 * automatically determined based on the post_type
1512 * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
1513 * all posts
1514 * - walker: Which walker to use? Defaults to
1515 * {@link BBP_Walker_Dropdown}
1516 * - select_id: ID of the select box. Defaults to 'bbp_forum_id'
1517 * - tab: Deprecated. Tabindex value. False or integer
1518 * - options_only: Show only <options>? No <select>?
1519 * - show_none: Boolean or String __( '&mdash; No Forum &mdash;', 'bbpress' )
1520 * - disable_categories: Disable forum categories and closed forums?
1521 * Defaults to true. Only for forums and when
1522 *
1523 * @return string The dropdown
1524 */
1525 function bbp_get_dropdown( $args = array() ) {
1526
1527 // Setup return value
1528 $retval = '';
1529
1530 /** Arguments *************************************************************/
1531
1532 // Parse arguments against default values
1533 $r = bbp_parse_args(
1534 $args,
1535 array(
1536
1537 // Support for get_posts()
1538 'post_type' => bbp_get_forum_post_type(),
1539 'post_parent' => null,
1540 'post_status' => null,
1541 'selected' => 0,
1542 'include' => array(),
1543 'exclude' => array(),
1544 'numberposts' => -1,
1545 'orderby' => 'menu_order title',
1546 'order' => 'ASC',
1547
1548 // Preloaded content
1549 'posts' => array(),
1550
1551 // Custom hierarchy walkers
1552 'walker' => '',
1553
1554 // Output-related
1555 'select_id' => 'bbp_forum_id',
1556 'select_class' => 'bbp_dropdown',
1557 'tab' => false,
1558 'options_only' => false,
1559 'show_none' => false,
1560 'disable_categories' => true,
1561 'disabled' => '',
1562 ),
1563 'get_dropdown'
1564 );
1565
1566 // Fallback to our walker
1567 if ( empty( $r['walker'] ) ) {
1568 $r['walker'] = new BBP_Walker_Dropdown();
1569 $r['walker']->tree_type = $r['post_type'];
1570 }
1571
1572 // Force 0
1573 if ( is_numeric( $r['selected'] ) && ( $r['selected'] < 0 ) ) {
1574 $r['selected'] = 0;
1575 }
1576
1577 // Force array
1578 if ( ! empty( $r['include'] ) && ! is_array( $r['include'] ) ) {
1579 $r['include'] = explode( ',', $r['include'] );
1580 }
1581
1582 // Force array
1583 if ( ! empty( $r['exclude'] ) && ! is_array( $r['exclude'] ) ) {
1584 $r['exclude'] = explode( ',', $r['exclude'] );
1585 }
1586
1587 /* Setup Posts ************************************************************/
1588
1589 /*
1590 * Allow passing of custom posts data
1591 *
1592 * @see bbp_get_reply_to_dropdown() as an example
1593 */
1594 if ( empty( $r['posts'] ) ) {
1595 $r['posts'] = get_posts(
1596 array(
1597 'post_type' => $r['post_type'],
1598 'post_status' => $r['post_status'],
1599 'post_parent' => $r['post_parent'],
1600 'include' => $r['include'],
1601 'exclude' => $r['exclude'],
1602 'numberposts' => $r['numberposts'],
1603 'orderby' => $r['orderby'],
1604 'order' => $r['order'],
1605 )
1606 );
1607 }
1608
1609 /* Drop Down **************************************************************/
1610
1611 // Build the opening tag for the select element
1612 if ( empty( $r['options_only'] ) ) {
1613
1614 // Should this select appear disabled?
1615 $disabled = disabled( isset( bbpress()->options[ $r['disabled'] ] ), true, false );
1616
1617 // Setup the tab index attribute
1618 $tab = ! empty( $r['tab'] )
1619 ? ' tabindex="'. intval( $r['tab'] ) . '"'
1620 : '';
1621
1622 // Open the select tag
1623 $retval .= '<select name="' . esc_attr( $r['select_id'] ) . '" id="' . esc_attr( $r['select_id'] ) . '" class="' . esc_attr( $r['select_class'] ) . '"' . $disabled . $tab . '>' . "\n";
1624 }
1625
1626 // Display a leading 'no-value' option, with or without custom text
1627 if ( ! empty( $r['show_none'] ) || ! empty( $r['none_found'] ) ) {
1628
1629 // Open the 'no-value' option tag
1630 $retval .= "\t<option value=\"\" class=\"level-0\">";
1631
1632 // Use deprecated 'none_found' first for backpat
1633 if ( ! empty( $r['none_found'] ) && is_string( $r['none_found'] ) ) {
1634 $retval .= esc_html( $r['none_found'] );
1635
1636 // Use 'show_none' second
1637 } elseif ( ! empty( $r['show_none'] ) && is_string( $r['show_none'] ) ) {
1638 $retval .= esc_html( $r['show_none'] );
1639
1640 // Otherwise, make some educated guesses
1641 } else {
1642
1643 // Switch the response based on post type
1644 switch ( $r['post_type'] ) {
1645 // Topics
1646 case bbp_get_topic_post_type():
1647 $retval .= esc_html__( 'No topics available', 'bbpress' );
1648 break;
1649
1650 // Forums
1651 case bbp_get_forum_post_type():
1652 $retval .= esc_html__( 'No forums available', 'bbpress' );
1653 break;
1654
1655 // Any other
1656 default:
1657 $retval .= esc_html__( 'None available', 'bbpress' );
1658 break;
1659 }
1660 }
1661
1662 // Close the 'no-value' option tag
1663 $retval .= '</option>';
1664 }
1665
1666 // Items found so walk the tree
1667 if ( ! empty( $r['posts'] ) ) {
1668 $retval .= walk_page_dropdown_tree( $r['posts'], 0, $r );
1669 }
1670
1671 // Close the selecet tag
1672 if ( empty( $r['options_only'] ) ) {
1673 $retval .= '</select>';
1674 }
1675
1676 // Filter & return
1677 return apply_filters( 'bbp_get_dropdown', $retval, $r, $args );
1678 }
1679
1680 /**
1681 * Output the required hidden fields when creating/editing a forum.
1682 *
1683 * @since 2.1.0 bbPress (r3553)
1684 */
1685 function bbp_forum_form_fields() {
1686 if ( bbp_is_forum_edit() ) { ?>
1687
1688 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-forum" />
1689 <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
1690
1691 <?php if ( current_user_can( 'unfiltered_html' ) ) {
1692 wp_nonce_field( 'bbp-unfiltered-html-forum_' . bbp_get_forum_id(), '_bbp_unfiltered_html_forum', false );
1693 } ?>
1694
1695 <?php wp_nonce_field( 'bbp-edit-forum_' . bbp_get_forum_id() );
1696 } else {
1697 if ( bbp_is_single_forum() ) { ?>
1698
1699 <input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_forum_parent_id(); ?>" />
1700
1701 <?php } ?>
1702
1703 <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-forum" />
1704
1705 <?php if ( current_user_can( 'unfiltered_html' ) ) {
1706 wp_nonce_field( 'bbp-unfiltered-html-forum_new', '_bbp_unfiltered_html_forum', false );
1707 } ?>
1708
1709 <?php wp_nonce_field( 'bbp-new-forum' );
1710 }
1711 }
1712
1713 /**
1714 * Output the required hidden fields when creating/editing a topic.
1715 *
1716 * @since 2.0.0 bbPress (r2753)
1717 */
1718 function bbp_topic_form_fields() {
1719 if ( bbp_is_topic_edit() ) { ?>
1720
1721 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" />
1722 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
1723
1724 <?php if ( current_user_can( 'unfiltered_html' ) ) {
1725 wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false );
1726 } ?>
1727
1728 <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() );
1729 } else {
1730 if ( bbp_is_single_forum() ) { ?>
1731
1732 <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
1733
1734 <?php } ?>
1735
1736 <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" />
1737
1738 <?php if ( current_user_can( 'unfiltered_html' ) ) {
1739 wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false );
1740 } ?>
1741
1742 <?php wp_nonce_field( 'bbp-new-topic' );
1743 }
1744 }
1745
1746 /**
1747 * Output the required hidden fields when creating/editing a reply.
1748 *
1749 * @since 2.0.0 bbPress (r2753)
1750 */
1751 function bbp_reply_form_fields() {
1752 if ( bbp_is_reply_edit() ) { ?>
1753
1754 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" />
1755 <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" />
1756
1757 <?php if ( current_user_can( 'unfiltered_html' ) ) {
1758 wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false );
1759 } ?>
1760
1761 <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() );
1762 } else { ?>
1763
1764 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
1765 <input type="hidden" name="bbp_reply_to" id="bbp_reply_to" value="<?php bbp_form_reply_to(); ?>" />
1766 <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" />
1767
1768 <?php if ( current_user_can( 'unfiltered_html' ) ) {
1769 wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false );
1770 } ?>
1771
1772 <?php wp_nonce_field( 'bbp-new-reply' );
1773
1774 // Show redirect field if not viewing a specific topic
1775 if ( bbp_is_query_name( 'bbp_single_topic' ) ) {
1776 $redirect_to = apply_filters( 'bbp_reply_form_redirect_to', get_permalink() );
1777 bbp_redirect_to_field( $redirect_to );
1778 }
1779 }
1780 }
1781
1782 /**
1783 * Output the required hidden fields when editing a user.
1784 *
1785 * @since 2.0.0 bbPress (r2690)
1786 */
1787 function bbp_edit_user_form_fields() {
1788 ?>
1789
1790 <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" />
1791 <input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" />
1792
1793 <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() );
1794 }
1795
1796 /**
1797 * Merge topic form fields.
1798 *
1799 * Output the required hidden fields when merging a topic.
1800 *
1801 * @since 2.0.0 bbPress (r2756)
1802 */
1803 function bbp_merge_topic_form_fields() {
1804 ?>
1805
1806 <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" />
1807 <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
1808
1809 <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() );
1810 }
1811
1812 /**
1813 * Split topic form fields.
1814 *
1815 * Output the required hidden fields when splitting a topic.
1816 *
1817 * @since 2.0.0 bbPress (r2756)
1818 */
1819 function bbp_split_topic_form_fields() {
1820 ?>
1821
1822 <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" />
1823 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo intval( $_GET['reply_id'] ); ?>" />
1824
1825 <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() );
1826 }
1827
1828 /**
1829 * Move reply form fields.
1830 *
1831 * Output the required hidden fields when moving a reply.
1832 *
1833 * @since 2.1.0 bbPress (r3586)
1834 */
1835 function bbp_move_reply_form_fields() {
1836 ?>
1837
1838 <input type="hidden" name="action" id="bbp_post_action" value="bbp-move-reply" />
1839 <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo intval( $_GET['reply_id'] ); ?>" />
1840
1841 <?php wp_nonce_field( 'bbp-move-reply_' . bbp_get_reply_id() );
1842 }
1843
1844 /**
1845 * Output a textarea or TinyMCE if enabled.
1846 *
1847 * @since 2.1.0 bbPress (r3586)
1848 *
1849 * @param array $args
1850 */
1851 function bbp_the_content( $args = array() ) {
1852 echo bbp_get_the_content( $args );
1853 }
1854
1855 /**
1856 * Return a textarea or TinyMCE if enabled.
1857 *
1858 * @since 2.1.0 bbPress (r3586)
1859 *
1860 * @param array $args
1861 *
1862 * @return string HTML from output buffer
1863 */
1864 function bbp_get_the_content( $args = array() ) {
1865
1866 // Parse arguments against default values
1867 $r = bbp_parse_args(
1868 $args,
1869 array(
1870 'context' => 'topic',
1871 'before' => '<div class="bbp-the-content-wrapper">',
1872 'after' => '</div>',
1873 'wpautop' => true,
1874 'media_buttons' => false,
1875 'textarea_rows' => '12',
1876 'tabindex' => false,
1877 'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags',
1878 'editor_class' => 'bbp-the-content',
1879 'tinymce' => false,
1880 'teeny' => true,
1881 'quicktags' => true,
1882 'dfw' => false,
1883 ),
1884 'get_the_content'
1885 );
1886
1887 // If using tinymce, remove our escaping and trust tinymce
1888 if ( bbp_use_wp_editor() && ( false !== $r['tinymce'] ) ) {
1889 remove_filter( 'bbp_get_form_forum_content', 'esc_textarea' );
1890 remove_filter( 'bbp_get_form_topic_content', 'esc_textarea' );
1891 remove_filter( 'bbp_get_form_reply_content', 'esc_textarea' );
1892 }
1893
1894 // Assume we are not editing
1895 $post_content = call_user_func( 'bbp_get_form_' . $r['context'] . '_content' );
1896
1897 // Start an output buffor
1898 ob_start();
1899
1900 // Output something before the editor
1901 if ( ! empty( $r['before'] ) ) {
1902 echo $r['before'];
1903 }
1904
1905 // Use TinyMCE if available
1906 if ( bbp_use_wp_editor() ) {
1907
1908 // Enable additional TinyMCE plugins before outputting the editor
1909 add_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
1910 add_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
1911 add_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' );
1912 add_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
1913
1914 // Output the editor
1915 wp_editor(
1916 $post_content,
1917 'bbp_' . $r['context'] . '_content',
1918 array(
1919 'wpautop' => $r['wpautop'],
1920 'media_buttons' => $r['media_buttons'],
1921 'textarea_rows' => $r['textarea_rows'],
1922 'tabindex' => $r['tabindex'],
1923 'tabfocus_elements' => $r['tabfocus_elements'],
1924 'editor_class' => $r['editor_class'],
1925 'tinymce' => $r['tinymce'],
1926 'teeny' => $r['teeny'],
1927 'quicktags' => $r['quicktags'],
1928 'dfw' => $r['dfw'],
1929 )
1930 );
1931
1932 // Remove additional TinyMCE plugins after outputting the editor
1933 remove_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
1934 remove_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
1935 remove_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' );
1936 remove_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
1937
1938 /*
1939 * Fallback to normal textarea.
1940 *
1941 * Note that we do not use esc_textarea() here to prevent double
1942 * escaping the editable output, mucking up existing content.
1943 */
1944 } else { ?>
1945
1946 <textarea id="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" class="<?php echo esc_attr( $r['editor_class'] ); ?>" name="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" cols="60" rows="<?php echo esc_attr( $r['textarea_rows'] ); ?>" <?php bbp_tab_index_attribute( $r['tabindex'] ); ?>><?php echo $post_content; ?></textarea>
1947
1948 <?php }
1949
1950 // Output something after the editor
1951 if ( ! empty( $r['after'] ) ) {
1952 echo $r['after'];
1953 }
1954
1955 // Put the output into a usable variable
1956 $output = ob_get_clean();
1957
1958 // Filter & return
1959 return apply_filters( 'bbp_get_the_content', $output, $args, $post_content );
1960 }
1961
1962 /**
1963 * Edit TinyMCE plugins to match core behaviour.
1964 *
1965 * @since 2.3.0 bbPress (r4574)
1966 *
1967 * @param array $plugins
1968 *
1969 * @see tiny_mce_plugins, teeny_mce_plugins
1970 *
1971 * @return array
1972 */
1973 function bbp_get_tiny_mce_plugins( $plugins = array() ) {
1974
1975 // Unset fullscreen
1976 foreach ( $plugins as $key => $value ) {
1977 if ( 'fullscreen' === $value ) {
1978 unset( $plugins[ $key ] );
1979 break;
1980 }
1981 }
1982
1983 // Add the tabfocus plugin
1984 $plugins[] = 'tabfocus';
1985
1986 // Filter & return
1987 return apply_filters( 'bbp_get_tiny_mce_plugins', $plugins );
1988 }
1989
1990 /**
1991 * Edit TeenyMCE buttons to match allowedtags.
1992 *
1993 * @since 2.3.0 bbPress (r4605)
1994 *
1995 * @param array $buttons
1996 *
1997 * @see teeny_mce_buttons
1998 *
1999 * @return array
2000 */
2001 function bbp_get_teeny_mce_buttons( $buttons = array() ) {
2002
2003 // Remove some buttons from TeenyMCE
2004 $buttons = array_diff(
2005 $buttons,
2006 array(
2007 'underline',
2008 'justifyleft',
2009 'justifycenter',
2010 'justifyright',
2011 )
2012 );
2013
2014 // Images
2015 array_push( $buttons, 'image' );
2016
2017 // Filter & return
2018 return apply_filters( 'bbp_get_teeny_mce_buttons', $buttons );
2019 }
2020
2021 /**
2022 * Edit TinyMCE quicktags buttons to match allowedtags.
2023 *
2024 * @since 2.3.0 bbPress (r4606)
2025 *
2026 * @param array $settings
2027 *
2028 * @see quicktags_settings
2029 *
2030 * @return array Quicktags settings
2031 */
2032 function bbp_get_quicktags_settings( $settings = array() ) {
2033
2034 // Get buttons out of settings
2035 $buttons_array = explode( ',', $settings['buttons'] );
2036
2037 // Diff the ones we don't want out
2038 $buttons = array_diff(
2039 $buttons_array,
2040 array(
2041 'ins',
2042 'more',
2043 'spell',
2044 )
2045 );
2046
2047 // Put them back into a string in the $settings array
2048 $settings['buttons'] = implode( ',', $buttons );
2049
2050 // Filter & return
2051 return apply_filters( 'bbp_get_quicktags_settings', $settings );
2052 }
2053
2054 /** Views *********************************************************************/
2055
2056 /**
2057 * Output the view id.
2058 *
2059 * @since 2.0.0 bbPress (r2789)
2060 *
2061 * @param string $view Optional. View id.
2062 */
2063 function bbp_view_id( $view = '' ) {
2064 echo bbp_get_view_id( $view );
2065 }
2066
2067 /**
2068 * Get the view id.
2069 *
2070 * Use view id if supplied, otherwise bbp_get_view_rewrite_id() query var.
2071 *
2072 * @since 2.0.0 bbPress (r2789)
2073 *
2074 * @param string $view Optional. View id.
2075 *
2076 * @return bool|string ID on success, false on failure.
2077 */
2078 function bbp_get_view_id( $view = '' ) {
2079 $bbp = bbpress();
2080
2081 // User supplied string
2082 if ( ! empty( $view ) && is_string( $view ) ) {
2083 $view_id = $view;
2084
2085 // Current view ID
2086 } elseif ( ! empty( $bbp->current_view_id ) ) {
2087 $view_id = $bbp->current_view_id;
2088
2089 // Querying for view
2090 } else {
2091 $view_id = get_query_var( bbp_get_view_rewrite_id() );
2092 }
2093
2094 // Filter & return
2095 return apply_filters( 'bbp_get_view_id', $view_id, $view );
2096 }
2097
2098 /**
2099 * Output the view name aka title.
2100 *
2101 * @since 2.0.0 bbPress (r2789)
2102 *
2103 * @param string $view Optional. View id.
2104 */
2105 function bbp_view_title( $view = '' ) {
2106 echo bbp_get_view_title( $view );
2107 }
2108
2109 /**
2110 * Get the view name aka title.
2111 *
2112 * If a view id is supplied, that is used. Otherwise the bbp_view
2113 * query var is checked for.
2114 *
2115 * @since 2.0.0 bbPress (r2789)
2116 *
2117 * @param string $view Optional. View id.
2118 *
2119 * @return bool|string Title on success, false on failure.
2120 */
2121 function bbp_get_view_title( $view = '' ) {
2122 $bbp = bbpress();
2123
2124 $view = bbp_get_view_id( $view );
2125 if ( empty( $view ) ) {
2126 return false;
2127 }
2128
2129 return $bbp->views[ $view ]['title'];
2130 }
2131
2132 /**
2133 * Output the view url.
2134 *
2135 * @since 2.0.0 bbPress (r2789)
2136 *
2137 * @param string $view Optional. View id.
2138 */
2139 function bbp_view_url( $view = false ) {
2140 echo esc_url( bbp_get_view_url( $view ) );
2141 }
2142 /**
2143 * Return the view url.
2144 *
2145 * @since 2.0.0 bbPress (r2789)
2146 *
2147 * @param string $view Optional. View id.
2148 *
2149 * @return string View url (or home url if the view was not found).
2150 */
2151 function bbp_get_view_url( $view = false ) {
2152
2153 $view = bbp_get_view_id( $view );
2154 if ( empty( $view ) ) {
2155 return home_url();
2156 }
2157
2158 // Pretty permalinks
2159 if ( bbp_use_pretty_urls() ) {
2160 // Run through home_url()
2161 $url = trailingslashit( bbp_get_root_url() . bbp_get_view_slug() ) . $view;
2162 $url = user_trailingslashit( $url );
2163 $url = home_url( $url );
2164
2165 // Unpretty permalinks
2166 } else {
2167 $url = add_query_arg(
2168 array(
2169 bbp_get_view_rewrite_id() => $view,
2170 ),
2171 home_url( '/' )
2172 );
2173 }
2174
2175 // Filter & return
2176 return apply_filters( 'bbp_get_view_link', $url, $view );
2177 }
2178
2179 /** Query *********************************************************************/
2180
2181 /**
2182 * Check the passed parameter against the current _bbp_query_name.
2183 *
2184 * @since 2.0.0 bbPress (r2980)
2185 *
2186 * @return bool True if match, false if not.
2187 */
2188 function bbp_is_query_name( $name = '' ) {
2189 return (bool) ( bbp_get_query_name() === $name );
2190 }
2191
2192 /**
2193 * Get the '_bbp_query_name' setting.
2194 *
2195 * @since 2.0.0 bbPress (r2695)
2196 *
2197 * @return string To return the query var value.
2198 */
2199 function bbp_get_query_name() {
2200 return get_query_var( '_bbp_query_name' );
2201 }
2202
2203 /**
2204 * Set the '_bbp_query_name' setting to $name.
2205 *
2206 * @since 2.0.0 bbPress (r2692)
2207 *
2208 * @param string $name What to set the query var to.
2209 */
2210 function bbp_set_query_name( $name = '' ) {
2211 set_query_var( '_bbp_query_name', $name );
2212 }
2213
2214 /**
2215 * Used to clear the '_bbp_query_name' setting.
2216 *
2217 * @since 2.0.0 bbPress (r2692)
2218 */
2219 function bbp_reset_query_name() {
2220 bbp_set_query_name();
2221 }
2222
2223 /** Breadcrumbs ***************************************************************/
2224
2225 /**
2226 * Output the page title as a breadcrumb.
2227 *
2228 * @since 2.0.0 bbPress (r2589)
2229 */
2230 function bbp_title_breadcrumb( $args = array() ) {
2231 echo bbp_get_breadcrumb( $args );
2232 }
2233
2234 /**
2235 * Output a breadcrumb.
2236 *
2237 * @since 2.0.0 bbPress (r2589)
2238 */
2239 function bbp_breadcrumb( $args = array() ) {
2240 echo bbp_get_breadcrumb( $args );
2241 }
2242
2243 /**
2244 * Return a breadcrumb ( forum -> topic -> reply )
2245 *
2246 * @since 2.0.0 bbPress (r2589)
2247 *
2248 * @param string $sep Separator. Defaults to '&larr;'.
2249 * @param bool $current_page Include the current item.
2250 * @param bool $root Include the root page if one exists.
2251 *
2252 * @return string Breadcrumbs.
2253 */
2254 function bbp_get_breadcrumb( $args = array() ) {
2255
2256 // Turn off breadcrumbs
2257 if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) ) {
2258 return;
2259 }
2260
2261 // Define variables
2262 $front_id = $root_id = $remove_root_id = 0;
2263 $ancestors = $crumbs = $tag_data = array();
2264 $pre_root_text = $pre_front_text = $pre_current_text = '';
2265 $pre_include_root = $pre_include_home = $pre_include_current = true;
2266
2267 /** Home Text *************************************************************/
2268
2269 // No custom home text
2270 if ( empty( $args['home_text'] ) ) {
2271
2272 $front_id = get_option( 'page_on_front' );
2273
2274 // Set home text to page title
2275 if ( ! empty( $front_id ) ) {
2276 $pre_front_text = get_the_title( $front_id );
2277
2278 // Default to 'Home'
2279 } else {
2280 $pre_front_text = esc_html__( 'Home', 'bbpress' );
2281 }
2282 }
2283
2284 /** Root Text *************************************************************/
2285
2286 // No custom root text
2287 if ( empty( $args['root_text'] ) ) {
2288 $page = bbp_get_page_by_path( bbp_get_root_slug() );
2289 if ( ! empty( $page ) ) {
2290 $root_id = $page->ID;
2291 }
2292 $pre_root_text = bbp_get_forum_archive_title();
2293 }
2294
2295 /** Includes **************************************************************/
2296
2297 // Root slug is also the front page
2298 if ( ! empty( $front_id ) && ( $front_id === $root_id ) ) {
2299 $pre_include_root = false;
2300 }
2301
2302 // Don't show root if viewing forum archive
2303 if ( bbp_is_forum_archive() ) {
2304 $pre_include_root = false;
2305 }
2306
2307 // Don't show root if viewing page in place of forum archive
2308 if ( ! empty( $root_id ) && ( ( is_single() || is_page() ) && ( get_the_ID() === $root_id ) ) ) {
2309 $pre_include_root = false;
2310 }
2311
2312 /** Current Text **********************************************************/
2313
2314 // Search page
2315 if ( bbp_is_search() ) {
2316 $pre_current_text = bbp_get_search_title();
2317
2318 // Forum archive
2319 } elseif ( bbp_is_forum_archive() ) {
2320 $pre_current_text = bbp_get_forum_archive_title();
2321
2322 // Topic archive
2323 } elseif ( bbp_is_topic_archive() ) {
2324 $pre_current_text = bbp_get_topic_archive_title();
2325
2326 // View
2327 } elseif ( bbp_is_single_view() ) {
2328 $pre_current_text = bbp_get_view_title();
2329
2330 // Single Forum
2331 } elseif ( bbp_is_single_forum() ) {
2332 $pre_current_text = bbp_get_forum_title();
2333
2334 // Single Topic
2335 } elseif ( bbp_is_single_topic() ) {
2336 $pre_current_text = bbp_get_topic_title();
2337
2338 // Single Topic
2339 } elseif ( bbp_is_single_reply() ) {
2340 $pre_current_text = bbp_get_reply_title();
2341
2342 // Topic Tag (or theme compat topic tag)
2343 } elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && ! bbp_is_topic_tag_edit() ) ) {
2344
2345 // Always include the tag name
2346 $tag_data[] = bbp_get_topic_tag_name();
2347
2348 // If capable, include a link to edit the tag
2349 if ( current_user_can( 'manage_topic_tags' ) ) {
2350 $tag_data[] = '<a href="' . esc_url( bbp_get_topic_tag_edit_link() ) . '" class="bbp-edit-topic-tag-link">' . esc_html__( '(Edit)', 'bbpress' ) . '</a>';
2351 }
2352
2353 // Implode the results of the tag data
2354 /* translators: %s: Topic tag data */
2355 $pre_current_text = sprintf( esc_html__( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) );
2356
2357 // Edit Topic Tag
2358 } elseif ( bbp_is_topic_tag_edit() ) {
2359 $pre_current_text = esc_html__( 'Edit', 'bbpress' );
2360
2361 // Single
2362 } else {
2363 $pre_current_text = get_the_title();
2364 }
2365
2366 /** Parse Args ************************************************************/
2367
2368 // Parse args
2369 $r = bbp_parse_args(
2370 $args,
2371 array(
2372
2373 // HTML
2374 'before' => '<div class="bbp-breadcrumb"><p>',
2375 'after' => '</p></div>',
2376
2377 // Separator
2378 'sep' => is_rtl() ? __( '&lsaquo;', 'bbpress' ) : __( '&rsaquo;', 'bbpress' ),
2379 'pad_sep' => 1,
2380 'sep_before' => '<span class="bbp-breadcrumb-sep">',
2381 'sep_after' => '</span>',
2382
2383 // Crumbs
2384 'crumb_before' => '',
2385 'crumb_after' => '',
2386
2387 // Home
2388 'include_home' => $pre_include_home,
2389 'home_text' => $pre_front_text,
2390
2391 // Forum root
2392 'include_root' => $pre_include_root,
2393 'root_text' => $pre_root_text,
2394
2395 // Current
2396 'include_current' => $pre_include_current,
2397 'current_text' => $pre_current_text,
2398 'current_before' => '<span class="bbp-breadcrumb-current">',
2399 'current_after' => '</span>',
2400 ),
2401 'get_breadcrumb'
2402 );
2403
2404 /** Ancestors *********************************************************/
2405
2406 // Get post ancestors
2407 if ( is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() ) {
2408 $ancestors = array_reverse( (array) get_post_ancestors( get_the_ID() ) );
2409 }
2410
2411 // Do we want to include a link to home?
2412 if ( ! empty( $r['include_home'] ) || empty( $r['home_text'] ) ) {
2413 $crumbs[] = '<a href="' . esc_url( home_url() ) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>';
2414 }
2415
2416 // Do we want to include a link to the forum root?
2417 if ( ! empty( $r['include_root'] ) || empty( $r['root_text'] ) ) {
2418
2419 // Page exists at root slug path, so use its permalink
2420 $page = bbp_get_page_by_path( bbp_get_root_slug() );
2421 if ( ! empty( $page ) ) {
2422 $root_url = get_permalink( $page->ID );
2423 $remove_root_id = $page->ID;
2424
2425 // Use the root slug
2426 } else {
2427 $root_url = get_post_type_archive_link( bbp_get_forum_post_type() );
2428 }
2429
2430 // Add the breadcrumb
2431 $crumbs[] = '<a href="' . esc_url( $root_url ) . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>';
2432 }
2433
2434 // Ancestors exist
2435 if ( ! empty( $ancestors ) ) {
2436
2437 // Loop through parents
2438 foreach ( (array) $ancestors as $parent_id ) {
2439
2440 // Parents
2441 $parent = get_post( $parent_id );
2442
2443 // Skip parent if empty or error
2444 if ( empty( $parent ) || is_wp_error( $parent ) ) {
2445 continue;
2446 }
2447
2448 // Skip to prevent duplicate root on subpages
2449 if ( ! empty( $remove_root_id ) && ( $parent->ID === $remove_root_id ) ) {
2450 continue;
2451 }
2452
2453 // Switch through post_type to ensure correct filters are applied
2454 switch ( $parent->post_type ) {
2455
2456 // Forum
2457 case bbp_get_forum_post_type() :
2458 $crumbs[] = '<a href="' . esc_url( bbp_get_forum_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a>';
2459 break;
2460
2461 // Topic
2462 case bbp_get_topic_post_type() :
2463 $crumbs[] = '<a href="' . esc_url( bbp_get_topic_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a>';
2464 break;
2465
2466 // Reply (Note: not in most themes )
2467 case bbp_get_reply_post_type() :
2468 $crumbs[] = '<a href="' . esc_url( bbp_get_reply_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a>';
2469 break;
2470
2471 // WordPress Post/Page/Other
2472 default :
2473 $crumbs[] = '<a href="' . esc_url( get_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a>';
2474 break;
2475 }
2476 }
2477
2478 // Edit topic tag
2479 } elseif ( bbp_is_topic_tag_edit() ) {
2480 /* translators: %s: Topic Tag name */
2481 $crumbs[] = '<a href="' . esc_url( get_term_link( bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id() ) ) . '" class="bbp-breadcrumb-topic-tag">' . sprintf( esc_html__( 'Topic Tag: %s', 'bbpress' ), bbp_get_topic_tag_name() ) . '</a>';
2482
2483 // Search
2484 } elseif ( bbp_is_search() && bbp_get_search_terms() ) {
2485 $crumbs[] = '<a href="' . esc_url( bbp_get_search_url() ) . '" class="bbp-breadcrumb-search">' . esc_html__( 'Search', 'bbpress' ) . '</a>';
2486 }
2487
2488 /** Current ***********************************************************/
2489
2490 // Add current page to breadcrumb
2491 if ( ! empty( $r['include_current'] ) || empty( $r['current_text'] ) ) {
2492 $crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after'];
2493 }
2494
2495 /** Separator *********************************************************/
2496
2497 // Wrap the separator in before/after before padding and filter
2498 if ( ! empty( $r['sep'] ) ) {
2499 $sep = $r['sep_before'] . $r['sep'] . $r['sep_after'];
2500 } else {
2501 $sep = '';
2502 }
2503
2504 // Pad the separator
2505 if ( ! empty( $r['pad_sep'] ) ) {
2506 if ( function_exists( 'mb_strlen' ) ) {
2507 $sep = str_pad( $sep, mb_strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
2508 } else {
2509 $sep = str_pad( $sep, strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
2510 }
2511 }
2512
2513 /** Finish Up *********************************************************/
2514
2515 // Filter the separator and breadcrumb
2516 $sep = apply_filters( 'bbp_breadcrumb_separator', $sep );
2517 $crumbs = apply_filters( 'bbp_breadcrumbs', $crumbs );
2518
2519 // Build the trail
2520 $trail = ! empty( $crumbs )
2521 ? ( $r['before'] . $r['crumb_before'] . implode( $sep . $r['crumb_after'] . $r['crumb_before'], $crumbs ) . $r['crumb_after'] . $r['after'] )
2522 : '';
2523
2524 // Filter & return
2525 return apply_filters( 'bbp_get_breadcrumb', $trail, $crumbs, $r, $args );
2526 }
2527
2528 /** Topic Tags ***************************************************************/
2529
2530 /**
2531 * Output all of the allowed tags in HTML format with attributes.
2532 *
2533 * This is useful for displaying in the post area, which elements and
2534 * attributes are supported. As well as any plugins which want to display it.
2535 *
2536 * @since 2.0.0 bbPress (r2780)
2537 */
2538 function bbp_allowed_tags() {
2539 echo bbp_get_allowed_tags();
2540 }
2541
2542 /**
2543 * Display all of the allowed tags in HTML format with attributes.
2544 *
2545 * This is useful for displaying in the post area, which elements and
2546 * attributes are supported. As well as any plugins which want to display it.
2547 *
2548 * @since 2.0.0 bbPress (r2780)
2549 *
2550 * @return string HTML allowed tags entity encoded.
2551 */
2552 function bbp_get_allowed_tags() {
2553 $allowed = '';
2554
2555 foreach ( (array) bbp_kses_allowed_tags() as $tag => $attributes ) {
2556 $allowed .= '<' . $tag;
2557
2558 if ( 0 < count( $attributes ) ) {
2559 foreach ( array_keys( $attributes ) as $attribute ) {
2560 $allowed .= ' ' . $attribute. '=""';
2561 }
2562 }
2563
2564 $allowed .= '> ';
2565 }
2566
2567 // Filter & return
2568 return apply_filters( 'bbp_get_allowed_tags', htmlentities( $allowed ) );
2569 }
2570
2571 /** Errors & Messages *********************************************************/
2572
2573 /**
2574 * Display possible errors & messages inside a template file.
2575 *
2576 * @since 2.0.0 bbPress (r2688)
2577 */
2578 function bbp_template_notices() {
2579
2580 // Bail if no notices or errors
2581 if ( ! bbp_has_errors() ) {
2582 return;
2583 }
2584
2585 // Define local variable(s )
2586 $errors = $messages = array();
2587
2588 // Get bbPress
2589 $bbp = bbpress();
2590
2591 // Loop through notices
2592 foreach ( $bbp->errors->get_error_codes() as $code ) {
2593
2594 // Get notice severity
2595 $severity = $bbp->errors->get_error_data( $code );
2596
2597 // Loop through notices and separate errors from messages
2598 foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
2599 if ( 'message' === $severity ) {
2600 $messages[] = $error;
2601 } else {
2602 $errors[] = $error;
2603 }
2604 }
2605 }
2606
2607 // Display errors first...
2608 if ( ! empty( $errors ) ) { ?>
2609
2610 <div class="bbp-template-notice error" role="alert" tabindex="-1">
2611 <ul>
2612 <li><?php echo implode( "</li>\n<li>", $errors ); ?></li>
2613 </ul>
2614 </div>
2615
2616 <?php }
2617
2618 // ...and messages last
2619 if ( ! empty( $messages ) ) { ?>
2620
2621 <div class="bbp-template-notice">
2622 <ul>
2623 <li><?php echo implode( "</li>\n<li>", $messages ); ?></li>
2624 </ul>
2625 </div>
2626
2627 <?php
2628
2629 }
2630 }
2631
2632 /** Login/logout/register/lost pass *******************************************/
2633
2634 /**
2635 * Output the logout link.
2636 *
2637 * @since 2.0.0 bbPress (r2827)
2638 *
2639 * @param string $redirect_to Redirect to url.
2640 */
2641 function bbp_logout_link( $redirect_to = '' ) {
2642 echo bbp_get_logout_link( $redirect_to );
2643 }
2644
2645 /**
2646 * Return the logout link.
2647 *
2648 * @since 2.0.0 bbPress (r2827)
2649 *
2650 * @param string $redirect_to Redirect to url.
2651 * redirect to url.
2652 *
2653 * @return string The logout link.
2654 */
2655 function bbp_get_logout_link( $redirect_to = '' ) {
2656
2657 // Build the link
2658 $link = '<a href="' . wp_logout_url( $redirect_to ) . '" class="button logout-link">' . esc_html__( 'Log Out', 'bbpress' ) . '</a>';
2659
2660 // Filter & return
2661 return apply_filters( 'bbp_get_logout_link', $link, $redirect_to );
2662 }
2663
2664 /** Title *********************************************************************/
2665
2666 /**
2667 * Custom page title for bbPress pages.
2668 *
2669 * @since 2.0.0 bbPress (r2788)
2670 *
2671 * @param string $title Optional. The title (not used).
2672 * @param string $sep Optional, default is '&raquo;'. How to separate the
2673 * various items within the page title.
2674 * @param string $seplocation Optional. Direction to display title, 'right'.
2675 * separator and separator location.
2676 *
2677 * @return string The title.
2678 */
2679 function bbp_title( $title = '', $sep = '&raquo;', $seplocation = '' ) {
2680
2681 // Title array
2682 $new_title = array();
2683
2684 /* Archives ************************************************************* */
2685
2686 // Forum Archive
2687 if ( bbp_is_forum_archive() ) {
2688 $new_title['text'] = bbp_get_forum_archive_title();
2689
2690 // Topic Archive
2691 } elseif ( bbp_is_topic_archive() ) {
2692 $new_title['text'] = bbp_get_topic_archive_title();
2693
2694 /* Edit ***************************************************************** */
2695
2696 // Forum edit page
2697 } elseif ( bbp_is_forum_edit() ) {
2698 $new_title['text'] = bbp_get_forum_title();
2699 /* translators: %s: Forum title */
2700 $new_title['format'] = esc_attr__( 'Forum Edit: %s', 'bbpress' );
2701
2702 // Topic edit page
2703 } elseif ( bbp_is_topic_edit() ) {
2704 $new_title['text'] = bbp_get_topic_title();
2705 /* translators: %s: Topic title */
2706 $new_title['format'] = esc_attr__( 'Topic Edit: %s', 'bbpress' );
2707
2708 // Reply edit page
2709 } elseif ( bbp_is_reply_edit() ) {
2710 $new_title['text'] = bbp_get_reply_title();
2711 /* translators: %s: Reply title */
2712 $new_title['format'] = esc_attr__( 'Reply Edit: %s', 'bbpress' );
2713
2714 // Topic tag edit page
2715 } elseif ( bbp_is_topic_tag_edit() ) {
2716 $new_title['text'] = bbp_get_topic_tag_name();
2717 /* translators: %s: Topic tag name */
2718 $new_title['format'] = esc_attr__( 'Topic Tag Edit: %s', 'bbpress' );
2719
2720 /* Singles ************************************************************** */
2721
2722 // Forum page
2723 } elseif ( bbp_is_single_forum() ) {
2724 $new_title['text'] = bbp_get_forum_title();
2725 /* translators: %s: Forum title */
2726 $new_title['format'] = esc_attr__( 'Forum: %s', 'bbpress' );
2727
2728 // Topic page
2729 } elseif ( bbp_is_single_topic() ) {
2730 $new_title['text'] = bbp_get_topic_title();
2731 /* translators: %s: Topic title */
2732 $new_title['format'] = esc_attr__( 'Topic: %s', 'bbpress' );
2733
2734 // Replies
2735 } elseif ( bbp_is_single_reply() ) {
2736 $new_title['text'] = bbp_get_reply_title();
2737
2738 // Topic tag page
2739 } elseif ( bbp_is_topic_tag() || get_query_var( 'bbp_topic_tag' ) ) {
2740 $new_title['text'] = bbp_get_topic_tag_name();
2741 /* translators: %s: Topic tag name */
2742 $new_title['format'] = esc_attr__( 'Topic Tag: %s', 'bbpress' );
2743
2744 /* Users **************************************************************** */
2745
2746 // Profile page
2747 } elseif ( bbp_is_single_user() ) {
2748 // Is user viewing their own profile?
2749 $is_user_home = bbp_is_user_home();
2750
2751 // User topics created
2752 if ( bbp_is_single_user_topics() ) {
2753 if ( true === $is_user_home ) {
2754 $new_title['text'] = esc_attr__( 'Your Topics', 'bbpress' );
2755 } else {
2756 $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2757 /* translators: user's display name */
2758 $new_title['format'] = esc_attr__( "%s's Topics", 'bbpress' );
2759 }
2760
2761 // User replies created
2762 } elseif ( bbp_is_single_user_replies() ) {
2763 if ( true === $is_user_home ) {
2764 $new_title['text'] = esc_attr__( 'Your Replies', 'bbpress' );
2765 } else {
2766 $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2767 /* translators: user's display name */
2768 $new_title['format'] = esc_attr__( "%s's Replies", 'bbpress' );
2769 }
2770
2771 // User favorites
2772 } elseif ( bbp_is_favorites() ) {
2773 if ( true === $is_user_home ) {
2774 $new_title['text'] = esc_attr__( 'Your Favorites', 'bbpress' );
2775 } else {
2776 $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2777 /* translators: user's display name */
2778 $new_title['format'] = esc_attr__( "%s's Favorites", 'bbpress' );
2779 }
2780
2781 // User subscriptions
2782 } elseif ( bbp_is_subscriptions() ) {
2783 if ( true === $is_user_home ) {
2784 $new_title['text'] = esc_attr__( 'Your Subscriptions', 'bbpress' );
2785 } else {
2786 $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2787 /* translators: user's display name */
2788 $new_title['format'] = esc_attr__( "%s's Subscriptions", 'bbpress' );
2789 }
2790
2791 // User "home"
2792 // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
2793 } else {
2794 if ( true === $is_user_home ) {
2795 $new_title['text'] = esc_attr__( 'Your Profile', 'bbpress' );
2796 } else {
2797 $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2798 /* translators: user's display name */
2799 $new_title['format'] = esc_attr__( "%s's Profile", 'bbpress' );
2800 }
2801 }
2802
2803 // Profile edit page
2804 } elseif ( bbp_is_single_user_edit() ) {
2805 // Current user
2806 if ( bbp_is_user_home_edit() ) {
2807 $new_title['text'] = esc_attr__( 'Edit Your Profile', 'bbpress' );
2808
2809 // Other user
2810 } else {
2811 $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2812 /* translators: %s: User's display name */
2813 $new_title['format'] = esc_attr__( "Edit %s's Profile", 'bbpress' );
2814 }
2815
2816 /* Views **************************************************************** */
2817
2818 // Views
2819 } elseif ( bbp_is_single_view() ) {
2820 $new_title['text'] = bbp_get_view_title();
2821 /* translators: %s: View title */
2822 $new_title['format'] = esc_attr__( 'View: %s', 'bbpress' );
2823
2824 /* Search *************************************************************** */
2825
2826 // Search
2827 } elseif ( bbp_is_search() ) {
2828 $new_title['text'] = bbp_get_search_title();
2829 }
2830
2831 // This filter is deprecated. Use 'bbp_before_title_parse_args' instead.
2832 $new_title = apply_filters( 'bbp_raw_title_array', $new_title );
2833
2834 // Set title array defaults
2835 $new_title = bbp_parse_args(
2836 $new_title,
2837 array(
2838 'text' => $title,
2839 'format' => '%s',
2840 ),
2841 'title'
2842 );
2843
2844 // Get the formatted raw title
2845 $new_title = sprintf( $new_title['format'], $new_title['text'] );
2846
2847 // Filter the raw title
2848 $new_title = apply_filters( 'bbp_raw_title', $new_title, $sep, $seplocation );
2849
2850 // Compare new title with original title
2851 if ( $new_title === $title ) {
2852 return $title;
2853 }
2854
2855 // Temporary separator, for accurate flipping, if necessary
2856 $t_sep = '%WP_TITILE_SEP%';
2857 $prefix = '';
2858
2859 if ( ! empty( $new_title ) ) {
2860 $prefix = " $sep ";
2861 }
2862
2863 // sep on right, so reverse the order
2864 if ( 'right' === $seplocation ) {
2865 $new_title_array = array_reverse( explode( $t_sep, $new_title ) );
2866 $new_title = implode( " $sep ", $new_title_array ) . $prefix;
2867
2868 // sep on left, do not reverse
2869 } else {
2870 $new_title_array = explode( $t_sep, $new_title );
2871 $new_title = $prefix . implode( " $sep ", $new_title_array );
2872 }
2873
2874 // Filter & return
2875 return apply_filters( 'bbp_title', $new_title, $sep, $seplocation );
2876 }
2877
2878 /**
2879 * Removes Protected/Private post title hints.
2880 *
2881 * This function is hooked to 2 WordPress filters that are responsible for
2882 * prepending hints to the beginning of Protected & Private post titles.
2883 *
2884 * These hints are a bit unsightly when used in functions like
2885 * bbp_get_breadcrumb(), so we strip them back out for bbPress post types.
2886 *
2887 * @since 2.7.0
2888 *
2889 * @param string $prepend text displayed before a post title.
2890 * @param int|WP_Post $post current post object.
2891 *
2892 * @return string
2893 */
2894 function bbp_no_title_status_hints( $prepend = '', $post = 0 ) {
2895
2896 // Bail if empty
2897 if ( empty( $prepend ) || empty( $post ) ) {
2898 return $prepend;
2899 }
2900
2901 // Get post type
2902 $post_type = get_post_type( $post );
2903
2904 // Maybe override return value
2905 $retval = in_array( $post_type, bbp_get_post_types(), true )
2906 ? '%s'
2907 : $prepend;
2908
2909 // Filter & return
2910 return (string) apply_filters( 'bbp_no_special_title_formatting', $retval, $prepend, $post );
2911 }
2912