PluginProbe
bbPress / 2.0-rc-2
bbPress v2.0-rc-2
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-2, at bbp-includes/bbp-core-compatibility.php

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