PluginProbe
bbPress / 2.6.19
bbPress v2.6.19
2.6.19 2.6.18 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 All 74 releases
bbpress / includes / common / template.php

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

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