PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.0
Forumax – AI Powered Advanced Community Forum Plugin v2.5.0
2.5.0 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 All 30 releases
bbp-core / lib / bbpress / includes / common / template.php

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

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