PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / trunk
Forumax – AI Powered Advanced Community Forum Plugin vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / lib / bbpress / includes / common / template.php

template.php in Forumax – AI Powered Advanced Community Forum Plugin trunk, at lib/bbpress/includes/common/template.php

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