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

1,533 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 * @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 edit template
621 *
622 * @since bbPress (r3311)
623 *
624 * @uses bbp_get_topic_post_type()
625 * @uses apply_filters()
626 *
627 * @return array
628 */
629 function bbp_get_topic_tag_edit_template() {
630
631 $tt_id = bbp_get_topic_tag_tax_id();
632 $templates = array(
633
634 // Single Topic Tag Edit
635 'taxonomy-' . $tt_id . '-edit.php',
636 'bbpress/taxonomy-' . $tt_id . '-edit.php',
637 'forums/taxonomy-' . $tt_id . '-edit.php',
638
639 // Single Topic Tag
640 'taxonomy-' . $tt_id . '.php',
641 'forums/taxonomy-' . $tt_id . '.php',
642 'bbpress/taxonomy-' . $tt_id . '.php',
643 );
644
645 $templates = apply_filters( 'bbp_get_topic_tag_edit_template', $templates );
646 $templates = bbp_set_theme_compat_templates( $templates );
647
648 $template = locate_template( $templates, false, false );
649 $template = bbp_set_theme_compat_template( $template );
650
651 return $template;
652 }
653
654 /**
655 * Get the files to fallback on to use for theme compatibility
656 *
657 * @since bbPress (r3311)
658 *
659 * @uses apply_filters()
660 * @uses bbp_set_theme_compat_templates();
661 *
662 * @return type
663 */
664 function bbp_get_theme_compat_templates() {
665
666 $templates = array(
667 'bbpress.php',
668 'forum.php',
669 'page.php',
670 'single.php',
671 'index.php'
672 );
673
674 $templates = apply_filters( 'bbp_get_theme_compat_templates', $templates );
675 $templates = bbp_set_theme_compat_templates( $templates );
676
677 $template = locate_template( $templates, false, false );
678 $template = bbp_set_theme_compat_template( $template );
679
680 return $template;
681 }
682
683 /**
684 * Possibly intercept the template being loaded
685 *
686 * Listens to the 'template_include' filter and waits for a bbPress post_type
687 * to appear. If the current theme does not explicitly support bbPress, it
688 * intercepts the page template and uses one served from the bbPress compatable
689 * theme, set in the $bbp->theme_compat global. If the current theme does
690 * support bbPress, we'll explore the template hierarchy and try to locate one.
691 *
692 * @since bbPress (r3032)
693 *
694 * @global bbPress $bbp
695 * @global WP_Query $post
696 *
697 * @param string $template
698 *
699 * @uses current_theme_supports() To check if theme supports bbPress
700 * @uses bbp_is_single_user() To check if page is single user
701 * @uses bbp_get_single_user_template() To get user template
702 * @uses bbp_is_single_user_edit() To check if page is single user edit
703 * @uses bbp_get_single_user_edit_template() To get user edit template
704 * @uses bbp_is_single_view() To check if page is single view
705 * @uses bbp_get_single_view_template() To get view template
706 * @uses bbp_is_topic_merge() To check if page is topic merge
707 * @uses bbp_get_topic_merge_template() To get topic merge template
708 * @uses bbp_is_topic_split() To check if page is topic split
709 * @uses bbp_get_topic_split_template() To get topic split template
710 * @uses bbp_is_topic_edit() To check if page is topic edit
711 * @uses bbp_get_topic_edit_template() To get topic edit template
712 * @uses bbp_is_reply_edit() To check if page is reply edit
713 * @uses bbp_get_reply_edit_template() To get reply edit template
714 * @uses bbp_set_theme_compat_template() To set the global theme compat template
715 *
716 * @return string The path to the template file that is being used
717 */
718 function bbp_template_include_theme_supports( $template = '' ) {
719 global $bbp;
720
721 // Current theme supports bbPress
722 if ( current_theme_supports( 'bbpress' ) ) {
723
724 // Viewing a user
725 if ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) :
726
727 // Editing a user
728 elseif ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) :
729
730 // Single View
731 elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) :
732
733 // Topic merge
734 elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) :
735
736 // Topic split
737 elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) :
738
739 // Topic edit
740 elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) :
741
742 // Editing a reply
743 elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) :
744
745 // Editing a topic tag
746 elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) :
747
748 // Editing a topic tag
749 elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) :
750 endif;
751
752 // Custom template file exists
753 $template = !empty( $new_template ) ? $new_template : $template;
754 }
755
756 return apply_filters( 'bbp_template_include_theme_supports', $template );
757 }
758
759 /**
760 * In this next bit, either the current theme does not support bbPress, or
761 * the theme author has incorrectly used add_theme_support( 'bbpress' )
762 * and we are going to help them out by silently filling in the blanks.
763 */
764 function bbp_template_include_theme_compat( $template = '' ) {
765 global $bbp;
766
767 if ( !current_theme_supports( 'bbpress' ) || ( !empty( $bbp->theme_compat->templates ) && empty( $bbp->theme_compat->template ) ) ) {
768
769 /** Users *************************************************************/
770
771 if ( bbp_is_single_user() || bbp_is_single_user_edit() ) {
772
773 // Reset post
774 bbp_theme_compat_reset_post( array(
775 'post_title' => esc_attr( bbp_get_displayed_user_field( 'display_name' ) )
776 ) );
777
778 /** Forums ************************************************************/
779
780 // Forum archive
781 } elseif ( bbp_is_forum_archive() ) {
782
783 // Reset post
784 bbp_theme_compat_reset_post( array(
785 'ID' => 0,
786 'post_title' => bbp_get_forum_archive_title(),
787 'post_author' => 0,
788 'post_date' => 0,
789 'post_content' => '',
790 'post_type' => bbp_get_forum_post_type(),
791 'post_status' => 'publish',
792 'is_archive' => true
793 ) );
794
795 /** Topics ************************************************************/
796
797 // Topic archive
798 } elseif ( bbp_is_topic_archive() ) {
799
800 // Reset post
801 bbp_theme_compat_reset_post( array(
802 'ID' => 0,
803 'post_title' => bbp_get_topic_archive_title(),
804 'post_author' => 0,
805 'post_date' => 0,
806 'post_content' => '',
807 'post_type' => bbp_get_topic_post_type(),
808 'post_status' => 'publish',
809 'is_archive' => true
810 ) );
811
812 // Single topic
813 } elseif ( bbp_is_topic_edit() || bbp_is_topic_split() || bbp_is_topic_merge() ) {
814
815 // Reset post
816 bbp_theme_compat_reset_post( array(
817 'ID' => bbp_get_topic_id(),
818 'post_title' => bbp_get_topic_title(),
819 'post_author' => bbp_get_topic_author_id(),
820 'post_date' => 0,
821 'post_content' => get_post_field( 'post_content', bbp_get_topic_id() ),
822 'post_type' => bbp_get_topic_post_type(),
823 'post_status' => bbp_get_topic_status(),
824 'is_single' => true
825 ) );
826
827 /** Replies ***********************************************************/
828
829 // Reply archive
830 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) {
831
832 // Reset post
833 bbp_theme_compat_reset_post( array(
834 'ID' => 0,
835 'post_title' => __( 'Replies', 'bbpress' ),
836 'post_author' => 0,
837 'post_date' => 0,
838 'post_content' => '',
839 'post_type' => bbp_get_reply_post_type(),
840 'post_status' => 'publish'
841 ) );
842
843 // Single reply
844 } elseif ( bbp_is_reply_edit() ) {
845
846 // Reset post
847 bbp_theme_compat_reset_post( array(
848 'ID' => bbp_get_reply_id(),
849 'post_title' => bbp_get_reply_title(),
850 'post_author' => bbp_get_reply_author_id(),
851 'post_date' => 0,
852 'post_content' => get_post_field( 'post_content', bbp_get_reply_id() ),
853 'post_type' => bbp_get_reply_post_type(),
854 'post_status' => bbp_get_reply_status()
855 ) );
856
857 /** Views *************************************************************/
858
859 } elseif ( bbp_is_single_view() ) {
860
861 // Reset post
862 bbp_theme_compat_reset_post( array(
863 'ID' => 0,
864 'post_title' => bbp_get_view_title(),
865 'post_author' => 0,
866 'post_date' => 0,
867 'post_content' => '',
868 'post_type' => '',
869 'post_status' => 'publish'
870 ) );
871
872
873 /** Topic Tags ********************************************************/
874
875 } elseif ( bbp_is_topic_tag_edit() ) {
876
877 // Stash the current term in a new var
878 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) );
879
880 // Reset the post with our new title
881 bbp_theme_compat_reset_post( array(
882 'post_title' => sprintf( __( 'Edit Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' )
883 ) );
884
885 } elseif ( bbp_is_topic_tag() ) {
886
887 // Stash the current term in a new var
888 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) );
889
890 // Reset the post with our new title
891 bbp_theme_compat_reset_post( array(
892 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' )
893 ) );
894
895 /** Single Forums/Topics/Replies **************************************/
896
897 } elseif ( bbp_is_custom_post_type() ) {
898 bbp_set_theme_compat_active();
899 }
900
901 /**
902 * If we are relying on bbPress's built in theme compatibility to load
903 * the proper content, we need to intercept the_content, replace the
904 * output, and display ours instead.
905 *
906 * To do this, we first remove all filters from 'the_content' and hook
907 * our own function into it, which runs a series of checks to determine
908 * the context, and then uses the built in shortcodes to output the
909 * correct results.
910 *
911 * We default to using page.php, since it's most likely to exist and
912 * should be coded to work without superfluous elements and logic, like
913 * prev/next navigation, comments, date/time, etc... You can hook into
914 * the 'bbp_template_include' filter to override page.php.
915 */
916 if ( bbp_is_theme_compat_active() ) {
917
918 // Remove all filters from the_content
919 bbp_remove_all_filters( 'the_content' );
920
921 // Add a filter on the_content late, which we will later remove
922 add_filter( 'the_content', 'bbp_replace_the_content' );
923
924 // Find the appropriate template file
925 $template = bbp_get_theme_compat_templates();
926 }
927 }
928
929 return apply_filters( 'bbp_template_include_theme_compat', $template );
930 }
931
932 /**
933 * Replaces the_content() if the post_type being displayed is one that would
934 * normally be handled by bbPress, but proper single page templates do not
935 * exist in the currently active theme.
936 *
937 * @since bbPress (r3034)
938 *
939 * @global bbPress $bbp
940 * @global WP_Query $post
941 * @param string $content
942 * @return type
943 */
944 function bbp_replace_the_content( $content = '' ) {
945
946 // Current theme does not support bbPress, so we need to do some heavy
947 // lifting to see if a bbPress template is needed in the current context
948 if ( !current_theme_supports( 'bbpress' ) ) {
949
950 // Use the $post global to check it's post_type
951 global $bbp;
952
953 // Define local variable(s)
954 $new_content = '';
955
956 // Remove the filter that was added in bbp_template_include()
957 remove_filter( 'the_content', 'bbp_replace_the_content' );
958
959 // Bail if shortcodes are unset somehow
960 if ( empty( $bbp->shortcodes ) )
961 return $content;
962
963 // Use shortcode API to display forums/topics/replies because they are
964 // already output buffered and ready to fit inside the_content
965
966 /** Users *************************************************************/
967
968 // Profile View
969 if ( bbp_is_single_user() ) {
970 ob_start();
971
972 bbp_get_template_part( 'bbpress/content', 'single-user' );
973
974 $new_content = ob_get_contents();
975
976 ob_end_clean();
977
978 // Profile Edit
979 } elseif ( bbp_is_single_user_edit() ) {
980 ob_start();
981
982 bbp_get_template_part( 'bbpress/content', 'single-user-edit' );
983
984 $new_content = ob_get_contents();
985
986 ob_end_clean();
987
988 /** Forums ************************************************************/
989
990 // Forum archive
991 } elseif ( bbp_is_forum_archive() ) {
992
993 // Page exists where this archive should be
994 if ( $page = bbp_get_page_by_path( $bbp->root_slug ) ) {
995
996 // Start output buffer
997 ob_start();
998
999 // Restore previously unset filters
1000 bbp_restore_all_filters( 'the_content' );
1001
1002 // Grab the content of this page
1003 $new_content = do_shortcode( apply_filters( 'the_content', get_post_field( 'post_content', $page->ID ) ) );
1004
1005 // Clean up the buffer
1006 ob_end_clean();
1007
1008 // No page so show the archive
1009 } else {
1010 $new_content = $bbp->shortcodes->display_forum_index();
1011 }
1012
1013 /** Topics ************************************************************/
1014
1015 // Topic archive
1016 } elseif ( bbp_is_topic_archive() ) {
1017
1018 // Page exists where this archive should be
1019 if ( $page = bbp_get_page_by_path( $bbp->topic_archive_slug ) ) {
1020
1021 // Start output buffer
1022 ob_start();
1023
1024 // Restore previously unset filters
1025 bbp_restore_all_filters( 'the_content' );
1026
1027 // Grab the content of this page
1028 $new_content = do_shortcode( apply_filters( 'the_content', get_post_field( 'post_content', $page->ID ) ) );
1029
1030 // Clean up the buffer
1031 ob_end_clean();
1032
1033
1034 // No page so show the archive
1035 } else {
1036 $new_content = $bbp->shortcodes->display_topic_index();
1037 }
1038
1039 // Single topic
1040 } elseif ( bbp_is_topic_edit() ) {
1041
1042 // Split
1043 if ( bbp_is_topic_split() ) {
1044 ob_start();
1045
1046 bbp_get_template_part( 'bbpress/form', 'topic-split' );
1047
1048 $new_content = ob_get_contents();
1049
1050 ob_end_clean();
1051
1052 // Merge
1053 } elseif ( bbp_is_topic_merge() ) {
1054 ob_start();
1055
1056 bbp_get_template_part( 'bbpress/form', 'topic-merge' );
1057
1058 $new_content = ob_get_contents();
1059
1060 ob_end_clean();
1061
1062 // Edit
1063 } else {
1064 $new_content = $bbp->shortcodes->display_topic_form();
1065 }
1066
1067 /** Replies ***********************************************************/
1068
1069 // Reply archive
1070 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) {
1071 //$new_content = $bbp->shortcodes->display_reply_index();
1072
1073 // Reply Edit
1074 } elseif ( bbp_is_reply_edit() ) {
1075 $new_content = $bbp->shortcodes->display_reply_form();
1076
1077 /** Views *************************************************************/
1078
1079 } elseif ( bbp_is_single_view() ) {
1080 $new_content = $bbp->shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) );
1081
1082 /** Topic Tags ********************************************************/
1083
1084 } elseif ( get_query_var( 'bbp_topic_tag' ) ) {
1085
1086 // Edit topic tag
1087 if ( bbp_is_topic_tag_edit() ) {
1088 $new_content = $bbp->shortcodes->display_topic_tag_form();
1089
1090 // Show topics of tag
1091 } else {
1092 $new_content = $bbp->shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) );
1093 }
1094
1095 /** Forums/Topics/Replies *********************************************/
1096
1097 } else {
1098
1099 // Check the post_type
1100 switch ( get_post_type() ) {
1101
1102 // Single Forum
1103 case bbp_get_forum_post_type() :
1104 $new_content = $bbp->shortcodes->display_forum( array( 'id' => get_the_ID() ) );
1105 break;
1106
1107 // Single Topic
1108 case bbp_get_topic_post_type() :
1109 $new_content = $bbp->shortcodes->display_topic( array( 'id' => get_the_ID() ) );
1110 break;
1111
1112 // Single Reply
1113 case bbp_get_reply_post_type() :
1114
1115 break;
1116 }
1117 }
1118
1119 // Juggle the content around and try to prevent unsightly comments
1120 if ( !empty( $new_content ) && ( $new_content != $content ) ) {
1121
1122 // Set the content to be the new content
1123 $content = apply_filters( 'bbp_replace_the_content', $new_content, $content );
1124
1125 // Clean up after ourselves
1126 unset( $new_content );
1127
1128 /**
1129 * Supplemental hack to prevent stubborn comments_template() output.
1130 *
1131 * By this time we can safely assume that everything we needed from
1132 * the {$post} global has been rendered into the buffer, so we're
1133 * going to empty it and {$withcomments} for good measure. This has
1134 * the added benefit of preventing an incorrect "Edit" link on the
1135 * bottom of most popular page templates, at the cost of rendering
1136 * these globals useless for the remaining page output without using
1137 * wp_reset_postdata() to get that data back.
1138 *
1139 * @see comments_template() For why we're doing this :)
1140 * @see wp_reset_postdata() If you need to get $post back
1141 *
1142 * Note: If a theme uses custom code to output comments, it's
1143 * possible all of this dancing around is for not.
1144 *
1145 * Note: If you need to keep these globals around for any special
1146 * reason, we've provided a failsafe hook to bypass this you
1147 * can put in your plugin or theme below ---v
1148 *
1149 * apply_filters( 'bbp_spill_the_beans', '__return_true' );
1150 */
1151 if ( !apply_filters( 'bbp_spill_the_beans', false ) ) {
1152
1153 // Setup the chopping block
1154 global $post, $withcomments;
1155
1156 // Empty out globals that aren't being used in this loop anymore
1157 $withcomments = $post = false;
1158 }
1159 }
1160 }
1161
1162 // Return possibly hi-jacked content
1163 return $content;
1164 }
1165
1166 /** Helpers *******************************************************************/
1167
1168 /**
1169 * Remove the canonical redirect to allow pretty pagination
1170 *
1171 * @since bbPress (r2628)
1172 *
1173 * @param string $redirect_url Redirect url
1174 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
1175 * @uses bbp_get_paged() To get the current page number
1176 * @uses bbp_is_single_topic() To check if it's a topic page
1177 * @uses bbp_is_single_forum() To check if it's a forum page
1178 * @return bool|string False if it's a topic/forum and their first page,
1179 * otherwise the redirect url
1180 */
1181 function bbp_redirect_canonical( $redirect_url ) {
1182 global $wp_rewrite;
1183
1184 // Canonical is for the beautiful
1185 if ( $wp_rewrite->using_permalinks() ) {
1186
1187 // Only if paginating
1188 if ( 1 < bbp_get_paged() ) {
1189
1190 // Only on single topics...
1191 if ( bbp_is_single_topic() ) {
1192 $redirect_url = false;
1193
1194 // ...and single replies
1195 } elseif ( bbp_is_single_forum() ) {
1196 $redirect_url = false;
1197 }
1198 }
1199 }
1200
1201 return $redirect_url;
1202 }
1203
1204 /**
1205 * Sets the 404 status.
1206 *
1207 * Used primarily with topics/replies inside hidden forums.
1208 *
1209 * @since bbPress (r3051)
1210 *
1211 * @global WP_Query $wp_query
1212 * @uses WP_Query::set_404()
1213 */
1214 function bbp_set_404() {
1215 global $wp_query;
1216
1217 if ( ! isset( $wp_query ) ) {
1218 _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
1219 return false;
1220 }
1221
1222 $wp_query->set_404();
1223 }
1224
1225 /**
1226 * Used to guess if page exists at requested path
1227 *
1228 * @since bbPress (r3304)
1229 *
1230 * @uses get_option() To see if pretty permalinks are enabled
1231 * @uses get_page_by_path() To see if page exists at path
1232 *
1233 * @param string $path
1234 * @return mixed False if no page, Page object if true
1235 */
1236 function bbp_get_page_by_path( $path = '' ) {
1237
1238 // Default to false
1239 $retval = false;
1240
1241 // Path is not empty
1242 if ( !empty( $path ) ) {
1243
1244 // Pretty permalinks are on so path might exist
1245 if ( get_option( 'permalink_structure' ) ) {
1246 $retval = get_page_by_path( $path );
1247 }
1248 }
1249
1250 return apply_filters( 'bbp_get_page_by_path', $retval, $path );
1251 }
1252
1253 /** Filters *******************************************************************/
1254
1255 /**
1256 * Removes all filters from a WordPress filter, and stashes them in the $bbp
1257 * global in the event they need to be restored later.
1258 *
1259 * @since bbPress (r3251)
1260 *
1261 * @global bbPress $bbp
1262 * @global WP_filter $wp_filter
1263 * @global array $merged_filters
1264 *
1265 * @param string $tag
1266 * @param int $priority
1267 *
1268 * @return bool
1269 */
1270 function bbp_remove_all_filters( $tag, $priority = false ) {
1271 global $bbp, $wp_filter, $merged_filters;
1272
1273 // Filters exist
1274 if ( isset( $wp_filter[$tag] ) ) {
1275
1276 // Filters exist in this priority
1277 if ( !empty( $priority ) && isset( $wp_filter[$tag][$priority] ) ) {
1278
1279 // Store filters in a backup
1280 $bbp->filters->wp_filter[$tag][$priority] = $wp_filter[$tag][$priority];
1281
1282 // Unset the filters
1283 unset( $wp_filter[$tag][$priority] );
1284
1285 // Priority is empty
1286 } else {
1287
1288 // Store filters in a backup
1289 $bbp->filters->wp_filter[$tag] = $wp_filter[$tag];
1290
1291 // Unset the filters
1292 unset( $wp_filter[$tag] );
1293 }
1294 }
1295
1296 // Check merged filters
1297 if ( isset( $merged_filters[$tag] ) ) {
1298
1299 // Store filters in a backup
1300 $bbp->filters->merged_filters[$tag] = $merged_filters[$tag];
1301
1302 // Unset the filters
1303 unset( $merged_filters[$tag] );
1304 }
1305
1306 return true;
1307 }
1308
1309 /**
1310 * Restores filters from the $bbp global that were removed using
1311 * bbp_remove_all_filters()
1312 *
1313 * @since bbPress (r3251)
1314 *
1315 * @global bbPress $bbp
1316 * @global WP_filter $wp_filter
1317 * @global array $merged_filters
1318 *
1319 * @param string $tag
1320 * @param int $priority
1321 *
1322 * @return bool
1323 */
1324 function bbp_restore_all_filters( $tag, $priority = false ) {
1325 global $bbp, $wp_filter, $merged_filters;
1326
1327 // Filters exist
1328 if ( isset( $bbp->filters->wp_filter[$tag] ) ) {
1329
1330 // Filters exist in this priority
1331 if ( !empty( $priority ) && isset( $bbp->filters->wp_filter[$tag][$priority] ) ) {
1332
1333 // Store filters in a backup
1334 $wp_filter[$tag][$priority] = $bbp->filters->wp_filter[$tag][$priority];
1335
1336 // Unset the filters
1337 unset( $bbp->filters->wp_filter[$tag][$priority] );
1338
1339 // Priority is empty
1340 } else {
1341
1342 // Store filters in a backup
1343 $wp_filter[$tag] = $bbp->filters->wp_filter[$tag];
1344
1345 // Unset the filters
1346 unset( $bbp->filters->wp_filter[$tag] );
1347 }
1348 }
1349
1350 // Check merged filters
1351 if ( isset( $bbp->filters->merged_filters[$tag] ) ) {
1352
1353 // Store filters in a backup
1354 $merged_filters[$tag] = $bbp->filters->merged_filters[$tag];
1355
1356 // Unset the filters
1357 unset( $bbp->filters->merged_filters[$tag] );
1358 }
1359
1360 return true;
1361 }
1362
1363 /**
1364 * Add checks for view page, user page, user edit, topic edit and reply edit
1365 * pages.
1366 *
1367 * If it's a user page, WP_Query::bbp_is_single_user is set to true.
1368 * If it's a user edit page, WP_Query::bbp_is_single_user_edit is set to true
1369 * and the the 'wp-admin/includes/user.php' file is included.
1370 * In addition, on user/user edit pages, WP_Query::home is set to false & query
1371 * vars 'bbp_user_id' with the displayed user id and 'author_name' with the
1372 * displayed user's nicename are added.
1373 *
1374 * If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true and
1375 * similarly, if it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
1376 *
1377 * If it's a view page, WP_Query::bbp_is_view is set to true
1378 *
1379 * @since bbPress (r2688)
1380 *
1381 * @global bbPress $bbp
1382 * #global WP_Query $wp_query
1383 *
1384 * @uses get_query_var() To get {@link WP_Query} query var
1385 * @uses is_email() To check if the string is an email
1386 * @uses get_user_by() To try to get the user by email and nicename
1387 * @uses WP_User to get the user data
1388 * @uses WP_Query::set_404() To set a 404 status
1389 * @uses current_user_can() To check if the current user can edit the user
1390 * @uses apply_filters() Calls 'enable_edit_any_user_configuration' with true
1391 * @uses wp_die() To die
1392 * @uses bbp_is_query_name() Check if query name is 'bbp_widget'
1393 * @uses bbp_get_view_query_args() To get the view query args
1394 * @uses bbp_get_topic_post_type() To get the topic post type
1395 * @uses bbp_get_reply_post_type() To get the reply post type
1396 * @uses is_multisite() To check if it's a multisite
1397 * @uses remove_action() To remove the auto save post revision action
1398 */
1399 function bbp_pre_get_posts( $posts_query ) {
1400 global $bbp, $wp_the_query;
1401
1402 // Bail if $posts_query is not the main loop
1403 if ( $posts_query != $wp_the_query )
1404 return $posts_query;
1405
1406 // Bail if filters are suppressed on this query, or in admin
1407 if ( true == $posts_query->get( 'suppress_filters' ) )
1408 return $posts_query;
1409
1410 // Bail if in admin
1411 if ( is_admin() )
1412 return $posts_query;
1413
1414 // Get query variables
1415 $bbp_user = $posts_query->get( $bbp->user_id );
1416 $bbp_view = $posts_query->get( $bbp->view_id );
1417 $is_edit = $posts_query->get( $bbp->edit_id );
1418
1419 // It is a user page - We'll also check if it is user edit
1420 if ( !empty( $bbp_user ) ) {
1421
1422 // Not a user_id so try email and slug
1423 if ( !is_numeric( $bbp_user ) ) {
1424
1425 // Email was passed
1426 if ( is_email( $bbp_user ) )
1427 $bbp_user = get_user_by( 'email', $bbp_user );
1428 // Try nicename
1429 else
1430 $bbp_user = get_user_by( 'slug', $bbp_user );
1431
1432 // If we were successful, set to ID
1433 if ( is_object( $bbp_user ) )
1434 $bbp_user = $bbp_user->ID;
1435 }
1436
1437 // Create new user
1438 $user = new WP_User( $bbp_user );
1439
1440 // Stop if no user
1441 if ( !isset( $user ) || empty( $user ) || empty( $user->ID ) ) {
1442 $posts_query->set_404();
1443 return;
1444 }
1445
1446 /** User Exists *******************************************************/
1447
1448 // View or edit?
1449 if ( !empty( $is_edit ) ) {
1450
1451 // Only allow super admins on multisite to edit every user.
1452 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 ) )
1453 wp_die( __( 'You do not have the permission to edit this user.', 'bbpress' ) );
1454
1455 // We are editing a profile
1456 $posts_query->bbp_is_single_user_edit = true;
1457
1458 // Load the core WordPress contact methods
1459 if ( !function_exists( '_wp_get_user_contactmethods' ) )
1460 include_once( ABSPATH . 'wp-includes/registration.php' );
1461
1462 // Load the edit_user functions
1463 if ( !function_exists( 'edit_user' ) )
1464 require_once( ABSPATH . 'wp-admin/includes/user.php' );
1465
1466 // We are viewing a profile
1467 } else {
1468 $posts_query->bbp_is_single_user = true;
1469 }
1470
1471 // Make sure 404 is not set
1472 $posts_query->is_404 = false;
1473
1474 // Correct is_home variable
1475 $posts_query->is_home = false;
1476
1477 // Set bbp_user_id for future reference
1478 $posts_query->query_vars['bbp_user_id'] = $user->ID;
1479
1480 // Set author_name as current user's nicename to get correct posts
1481 if ( !bbp_is_query_name( 'bbp_widget' ) )
1482 $posts_query->query_vars['author_name'] = $user->user_nicename;
1483
1484 // Set the displayed user global to this user
1485 $bbp->displayed_user = $user;
1486
1487 // View Page
1488 } elseif ( !empty( $bbp_view ) ) {
1489
1490 // Check if the view exists by checking if there are query args are set
1491 $view_args = bbp_get_view_query_args( $bbp_view );
1492
1493 // Stop if view args is false - means the view isn't registered
1494 if ( false === $view_args ) {
1495 $posts_query->set_404();
1496 return;
1497 }
1498
1499 // Correct is_home variable
1500 $posts_query->is_home = false;
1501
1502 // We are in a custom topic view
1503 $posts_query->bbp_is_view = true;
1504
1505 // Topic/Reply Edit Page
1506 } elseif ( !empty( $is_edit ) ) {
1507
1508 // We are editing a topic
1509 if ( $posts_query->get( 'post_type' ) == bbp_get_topic_post_type() )
1510 $posts_query->bbp_is_topic_edit = true;
1511
1512 // We are editing a reply
1513 elseif ( $posts_query->get( 'post_type' ) == bbp_get_reply_post_type() )
1514 $posts_query->bbp_is_reply_edit = true;
1515
1516 // We are editing a topic tag
1517 elseif ( bbp_is_topic_tag() )
1518 $posts_query->bbp_is_topic_tag_edit = true;
1519
1520 // We save post revisions on our own
1521 remove_action( 'pre_post_update', 'wp_save_post_revision' );
1522
1523 // Topic tag page
1524 } elseif ( bbp_is_topic_tag() ) {
1525 $posts_query->query_vars['post_type'] = bbp_get_topic_post_type();
1526 $posts_query->query_vars['posts_per_page'] = get_option( '_bbp_topics_per_page', 15 );
1527 }
1528
1529 return $posts_query;
1530 }
1531
1532 ?>
1533