PluginProbe
bbPress / 2.0-rc-4
bbPress v2.0-rc-4
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / bbp-includes / bbp-core-compatibility.php

bbp-core-compatibility.php in bbPress 2.0-rc-4, at bbp-includes/bbp-core-compatibility.php

1,591 lines 43.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Core Theme Compatibility
5 *
6 * @package bbPress
7 * @subpackage ThemeCompatibility
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Theme Compat **************************************************************/
14
15 /**
16 * What follows is an attempt at intercepting the natural page load process
17 * to replace the_content() with the appropriate bbPress content.
18 *
19 * To do this, bbPress does several direct manipulations of global variables
20 * and forces them to do what they are not supposed to be doing.
21 *
22 * Don't try anything you're about to witness here, at home. Ever.
23 */
24
25 /**
26 * Set the theme compat theme URL and DIR
27 *
28 * @since bbPress (r3311)
29 *
30 * @global bbPress $bbp
31 * @param string $theme
32 * @uses current_theme_supports()
33 */
34 function bbp_setup_theme_compat( $theme = array() ) {
35 global $bbp;
36
37 // Check if current theme supports bbPress
38 if ( empty( $bbp->theme_compat->theme ) && !current_theme_supports( 'bbpress' ) ) {
39 if ( empty( $theme ) ) {
40 $theme = array(
41 'dir' => $bbp->themes_dir . '/bbp-twentyten',
42 'url' => $bbp->themes_url . '/bbp-twentyten'
43 );
44 }
45
46 // Set the theme compat globals for help with loading template parts
47 $bbp->theme_compat->theme = $theme;
48 }
49 }
50
51 /**
52 * If not using a bbPress compatable theme, enqueue some basic styling and js
53 *
54 * @since bbPress (r3029)
55 *
56 * @uses bbp_set_compat_theme_dir() Set the compatable theme to bbp-twentyten
57 * @uses current_theme_supports() Check bbPress theme support
58 * @uses wp_enqueue_style() Enqueue the bbp-twentyten default CSS
59 * @uses wp_enqueue_script() Enqueue the bbp-twentyten default topic JS
60 */
61 function bbp_theme_compat_enqueue_css() {
62
63 // Check if current theme supports bbPress
64 if ( !current_theme_supports( 'bbpress' ) ) {
65
66 /** Default CSS ***************************************************/
67
68 // Version of CSS
69 $version = '20110808b';
70
71 // Right to left
72 if ( is_rtl() ) {
73 wp_enqueue_style( 'bbpress-style', bbp_get_theme_compat_url() . '/css/bbpress-rtl.css', '', $version, 'screen' );
74
75 // Left to right
76 } else {
77 wp_enqueue_style( 'bbpress-style', bbp_get_theme_compat_url() . '/css/bbpress.css', '', $version, 'screen' );
78 }
79 }
80 }
81
82 /**
83 * Adds bbPress theme support to any active WordPress theme
84 *
85 * This function is really cool because it's responsible for managing the
86 * theme compatability layer when the current theme does not support bbPress.
87 * It uses the current_theme_supports() WordPress function to see if 'bbpress'
88 * is explicitly supported. If not, it will directly load the requested template
89 * part using load_template(). If so, it proceeds with using get_template_part()
90 * as per normal, and no one is the wiser.
91 *
92 * @since bbPress (r3032)
93 *
94 * @param string $slug
95 * @param string $name Optional. Default null
96 * @uses current_theme_supports()
97 * @uses load_template()
98 * @uses get_template_part()
99 */
100 function bbp_get_template_part( $slug, $name = null ) {
101
102 // Current theme does not support bbPress, so we need to do some heavy
103 // lifting to see if a bbPress template is needed in the current context
104 if ( !current_theme_supports( 'bbpress' ) )
105 load_template( bbp_get_theme_compat_dir() . '/' . $slug . '-' . $name . '.php', false );
106
107 // Current theme supports bbPress to proceed as usual
108 else
109 get_template_part( $slug, $name );
110
111 }
112
113 /**
114 * Gets the bbPress compatable theme used in the event the currently active
115 * WordPress theme does not explicitly support bbPress. This can be filtered,
116 * or set manually. Tricky theme authors can override the default and include
117 * their own bbPress compatability layers for their themes.
118 *
119 * @since bbPress (r3032)
120 *
121 * @global bbPress $bbp
122 * @uses apply_filters()
123 * @return string
124 */
125 function bbp_get_theme_compat_dir() {
126 global $bbp;
127
128 return apply_filters( 'bbp_get_theme_compat_dir', $bbp->theme_compat->theme['dir'] );
129 }
130
131 /**
132 * Gets the bbPress compatable theme used in the event the currently active
133 * WordPress theme does not explicitly support bbPress. This can be filtered,
134 * or set manually. Tricky theme authors can override the default and include
135 * their own bbPress compatability layers for their themes.
136 *
137 * @since bbPress (r3032)
138 *
139 * @global bbPress $bbp
140 * @uses apply_filters()
141 * @return string
142 */
143 function bbp_get_theme_compat_url() {
144 global $bbp;
145
146 return apply_filters( 'bbp_get_theme_compat_url', $bbp->theme_compat->theme['url'] );
147 }
148
149 /**
150 * Gets true/false if page is currently inside theme compatibility
151 *
152 * @since bbPress (r3265)
153 *
154 * @global bbPress $bbp
155 *
156 * @return bool
157 */
158 function bbp_is_theme_compat_active() {
159 global $bbp;
160
161 if ( empty( $bbp->theme_compat->active ) )
162 return false;
163
164 return $bbp->theme_compat->active;
165 }
166
167 /**
168 * Sets true/false if page is currently inside theme compatibility
169 *
170 * @since bbPress (r3265)
171 *
172 * @global bbPress $bbp
173 *
174 * @param bool $set
175 *
176 * @return bool
177 */
178 function bbp_set_theme_compat_active( $set = true ) {
179 global $bbp;
180
181 $bbp->theme_compat->active = $set;
182
183 return (bool) $bbp->theme_compat->active;
184 }
185
186 /**
187 * Set the theme compat templates global
188 *
189 * Stash possible template files for the current query. Useful if plugins want
190 * to override them, or see what files are being scanned for inclusion.
191 *
192 * @since bbPress (r3311)
193 *
194 * @global $bbp;
195 */
196 function bbp_set_theme_compat_templates( $templates = array() ) {
197 global $bbp;
198
199 $bbp->theme_compat->templates = $templates;
200
201 return $bbp->theme_compat->templates;
202 }
203
204 /**
205 * Set the theme compat template global
206 *
207 * Stash the template file for the current query. Useful if plugins want
208 * to override it, or see what file is being included.
209 *
210 * @since bbPress (r3311)
211 *
212 * @global $bbp;
213 */
214 function bbp_set_theme_compat_template( $template = '' ) {
215 global $bbp;
216
217 $bbp->theme_compat->template = $template;
218
219 return $bbp->theme_compat->template;
220 }
221
222 /**
223 * This fun little function fills up some WordPress globals with dummy data to
224 * stop your average page template from complaining about it missing.
225 *
226 * @since bbPress (r3108)
227 *
228 * @global WP_Query $wp_query
229 * @global object $post
230 * @param array $args
231 */
232 function bbp_theme_compat_reset_post( $args = array() ) {
233 global $wp_query, $post;
234
235 // Why would you ever want to do this otherwise?
236 if ( current_theme_supports( 'bbpress' ) )
237 wp_die( __( 'Hands off, partner!', 'bbpress' ) );
238
239 // Default for current post
240 if ( isset( $wp_query->post ) ) {
241 $defaults = array(
242 'ID' => get_the_ID(),
243 'post_title' => get_the_title(),
244 'post_author' => get_the_author_meta('ID'),
245 'post_date' => get_the_date(),
246 'post_content' => get_the_content(),
247 'post_type' => get_post_type(),
248 'post_status' => get_post_status(),
249 'is_404' => false,
250 'is_page' => false,
251 'is_single' => false,
252 'is_archive' => false,
253 'is_tax' => false,
254 );
255
256 // Empty defaults
257 } else {
258 $defaults = array(
259 'ID' => 0,
260 'post_title' => '',
261 'post_author' => 0,
262 'post_date' => 0,
263 'post_content' => '',
264 'post_type' => 'page',
265 'post_status' => 'publish',
266 'is_404' => false,
267 'is_page' => false,
268 'is_single' => false,
269 'is_archive' => false,
270 'is_tax' => false,
271 );
272 }
273 $dummy = wp_parse_args( $args, $defaults );
274
275 // Clear out the post related globals
276 unset( $wp_query->posts );
277 unset( $wp_query->post );
278 unset( $post );
279
280 // Setup the dummy post object
281 $wp_query->post->ID = $dummy['ID'];
282 $wp_query->post->post_title = $dummy['post_title'];
283 $wp_query->post->post_author = $dummy['post_author'];
284 $wp_query->post->post_date = $dummy['post_date'];
285 $wp_query->post->post_content = $dummy['post_content'];
286 $wp_query->post->post_type = $dummy['post_type'];
287 $wp_query->post->post_status = $dummy['post_status'];
288
289 // Set the $post global
290 $post = $wp_query->post;
291
292 // Setup the dummy post loop
293 $wp_query->posts[0] = $wp_query->post;
294
295 // Prevent comments form from appearing
296 $wp_query->post_count = 1;
297 $wp_query->is_404 = $dummy['is_404'];
298 $wp_query->is_page = $dummy['is_page'];
299 $wp_query->is_single = $dummy['is_single'];
300 $wp_query->is_archive = $dummy['is_archive'];
301 $wp_query->is_tax = $dummy['is_tax'];
302
303 // If we are resetting a post, we are in theme compat
304 bbp_set_theme_compat_active();
305 }
306
307 /** Templates *****************************************************************/
308
309 /**
310 * Get the user profile template
311 *
312 * @since bbPress (r3311)
313 *
314 * @uses bbp_get_displayed_user_id()
315 * @uses apply_filters()
316 *
317 * @return array
318 */
319 function bbp_get_single_user_template() {
320
321 $displayed = bbp_get_displayed_user_id();
322 $templates = array(
323
324 // Single User ID
325 'single-user-' . $displayed . '.php',
326 'bbpress/single-user-' . $displayed . '.php',
327 'forums/single-user-' . $displayed . '.php',
328
329 // Single User
330 'single-user.php',
331 'bbpress/single-user.php',
332 'forums/single-user.php',
333
334 // User
335 'user.php',
336 'bbpress/user.php',
337 'forums/user.php',
338 );
339
340 $templates = apply_filters( 'bbp_get_profile_template', $templates );
341 $templates = bbp_set_theme_compat_templates( $templates );
342
343 $template = locate_template( $templates, false, false );
344 $template = bbp_set_theme_compat_template( $template );
345
346 return $template;
347 }
348
349 /**
350 * Get the user profile edit template
351 *
352 * @since bbPress (r3311)
353 *
354 * @uses $displayed
355 * @uses apply_filters()
356 *
357 * @return array
358 */
359 function bbp_get_single_user_edit_template() {
360
361 $displayed = bbp_get_displayed_user_id();
362 $templates = array(
363
364 // Single User Edit ID
365 'single-user-edit-' . $displayed . '.php',
366 'bbpress/single-user-edit-' . $displayed . '.php',
367 'forums/single-user-edit-' . $displayed . '.php',
368
369 // Single User Edit
370 'single-user-edit.php',
371 'bbpress/single-user-edit.php',
372 'forums/single-user-edit.php',
373
374 // User Edit
375 'user-edit.php',
376 'bbpress/user-edit.php',
377 'forums/user-edit.php',
378
379 // User
380 'forums/user.php',
381 'bbpress/user.php',
382 'user.php',
383 );
384
385 $templates = apply_filters( 'bbp_get_profile_edit_template', $templates );
386 $templates = bbp_set_theme_compat_templates( $templates );
387
388 $template = locate_template( $templates, false, false );
389 $template = bbp_set_theme_compat_template( $template );
390
391 return $template;
392 }
393
394 /**
395 * Get the view template
396 *
397 * @since bbPress (r3311)
398 *
399 * @uses bbp_get_view_id()
400 * @uses apply_filters()
401 *
402 * @return array
403 */
404 function bbp_get_single_view_template() {
405
406 $view_id = bbp_get_view_id();
407 $templates = array(
408
409 // Single View ID
410 'single-view-' . $view_id . '.php',
411 'bbpress/single-view-' . $view_id . '.php',
412 'forums/single-view-' . $view_id . '.php',
413
414 // View ID
415 'view-' . $view_id . '.php',
416 'bbpress/view-' . $view_id . '.php',
417 'forums/view-' . $view_id . '.php',
418
419 // Single View
420 'single-view.php',
421 'bbpress/single-view.php',
422 'forums/single-view.php',
423
424 // View
425 'view.php',
426 'bbpress/view.php',
427 'forums/view.php',
428 );
429
430 $templates = apply_filters( 'bbp_get_single_view_template', $templates );
431 $templates = bbp_set_theme_compat_templates( $templates );
432
433 $template = locate_template( $templates, false, false );
434 $template = bbp_set_theme_compat_template( $template );
435
436 return $template;
437 }
438
439 /**
440 * Get the topic edit template
441 *
442 * @since bbPress (r3311)
443 *
444 * @uses bbp_get_topic_post_type()
445 * @uses apply_filters()
446 *
447 * @return array
448 */
449 function bbp_get_topic_edit_template() {
450
451 $post_type = bbp_get_topic_post_type();
452 $templates = array(
453
454 // Single Topic Edit
455 'single-' . $post_type . '-edit.php',
456 'bbpress/single-' . $post_type . '-edit.php',
457 'forums/single-' . $post_type . '-edit.php',
458
459 // Single Action Edit Topic
460 'single-action-edit-' . $post_type . '.php',
461 'bbpress/single-action-edit-' . $post_type . '.php',
462 'forums/single-action-edit-' . $post_type . '.php',
463
464 // Single Action Edit
465 'single-action-edit.php',
466 'bbpress/single-action-edit.php',
467 'forums/single-action-edit.php',
468
469 // Action Edit
470 'action-edit.php',
471 'bbpress/action-edit.php',
472 'forums/action-edit.php',
473
474 // Single Topic
475 'single-' . $post_type . '.php',
476 'forums/single-' . $post_type . '.php',
477 'bbpress/single-' . $post_type . '.php',
478 );
479
480 $templates = apply_filters( 'bbp_get_topic_edit_template', $templates );
481 $templates = bbp_set_theme_compat_templates( $templates );
482
483 $template = locate_template( $templates, false, false );
484 $template = bbp_set_theme_compat_template( $template );
485
486 return $template;
487 }
488
489 /**
490 * Get the topic split template
491 *
492 * @since bbPress (r3311)
493 *
494 * @uses bbp_get_topic_post_type()
495 * @uses apply_filters()
496 *
497 * @return array
498 */
499 function bbp_get_topic_split_template() {
500
501 $post_type = bbp_get_topic_post_type();
502 $templates = array(
503
504 // Topic Split
505 'single-' . $post_type . '-split.php',
506 'bbpress/single-' . $post_type . '-split.php',
507 'forums/single-' . $post_type . '-split.php',
508
509 // Action Split
510 'single-action-split-merge.php',
511 'bbpress/single-action-split-merge.php',
512 'forums/single-action-split-merge.php',
513
514 // Action Split
515 'action-split-merge.php',
516 'bbpress/action-split-merge.php',
517 'forums/action-split-merge.php'
518 );
519
520 $templates = apply_filters( 'bbp_get_topic_split_template', $templates );
521 $templates = bbp_set_theme_compat_templates( $templates );
522
523 $template = locate_template( $templates, false, false );
524 $template = bbp_set_theme_compat_template( $template );
525
526 return $template;
527 }
528
529 /**
530 * Get the topic merge template
531 *
532 * @since bbPress (r3311)
533 *
534 * @uses bbp_get_topic_post_type()
535 * @uses apply_filters()
536 *
537 * @return array
538 */
539 function bbp_get_topic_merge_template() {
540
541 $post_type = bbp_get_topic_post_type();
542 $templates = array(
543
544 // Topic Merge
545 'single-' . $post_type . '-merge.php',
546 'bbpress/single-' . $post_type . '-merge.php',
547 'forums/single-' . $post_type . '-merge.php',
548
549 // Action Merge
550 'single-action-split-merge.php',
551 'bbpress/single-action-split-merge.php',
552 'forums/single-action-split-merge.php',
553
554 // Action Merge
555 'action-split-merge.php',
556 'bbpress/action-split-merge.php',
557 'forums/action-split-merge.php'
558 );
559
560 $templates = apply_filters( 'bbp_get_topic_merge_template', $templates );
561 $templates = bbp_set_theme_compat_templates( $templates );
562
563 $template = locate_template( $templates, false, false );
564 $template = bbp_set_theme_compat_template( $template );
565
566 return $template;
567 }
568
569 /**
570 * Get the reply edit template
571 *
572 * @since bbPress (r3311)
573 *
574 * @uses bbp_get_reply_post_type()
575 * @uses apply_filters()
576 *
577 * @return array
578 */
579 function bbp_get_reply_edit_template() {
580
581 $post_type = bbp_get_reply_post_type();
582 $templates = array(
583
584 // Single Reply Edit
585 'single-' . $post_type . '-edit.php',
586 'bbpress/single-' . $post_type . '-edit.php',
587 'forums/single-' . $post_type . '-edit.php',
588
589 // Single Action Edit Reply
590 'single-action-edit-' . $post_type . '.php',
591 'bbpress/single-action-edit-' . $post_type . '.php',
592 'forums/single-action-edit-' . $post_type . '.php',
593
594 // Single Action Edit
595 'single-action-edit.php',
596 'bbpress/single-action-edit.php',
597 'forums/single-action-edit.php',
598
599 // Action Edit
600 'action-edit.php',
601 'bbpress/action-edit.php',
602 'forums/action-edit.php',
603
604 // Single Reply
605 'single-' . $post_type . '.php',
606 'forums/single-' . $post_type . '.php',
607 'bbpress/single-' . $post_type . '.php',
608 );
609
610 $templates = apply_filters( 'bbp_get_reply_edit_template', $templates );
611 $templates = bbp_set_theme_compat_templates( $templates );
612
613 $template = locate_template( $templates, false, false );
614 $template = bbp_set_theme_compat_template( $template );
615
616 return $template;
617 }
618
619 /**
620 * Get the topic template
621 *
622 * @since bbPress (r3311)
623 *
624 * @uses bbp_get_topic_tag_tax_id()
625 * @uses apply_filters()
626 *
627 * @return array
628 */
629 function bbp_get_topic_tag_template() {
630
631 $tt_id = bbp_get_topic_tag_tax_id();
632 $templates = array(
633
634 // Single Topic Tag
635 'taxonomy-' . $tt_id . '.php',
636 'forums/taxonomy-' . $tt_id . '.php',
637 'bbpress/taxonomy-' . $tt_id . '.php',
638 );
639
640 $templates = apply_filters( 'bbp_get_topic_tag_template', $templates );
641 $templates = bbp_set_theme_compat_templates( $templates );
642
643 $template = locate_template( $templates, false, false );
644 $template = bbp_set_theme_compat_template( $template );
645
646 return $template;
647 }
648
649 /**
650 * Get the topic edit template
651 *
652 * @since bbPress (r3311)
653 *
654 * @uses bbp_get_topic_tag_tax_id()
655 * @uses apply_filters()
656 *
657 * @return array
658 */
659 function bbp_get_topic_tag_edit_template() {
660
661 $tt_id = bbp_get_topic_tag_tax_id();
662 $templates = array(
663
664 // Single Topic Tag Edit
665 'taxonomy-' . $tt_id . '-edit.php',
666 'bbpress/taxonomy-' . $tt_id . '-edit.php',
667 'forums/taxonomy-' . $tt_id . '-edit.php',
668
669 // Single Topic Tag
670 'taxonomy-' . $tt_id . '.php',
671 'forums/taxonomy-' . $tt_id . '.php',
672 'bbpress/taxonomy-' . $tt_id . '.php',
673 );
674
675 $templates = apply_filters( 'bbp_get_topic_tag_edit_template', $templates );
676 $templates = bbp_set_theme_compat_templates( $templates );
677
678 $template = locate_template( $templates, false, false );
679 $template = bbp_set_theme_compat_template( $template );
680
681 return $template;
682 }
683
684 /**
685 * Get the files to fallback on to use for theme compatibility
686 *
687 * @since bbPress (r3311)
688 *
689 * @uses apply_filters()
690 * @uses bbp_set_theme_compat_templates();
691 *
692 * @return type
693 */
694 function bbp_get_theme_compat_templates() {
695
696 $templates = array(
697 'bbpress.php',
698 'forum.php',
699 'page.php',
700 'single.php',
701 'index.php'
702 );
703
704 $templates = apply_filters( 'bbp_get_theme_compat_templates', $templates );
705 $templates = bbp_set_theme_compat_templates( $templates );
706
707 $template = locate_template( $templates, false, false );
708 $template = bbp_set_theme_compat_template( $template );
709
710 return $template;
711 }
712
713 /**
714 * Possibly intercept the template being loaded
715 *
716 * Listens to the 'template_include' filter and waits for a bbPress post_type
717 * to appear. If the current theme does not explicitly support bbPress, it
718 * intercepts the page template and uses one served from the bbPress compatable
719 * theme, set in the $bbp->theme_compat global. If the current theme does
720 * support bbPress, we'll explore the template hierarchy and try to locate one.
721 *
722 * @since bbPress (r3032)
723 *
724 * @global bbPress $bbp
725 * @global WP_Query $post
726 *
727 * @param string $template
728 *
729 * @uses current_theme_supports() To check if theme supports bbPress
730 * @uses bbp_is_single_user() To check if page is single user
731 * @uses bbp_get_single_user_template() To get user template
732 * @uses bbp_is_single_user_edit() To check if page is single user edit
733 * @uses bbp_get_single_user_edit_template() To get user edit template
734 * @uses bbp_is_single_view() To check if page is single view
735 * @uses bbp_get_single_view_template() To get view template
736 * @uses bbp_is_topic_merge() To check if page is topic merge
737 * @uses bbp_get_topic_merge_template() To get topic merge template
738 * @uses bbp_is_topic_split() To check if page is topic split
739 * @uses bbp_get_topic_split_template() To get topic split template
740 * @uses bbp_is_topic_edit() To check if page is topic edit
741 * @uses bbp_get_topic_edit_template() To get topic edit template
742 * @uses bbp_is_reply_edit() To check if page is reply edit
743 * @uses bbp_get_reply_edit_template() To get reply edit template
744 * @uses bbp_set_theme_compat_template() To set the global theme compat template
745 *
746 * @return string The path to the template file that is being used
747 */
748 function bbp_template_include_theme_supports( $template = '' ) {
749 global $bbp;
750
751 // Current theme supports bbPress
752 if ( current_theme_supports( 'bbpress' ) ) {
753
754 // Viewing a user
755 if ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
756
757 // Editing a user
758 elseif ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
759
760 // Single View
761 elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
762
763 // Topic merge
764 elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
765
766 // Topic split
767 elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
768
769 // Topic edit
770 elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
771
772 // Editing a reply
773 elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
774
775 // Viewing a topic tag
776 elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
777
778 // Editing a topic tag
779 elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
780 endif;
781
782 // Custom template file exists
783 $template = !empty( $new_template ) ? $new_template : $template;
784 }
785
786 return apply_filters( 'bbp_template_include_theme_supports', $template );
787 }
788
789 /**
790 * In this next bit, either the current theme does not support bbPress, or
791 * the theme author has incorrectly used add_theme_support( 'bbpress' )
792 * and we are going to help them out by silently filling in the blanks.
793 */
794 function bbp_template_include_theme_compat( $template = '' ) {
795 global $bbp;
796
797 if ( !current_theme_supports( 'bbpress' ) || ( !empty( $bbp->theme_compat->templates ) && empty( $bbp->theme_compat->template ) ) ) {
798
799 /** Users *************************************************************/
800
801 if ( bbp_is_single_user() || bbp_is_single_user_edit() ) {
802
803 // Reset post
804 bbp_theme_compat_reset_post( array(
805 'post_title' => esc_attr( bbp_get_displayed_user_field( 'display_name' ) )
806 ) );
807
808 /** Forums ************************************************************/
809
810 // Forum archive
811 } elseif ( bbp_is_forum_archive() ) {
812
813 // Reset post
814 bbp_theme_compat_reset_post( array(
815 'ID' => 0,
816 'post_title' => bbp_get_forum_archive_title(),
817 'post_author' => 0,
818 'post_date' => 0,
819 'post_content' => '',
820 'post_type' => bbp_get_forum_post_type(),
821 'post_status' => 'publish',
822 'is_archive' => true
823 ) );
824
825 /** Topics ************************************************************/
826
827 // Topic archive
828 } elseif ( bbp_is_topic_archive() ) {
829
830 // Reset post
831 bbp_theme_compat_reset_post( array(
832 'ID' => 0,
833 'post_title' => bbp_get_topic_archive_title(),
834 'post_author' => 0,
835 'post_date' => 0,
836 'post_content' => '',
837 'post_type' => bbp_get_topic_post_type(),
838 'post_status' => 'publish',
839 'is_archive' => true
840 ) );
841
842 // Single topic
843 } elseif ( bbp_is_topic_edit() || bbp_is_topic_split() || bbp_is_topic_merge() ) {
844
845 // Reset post
846 bbp_theme_compat_reset_post( array(
847 'ID' => bbp_get_topic_id(),
848 'post_title' => bbp_get_topic_title(),
849 'post_author' => bbp_get_topic_author_id(),
850 'post_date' => 0,
851 'post_content' => get_post_field( 'post_content', bbp_get_topic_id() ),
852 'post_type' => bbp_get_topic_post_type(),
853 'post_status' => bbp_get_topic_status(),
854 'is_single' => true
855 ) );
856
857 /** Replies ***********************************************************/
858
859 // Reply archive
860 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) {
861
862 // Reset post
863 bbp_theme_compat_reset_post( array(
864 'ID' => 0,
865 'post_title' => __( 'Replies', 'bbpress' ),
866 'post_author' => 0,
867 'post_date' => 0,
868 'post_content' => '',
869 'post_type' => bbp_get_reply_post_type(),
870 'post_status' => 'publish'
871 ) );
872
873 // Single reply
874 } elseif ( bbp_is_reply_edit() ) {
875
876 // Reset post
877 bbp_theme_compat_reset_post( array(
878 'ID' => bbp_get_reply_id(),
879 'post_title' => bbp_get_reply_title(),
880 'post_author' => bbp_get_reply_author_id(),
881 'post_date' => 0,
882 'post_content' => get_post_field( 'post_content', bbp_get_reply_id() ),
883 'post_type' => bbp_get_reply_post_type(),
884 'post_status' => bbp_get_reply_status()
885 ) );
886
887 /** Views *************************************************************/
888
889 } elseif ( bbp_is_single_view() ) {
890
891 // Reset post
892 bbp_theme_compat_reset_post( array(
893 'ID' => 0,
894 'post_title' => bbp_get_view_title(),
895 'post_author' => 0,
896 'post_date' => 0,
897 'post_content' => '',
898 'post_type' => '',
899 'post_status' => 'publish'
900 ) );
901
902
903 /** Topic Tags ********************************************************/
904
905 } elseif ( bbp_is_topic_tag_edit() ) {
906
907 // Stash the current term in a new var
908 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) );
909
910 // Reset the post with our new title
911 bbp_theme_compat_reset_post( array(
912 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' )
913 ) );
914
915 } elseif ( bbp_is_topic_tag() ) {
916
917 // Stash the current term in a new var
918 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) );
919
920 // Reset the post with our new title
921 bbp_theme_compat_reset_post( array(
922 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' )
923 ) );
924
925 /** Single Forums/Topics/Replies **************************************/
926
927 } elseif ( bbp_is_custom_post_type() ) {
928 bbp_set_theme_compat_active();
929 }
930
931 /**
932 * If we are relying on bbPress's built in theme compatibility to load
933 * the proper content, we need to intercept the_content, replace the
934 * output, and display ours instead.
935 *
936 * To do this, we first remove all filters from 'the_content' and hook
937 * our own function into it, which runs a series of checks to determine
938 * the context, and then uses the built in shortcodes to output the
939 * correct results.
940 *
941 * We default to using page.php, since it's most likely to exist and
942 * should be coded to work without superfluous elements and logic, like
943 * prev/next navigation, comments, date/time, etc... You can hook into
944 * the 'bbp_template_include' filter to override page.php.
945 */
946 if ( bbp_is_theme_compat_active() ) {
947
948 // Remove all filters from the_content
949 bbp_remove_all_filters( 'the_content' );
950
951 // Add a filter on the_content late, which we will later remove
952 add_filter( 'the_content', 'bbp_replace_the_content' );
953
954 // Find the appropriate template file
955 $template = bbp_get_theme_compat_templates();
956 }
957 }
958
959 return apply_filters( 'bbp_template_include_theme_compat', $template );
960 }
961
962 /**
963 * Replaces the_content() if the post_type being displayed is one that would
964 * normally be handled by bbPress, but proper single page templates do not
965 * exist in the currently active theme.
966 *
967 * @since bbPress (r3034)
968 *
969 * @global bbPress $bbp
970 * @global WP_Query $post
971 * @param string $content
972 * @return type
973 */
974 function bbp_replace_the_content( $content = '' ) {
975
976 // Current theme does not support bbPress, so we need to do some heavy
977 // lifting to see if a bbPress template is needed in the current context
978 if ( !current_theme_supports( 'bbpress' ) ) {
979
980 // Use the $post global to check it's post_type
981 global $bbp;
982
983 // Define local variable(s)
984 $new_content = '';
985
986 // Remove the filter that was added in bbp_template_include()
987 remove_filter( 'the_content', 'bbp_replace_the_content' );
988
989 // Bail if shortcodes are unset somehow
990 if ( empty( $bbp->shortcodes ) )
991 return $content;
992
993 // Use shortcode API to display forums/topics/replies because they are
994 // already output buffered and ready to fit inside the_content
995
996 /** Users *************************************************************/
997
998 // Profile View
999 if ( bbp_is_single_user() ) {
1000 ob_start();
1001
1002 bbp_get_template_part( 'bbpress/content', 'single-user' );
1003
1004 $new_content = ob_get_contents();
1005
1006 ob_end_clean();
1007
1008 // Profile Edit
1009 } elseif ( bbp_is_single_user_edit() ) {
1010 ob_start();
1011
1012 bbp_get_template_part( 'bbpress/content', 'single-user-edit' );
1013
1014 $new_content = ob_get_contents();
1015
1016 ob_end_clean();
1017
1018 /** Forums ************************************************************/
1019
1020 // Forum archive
1021 } elseif ( bbp_is_forum_archive() ) {
1022
1023 // Page exists where this archive should be
1024 if ( $page = bbp_get_page_by_path( $bbp->root_slug ) ) {
1025
1026 // Start output buffer
1027 ob_start();
1028
1029 // Restore previously unset filters
1030 bbp_restore_all_filters( 'the_content' );
1031
1032 // Grab the content of this page
1033 $new_content = do_shortcode( apply_filters( 'the_content', get_post_field( 'post_content', $page->ID ) ) );
1034
1035 // Clean up the buffer
1036 ob_end_clean();
1037
1038 // No page so show the archive
1039 } else {
1040 $new_content = $bbp->shortcodes->display_forum_index();
1041 }
1042
1043 /** Topics ************************************************************/
1044
1045 // Topic archive
1046 } elseif ( bbp_is_topic_archive() ) {
1047
1048 // Page exists where this archive should be
1049 if ( $page = bbp_get_page_by_path( $bbp->topic_archive_slug ) ) {
1050
1051 // Start output buffer
1052 ob_start();
1053
1054 // Restore previously unset filters
1055 bbp_restore_all_filters( 'the_content' );
1056
1057 // Grab the content of this page
1058 $new_content = do_shortcode( apply_filters( 'the_content', get_post_field( 'post_content', $page->ID ) ) );
1059
1060 // Clean up the buffer
1061 ob_end_clean();
1062
1063
1064 // No page so show the archive
1065 } else {
1066 $new_content = $bbp->shortcodes->display_topic_index();
1067 }
1068
1069 // Single topic
1070 } elseif ( bbp_is_topic_edit() ) {
1071
1072 // Split
1073 if ( bbp_is_topic_split() ) {
1074 ob_start();
1075
1076 bbp_get_template_part( 'bbpress/form', 'topic-split' );
1077
1078 $new_content = ob_get_contents();
1079
1080 ob_end_clean();
1081
1082 // Merge
1083 } elseif ( bbp_is_topic_merge() ) {
1084 ob_start();
1085
1086 bbp_get_template_part( 'bbpress/form', 'topic-merge' );
1087
1088 $new_content = ob_get_contents();
1089
1090 ob_end_clean();
1091
1092 // Edit
1093 } else {
1094 $new_content = $bbp->shortcodes->display_topic_form();
1095 }
1096
1097 /** Replies ***********************************************************/
1098
1099 // Reply archive
1100 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) {
1101 //$new_content = $bbp->shortcodes->display_reply_index();
1102
1103 // Reply Edit
1104 } elseif ( bbp_is_reply_edit() ) {
1105 $new_content = $bbp->shortcodes->display_reply_form();
1106
1107 /** Views *************************************************************/
1108
1109 } elseif ( bbp_is_single_view() ) {
1110 $new_content = $bbp->shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) );
1111
1112 /** Topic Tags ********************************************************/
1113
1114 } elseif ( get_query_var( 'bbp_topic_tag' ) ) {
1115
1116 // Edit topic tag
1117 if ( bbp_is_topic_tag_edit() ) {
1118 $new_content = $bbp->shortcodes->display_topic_tag_form();
1119
1120 // Show topics of tag
1121 } else {
1122 $new_content = $bbp->shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) );
1123 }
1124
1125 /** Forums/Topics/Replies *********************************************/
1126
1127 } else {
1128
1129 // Check the post_type
1130 switch ( get_post_type() ) {
1131
1132 // Single Forum
1133 case bbp_get_forum_post_type() :
1134 $new_content = $bbp->shortcodes->display_forum( array( 'id' => get_the_ID() ) );
1135 break;
1136
1137 // Single Topic
1138 case bbp_get_topic_post_type() :
1139 $new_content = $bbp->shortcodes->display_topic( array( 'id' => get_the_ID() ) );
1140 break;
1141
1142 // Single Reply
1143 case bbp_get_reply_post_type() :
1144
1145 break;
1146 }
1147 }
1148
1149 // Juggle the content around and try to prevent unsightly comments
1150 if ( !empty( $new_content ) && ( $new_content != $content ) ) {
1151
1152 // Set the content to be the new content
1153 $content = apply_filters( 'bbp_replace_the_content', $new_content, $content );
1154
1155 // Clean up after ourselves
1156 unset( $new_content );
1157
1158 /**
1159 * Supplemental hack to prevent stubborn comments_template() output.
1160 *
1161 * By this time we can safely assume that everything we needed from
1162 * the {$post} global has been rendered into the buffer, so we're
1163 * going to empty it and {$withcomments} for good measure. This has
1164 * the added benefit of preventing an incorrect "Edit" link on the
1165 * bottom of most popular page templates, at the cost of rendering
1166 * these globals useless for the remaining page output without using
1167 * wp_reset_postdata() to get that data back.
1168 *
1169 * @see comments_template() For why we're doing this :)
1170 * @see wp_reset_postdata() If you need to get $post back
1171 *
1172 * Note: If a theme uses custom code to output comments, it's
1173 * possible all of this dancing around is for not.
1174 *
1175 * Note: If you need to keep these globals around for any special
1176 * reason, we've provided a failsafe hook to bypass this you
1177 * can put in your plugin or theme below ---v
1178 *
1179 * apply_filters( 'bbp_spill_the_beans', '__return_true' );
1180 */
1181 if ( !apply_filters( 'bbp_spill_the_beans', false ) ) {
1182
1183 // Setup the chopping block
1184 global $post, $withcomments;
1185
1186 // Empty out globals that aren't being used in this loop anymore
1187 $withcomments = $post = false;
1188 }
1189 }
1190 }
1191
1192 // Return possibly hi-jacked content
1193 return $content;
1194 }
1195
1196 /** Helpers *******************************************************************/
1197
1198 /**
1199 * Remove the canonical redirect to allow pretty pagination
1200 *
1201 * @since bbPress (r2628)
1202 *
1203 * @param string $redirect_url Redirect url
1204 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
1205 * @uses bbp_get_paged() To get the current page number
1206 * @uses bbp_is_single_topic() To check if it's a topic page
1207 * @uses bbp_is_single_forum() To check if it's a forum page
1208 * @return bool|string False if it's a topic/forum and their first page,
1209 * otherwise the redirect url
1210 */
1211 function bbp_redirect_canonical( $redirect_url ) {
1212 global $wp_rewrite;
1213
1214 // Canonical is for the beautiful
1215 if ( $wp_rewrite->using_permalinks() ) {
1216
1217 // If viewing beyond page 1 of several
1218 if ( 1 < bbp_get_paged() ) {
1219
1220 // Only on single topics...
1221 if ( bbp_is_single_topic() ) {
1222 $redirect_url = false;
1223
1224 // ...and single replies
1225 } elseif ( bbp_is_single_forum() ) {
1226 $redirect_url = false;
1227 }
1228
1229 // If editing a topic
1230 } elseif ( bbp_is_topic_edit() ) {
1231 $redirect_url = false;
1232
1233 // If editing a reply
1234 } elseif ( bbp_is_reply_edit() ) {
1235 $redirect_url = false;
1236 }
1237 }
1238
1239 return $redirect_url;
1240 }
1241
1242 /**
1243 * Sets the 404 status.
1244 *
1245 * Used primarily with topics/replies inside hidden forums.
1246 *
1247 * @since bbPress (r3051)
1248 *
1249 * @global WP_Query $wp_query
1250 * @uses WP_Query::set_404()
1251 */
1252 function bbp_set_404() {
1253 global $wp_query;
1254
1255 if ( ! isset( $wp_query ) ) {
1256 _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
1257 return false;
1258 }
1259
1260 $wp_query->set_404();
1261 }
1262
1263 /**
1264 * Used to guess if page exists at requested path
1265 *
1266 * @since bbPress (r3304)
1267 *
1268 * @uses get_option() To see if pretty permalinks are enabled
1269 * @uses get_page_by_path() To see if page exists at path
1270 *
1271 * @param string $path
1272 * @return mixed False if no page, Page object if true
1273 */
1274 function bbp_get_page_by_path( $path = '' ) {
1275
1276 // Default to false
1277 $retval = false;
1278
1279 // Path is not empty
1280 if ( !empty( $path ) ) {
1281
1282 // Pretty permalinks are on so path might exist
1283 if ( get_option( 'permalink_structure' ) ) {
1284 $retval = get_page_by_path( $path );
1285 }
1286 }
1287
1288 return apply_filters( 'bbp_get_page_by_path', $retval, $path );
1289 }
1290
1291 /** Filters *******************************************************************/
1292
1293 /**
1294 * Removes all filters from a WordPress filter, and stashes them in the $bbp
1295 * global in the event they need to be restored later.
1296 *
1297 * @since bbPress (r3251)
1298 *
1299 * @global bbPress $bbp
1300 * @global WP_filter $wp_filter
1301 * @global array $merged_filters
1302 *
1303 * @param string $tag
1304 * @param int $priority
1305 *
1306 * @return bool
1307 */
1308 function bbp_remove_all_filters( $tag, $priority = false ) {
1309 global $bbp, $wp_filter, $merged_filters;
1310
1311 // Filters exist
1312 if ( isset( $wp_filter[$tag] ) ) {
1313
1314 // Filters exist in this priority
1315 if ( !empty( $priority ) && isset( $wp_filter[$tag][$priority] ) ) {
1316
1317 // Store filters in a backup
1318 $bbp->filters->wp_filter[$tag][$priority] = $wp_filter[$tag][$priority];
1319
1320 // Unset the filters
1321 unset( $wp_filter[$tag][$priority] );
1322
1323 // Priority is empty
1324 } else {
1325
1326 // Store filters in a backup
1327 $bbp->filters->wp_filter[$tag] = $wp_filter[$tag];
1328
1329 // Unset the filters
1330 unset( $wp_filter[$tag] );
1331 }
1332 }
1333
1334 // Check merged filters
1335 if ( isset( $merged_filters[$tag] ) ) {
1336
1337 // Store filters in a backup
1338 $bbp->filters->merged_filters[$tag] = $merged_filters[$tag];
1339
1340 // Unset the filters
1341 unset( $merged_filters[$tag] );
1342 }
1343
1344 return true;
1345 }
1346
1347 /**
1348 * Restores filters from the $bbp global that were removed using
1349 * bbp_remove_all_filters()
1350 *
1351 * @since bbPress (r3251)
1352 *
1353 * @global bbPress $bbp
1354 * @global WP_filter $wp_filter
1355 * @global array $merged_filters
1356 *
1357 * @param string $tag
1358 * @param int $priority
1359 *
1360 * @return bool
1361 */
1362 function bbp_restore_all_filters( $tag, $priority = false ) {
1363 global $bbp, $wp_filter, $merged_filters;
1364
1365 // Filters exist
1366 if ( isset( $bbp->filters->wp_filter[$tag] ) ) {
1367
1368 // Filters exist in this priority
1369 if ( !empty( $priority ) && isset( $bbp->filters->wp_filter[$tag][$priority] ) ) {
1370
1371 // Store filters in a backup
1372 $wp_filter[$tag][$priority] = $bbp->filters->wp_filter[$tag][$priority];
1373
1374 // Unset the filters
1375 unset( $bbp->filters->wp_filter[$tag][$priority] );
1376
1377 // Priority is empty
1378 } else {
1379
1380 // Store filters in a backup
1381 $wp_filter[$tag] = $bbp->filters->wp_filter[$tag];
1382
1383 // Unset the filters
1384 unset( $bbp->filters->wp_filter[$tag] );
1385 }
1386 }
1387
1388 // Check merged filters
1389 if ( isset( $bbp->filters->merged_filters[$tag] ) ) {
1390
1391 // Store filters in a backup
1392 $merged_filters[$tag] = $bbp->filters->merged_filters[$tag];
1393
1394 // Unset the filters
1395 unset( $bbp->filters->merged_filters[$tag] );
1396 }
1397
1398 return true;
1399 }
1400
1401 /**
1402 * Add checks for view page, user page, user edit, topic edit and reply edit
1403 * pages.
1404 *
1405 * If it's a user page, WP_Query::bbp_is_single_user is set to true.
1406 * If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true
1407 * and the the 'wp-admin/includes/user.php' file is included.
1408 * In addition, on user/user edit pages, WP_Query::home is set to false & query
1409 * vars 'bbp_user_id' with the displayed user id and 'author_name' with the
1410 * displayed user's nicename are added.
1411 *
1412 * If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true and
1413 * similarly, if it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
1414 *
1415 * If it's a view page, WP_Query::bbp_is_view is set to true
1416 *
1417 * @since bbPress (r2688)
1418 *
1419 * @global bbPress $bbp
1420 * #global WP_Query $wp_query
1421 *
1422 * @uses get_query_var() To get {@link WP_Query} query var
1423 * @uses is_email() To check if the string is an email
1424 * @uses get_user_by() To try to get the user by email and nicename
1425 * @uses WP_User to get the user data
1426 * @uses WP_Query::set_404() To set a 404 status
1427 * @uses current_user_can() To check if the current user can edit the user
1428 * @uses apply_filters() Calls 'enable_edit_any_user_configuration' with true
1429 * @uses wp_die() To die
1430 * @uses bbp_is_query_name() Check if query name is 'bbp_widget'
1431 * @uses bbp_get_view_query_args() To get the view query args
1432 * @uses bbp_get_topic_post_type() To get the topic post type
1433 * @uses bbp_get_reply_post_type() To get the reply post type
1434 * @uses is_multisite() To check if it's a multisite
1435 * @uses remove_action() To remove the auto save post revision action
1436 */
1437 function bbp_pre_get_posts( $posts_query ) {
1438 global $bbp, $wp_the_query;
1439
1440 // Bail if $posts_query is not the main loop
1441 if ( $posts_query != $wp_the_query )
1442 return $posts_query;
1443
1444 // Bail if filters are suppressed on this query, or in admin
1445 if ( true == $posts_query->get( 'suppress_filters' ) )
1446 return $posts_query;
1447
1448 // Bail if in admin
1449 if ( is_admin() )
1450 return $posts_query;
1451
1452 // Get query variables
1453 $bbp_user = $posts_query->get( $bbp->user_id );
1454 $bbp_view = $posts_query->get( $bbp->view_id );
1455 $is_edit = $posts_query->get( $bbp->edit_id );
1456
1457 // It is a user page - We'll also check if it is user edit
1458 if ( !empty( $bbp_user ) ) {
1459
1460 // Not a user_id so try email and slug
1461 if ( !is_numeric( $bbp_user ) ) {
1462
1463 // Email was passed
1464 if ( is_email( $bbp_user ) )
1465 $bbp_user = get_user_by( 'email', $bbp_user );
1466 // Try nicename
1467 else
1468 $bbp_user = get_user_by( 'slug', $bbp_user );
1469
1470 // If we were successful, set to ID
1471 if ( is_object( $bbp_user ) )
1472 $bbp_user = $bbp_user->ID;
1473 }
1474
1475 // Create new user
1476 $user = new WP_User( $bbp_user );
1477
1478 // Stop if no user
1479 if ( !isset( $user ) || empty( $user ) || empty( $user->ID ) ) {
1480 $posts_query->set_404();
1481 return;
1482 }
1483
1484 /** User Exists *******************************************************/
1485
1486 // View or edit?
1487 if ( !empty( $is_edit ) ) {
1488
1489 // Only allow super admins on multisite to edit every user.
1490 if ( ( is_multisite() && !current_user_can( 'manage_network_users' ) && $user_id != $current_user->ID && !apply_filters( 'enable_edit_any_user_configuration', true ) ) || !current_user_can( 'edit_user', $user->ID ) )
1491 wp_die( __( 'You do not have the permission to edit this user.', 'bbpress' ) );
1492
1493 // We are editing a profile
1494 $posts_query->bbp_is_single_user_edit = true;
1495
1496 // Load the core WordPress contact methods
1497 if ( !function_exists( '_wp_get_user_contactmethods' ) )
1498 include_once( ABSPATH . 'wp-includes/registration.php' );
1499
1500 // Load the edit_user functions
1501 if ( !function_exists( 'edit_user' ) )
1502 require_once( ABSPATH . 'wp-admin/includes/user.php' );
1503
1504 // We are viewing a profile
1505 } else {
1506 $posts_query->bbp_is_single_user = true;
1507 }
1508
1509 // Make sure 404 is not set
1510 $posts_query->is_404 = false;
1511
1512 // Correct is_home variable
1513 $posts_query->is_home = false;
1514
1515 // Set bbp_user_id for future reference
1516 $posts_query->set( 'bbp_user_id', $user->ID );
1517
1518 // Set author_name as current user's nicename to get correct posts
1519 if ( !bbp_is_query_name( 'bbp_widget' ) )
1520 $posts_query->set( 'author_name', $user->user_nicename );
1521
1522 // Set the displayed user global to this user
1523 $bbp->displayed_user = $user;
1524
1525 // View Page
1526 } elseif ( !empty( $bbp_view ) ) {
1527
1528 // Check if the view exists by checking if there are query args are set
1529 $view_args = bbp_get_view_query_args( $bbp_view );
1530
1531 // Stop if view args is false - means the view isn't registered
1532 if ( false === $view_args ) {
1533 $posts_query->set_404();
1534 return;
1535 }
1536
1537 // Correct is_home variable
1538 $posts_query->is_home = false;
1539
1540 // We are in a custom topic view
1541 $posts_query->bbp_is_view = true;
1542
1543 // Topic/Reply Edit Page
1544 } elseif ( !empty( $is_edit ) ) {
1545
1546 // We are editing a topic
1547 if ( $posts_query->get( 'post_type' ) == bbp_get_topic_post_type() )
1548 $posts_query->bbp_is_topic_edit = true;
1549
1550 // We are editing a reply
1551 elseif ( $posts_query->get( 'post_type' ) == bbp_get_reply_post_type() )
1552 $posts_query->bbp_is_reply_edit = true;
1553
1554 // We are editing a topic tag
1555 elseif ( bbp_is_topic_tag() )
1556 $posts_query->bbp_is_topic_tag_edit = true;
1557
1558 // We save post revisions on our own
1559 remove_action( 'pre_post_update', 'wp_save_post_revision' );
1560
1561 // Check forum status and exclude single forums the user cannot see
1562 } elseif ( bbp_get_forum_post_type() == $posts_query->get( 'post_type' ) ) {
1563
1564 // Define local variable
1565 $status = array();
1566
1567 // All users can see published forums
1568 $status[] = 'publish';
1569
1570 // Add 'private' if user is capable
1571 if ( current_user_can( 'read_private_forums' ) )
1572 $status[] = 'private';
1573
1574 // Add 'hidden' if user is capable
1575 if ( current_user_can( 'read_hidden_forums' ) )
1576 $status[] = $bbp->hidden_status_id;
1577
1578 // Implode and add the statuses
1579 $posts_query->set( 'post_status', implode( ',', $status ) );
1580
1581 // Topic tag page
1582 } elseif ( bbp_is_topic_tag() ) {
1583 $posts_query->set( 'post_type', bbp_get_topic_post_type() );
1584 $posts_query->set( 'posts_per_page', get_option( '_bbp_topics_per_page', 15 ) );
1585 }
1586
1587 return $posts_query;
1588 }
1589
1590 ?>
1591