PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
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 / includes / common / template.php

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

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