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

853 lines 25.2 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 // Redirect 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 * Adds bbPress theme support to any active WordPress theme
27 *
28 * This function is really cool because it's responsible for managing the
29 * theme compatability layer when the current theme does not support bbPress.
30 * It uses the current_theme_supports() WordPress function to see if 'bbpress'
31 * is explicitly supported. If not, it will directly load the requested template
32 * part using load_template(). If so, it proceeds with using get_template_part()
33 * as per normal, and no one is the wiser.
34 *
35 * @since bbPress (r3032)
36 *
37 * @param string $slug
38 * @param string $name Optional. Default null
39 * @uses current_theme_supports()
40 * @uses load_template()
41 * @uses get_template_part()
42 */
43 function bbp_get_template_part( $slug, $name = null ) {
44
45 // Current theme does not support bbPress, so we need to do some heavy
46 // lifting to see if a bbPress template is needed in the current context
47 if ( !current_theme_supports( 'bbpress' ) )
48 load_template( bbp_get_theme_compat() . '/' . $slug . '-' . $name . '.php', false );
49
50 // Current theme supports bbPress to proceed as usual
51 else
52 get_template_part( $slug, $name );
53
54 }
55
56 /**
57 * Gets the bbPress compatable theme used in the event the currently active
58 * WordPress theme does not explicitly support bbPress. This can be filtered,
59 * or set manually. Tricky theme authors can override the default and include
60 * their own bbPress compatability layers for their themes.
61 *
62 * @since bbPress (r3032)
63 *
64 * @global bbPress $bbp
65 * @uses apply_filters()
66 * @return string
67 */
68 function bbp_get_theme_compat() {
69 global $bbp;
70
71 return apply_filters( 'bbp_get_theme_compat', $bbp->theme_compat );
72 }
73
74 /**
75 * Sets the bbPress compatable theme used in the event the currently active
76 * WordPress theme does not explicitly support bbPress. This can be filtered,
77 * or set manually. Tricky theme authors can override the default and include
78 * their own bbPress compatability layers for their themes.
79 *
80 * @since bbPress (r3032)
81 *
82 * @global bbPress $bbp
83 * @param string $theme Optional. Must be full absolute path to theme
84 * @uses apply_filters()
85 * @return string
86 */
87 function bbp_set_theme_compat( $theme = '' ) {
88 global $bbp;
89
90 // Set theme to bundled bbp-twentyten if nothing is passed
91 if ( empty( $theme ) && !empty( $bbp->themes_dir ) )
92 $bbp->theme_compat = $bbp->themes_dir . '/bbp-twentyten';
93
94 // Set to what is passed
95 else
96 $bbp->theme_compat = $theme;
97
98 return apply_filters( 'bbp_get_theme_compat', $bbp->theme_compat );
99 }
100
101 /**
102 * This fun little function fills up some WordPress globals with dummy data to
103 * stop your average page template from complaining about it missing.
104 *
105 * @since bbPress (r3108)
106 *
107 * @global WP_Query $wp_query
108 * @global object $post
109 * @param array $args
110 */
111 function bbp_theme_compat_reset_post( $args = array() ) {
112 global $wp_query, $post;
113
114 // Why would you ever want to do this otherwise?
115 if ( current_theme_supports( 'bbpress' ) )
116 wp_die( __( 'Hands off, partner!', 'bbpress' ) );
117
118 // Default for current post
119 if ( isset( $wp_query->post ) ) {
120 $defaults = array(
121 'ID' => get_the_ID(),
122 'post_title' => get_the_title(),
123 'post_author' => get_the_author_meta('ID'),
124 'post_date' => get_the_date(),
125 'post_content' => get_the_content(),
126 'post_type' => get_post_type(),
127 'post_status' => get_post_status()
128 );
129
130 // Empty defaults
131 } else {
132 $defaults = array(
133 'ID' => 0,
134 'post_title' => '',
135 'post_author' => 0,
136 'post_date' => 0,
137 'post_content' => '',
138 'post_type' => 'page',
139 'post_status' => 'publish'
140 );
141 }
142 $dummy = wp_parse_args( $args, $defaults );
143
144 // Setup the dummy post object
145 $wp_query->post->ID = $dummy['ID'];
146 $wp_query->post->post_title = $dummy['post_title'];
147 $wp_query->post->post_author = $dummy['post_author'];
148 $wp_query->post->post_date = $dummy['post_date'];
149 $wp_query->post->post_content = $dummy['post_content'];
150 $wp_query->post->post_type = $dummy['post_type'];
151 $wp_query->post->post_status = $dummy['post_status'];
152
153 // Set the $post global
154 $post = $wp_query->post;
155
156 // Setup the dummy post loop
157 $wp_query->posts[] = $wp_query->post;
158
159 // Prevent comments form from appearing
160 $wp_query->post_count = 1;
161 $wp_query->is_404 = false;
162 $wp_query->is_page = false;
163 $wp_query->is_single = false;
164 $wp_query->is_archive = false;
165 $wp_query->is_tax = false;
166 }
167
168 /**
169 * Add checks for view page, user page, user edit, topic edit and reply edit
170 * pages.
171 *
172 * If it's a user page, WP_Query::bbp_is_user_profile_page is set to true.
173 * If it's a user edit page, WP_Query::bbp_is_user_profile_edit is set to true
174 * and the the 'wp-admin/includes/user.php' file is included.
175 * In addition, on user/user edit pages, WP_Query::home is set to false & query
176 * vars 'bbp_user_id' with the displayed user id and 'author_name' with the
177 * displayed user's nicename are added.
178 *
179 * If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true and
180 * similarly, if it's a reply edit, WP_Query::bbp_is_reply_edit is set to true.
181 *
182 * If it's a view page, WP_Query::bbp_is_view is set to true
183 *
184 * @since bbPress (r2688)
185 *
186 * @uses get_query_var() To get {@link WP_Query} query var
187 * @uses is_email() To check if the string is an email
188 * @uses get_user_by() To try to get the user by email and nicename
189 * @uses WP_User to get the user data
190 * @uses WP_Query::set_404() To set a 404 status
191 * @uses current_user_can() To check if the current user can edit the user
192 * @uses apply_filters() Calls 'enable_edit_any_user_configuration' with true
193 * @uses wp_die() To die
194 * @uses bbp_is_query_name() Check if query name is 'bbp_widget'
195 * @uses bbp_get_view_query_args() To get the view query args
196 * @uses bbp_get_topic_post_type() To get the topic post type
197 * @uses bbp_get_reply_post_type() To get the reply post type
198 * @uses is_multisite() To check if it's a multisite
199 * @uses remove_action() To remove the auto save post revision action
200 */
201 function bbp_pre_get_posts( $posts_query ) {
202 global $bbp;
203
204 // Bail if $posts_query is not an object or of incorrect class
205 if ( !is_object( $posts_query ) || ( 'WP_Query' != get_class( $posts_query ) ) )
206 return $posts_query;
207
208 // Bail if filters are suppressed on this query
209 if ( true == $posts_query->get( 'suppress_filters' ) )
210 return $posts_query;
211
212 // Get query variables
213 $bbp_user = $posts_query->get( 'bbp_user' );
214 $bbp_view = $posts_query->get( 'bbp_view' );
215 $is_edit = $posts_query->get( 'edit' );
216
217 // It is a user page - We'll also check if it is user edit
218 if ( !empty( $bbp_user ) ) {
219
220 // Not a user_id so try email and slug
221 if ( !is_numeric( $bbp_user ) ) {
222
223 // Email was passed
224 if ( is_email( $bbp_user ) )
225 $bbp_user = get_user_by( 'email', $bbp_user );
226 // Try nicename
227 else
228 $bbp_user = get_user_by( 'slug', $bbp_user );
229
230 // If we were successful, set to ID
231 if ( is_object( $bbp_user ) )
232 $bbp_user = $bbp_user->ID;
233 }
234
235 // Create new user
236 $user = new WP_User( $bbp_user );
237
238 // Stop if no user
239 if ( !isset( $user ) || empty( $user ) || empty( $user->ID ) ) {
240 $posts_query->set_404();
241 return;
242 }
243
244 /** User Exists *******************************************************/
245
246 // View or edit?
247 if ( !empty( $is_edit ) ) {
248
249 // Only allow super admins on multisite to edit every user.
250 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 ) )
251 wp_die( __( 'You do not have the permission to edit this user.', 'bbpress' ) );
252
253 // We are editing a profile
254 $posts_query->bbp_is_user_profile_edit = true;
255
256 // Load the core WordPress contact methods
257 if ( !function_exists( '_wp_get_user_contactmethods' ) )
258 include_once( ABSPATH . 'wp-includes/registration.php' );
259
260 // Load the edit_user functions
261 if ( !function_exists( 'edit_user' ) )
262 require_once( ABSPATH . 'wp-admin/includes/user.php' );
263
264 // We are viewing a profile
265 } else {
266 $posts_query->bbp_is_user_profile_page = true;
267 }
268
269 // Make sure 404 is not set
270 $posts_query->is_404 = false;
271
272 // Correct is_home variable
273 $posts_query->is_home = false;
274
275 // Set bbp_user_id for future reference
276 $posts_query->query_vars['bbp_user_id'] = $user->ID;
277
278 // Set author_name as current user's nicename to get correct posts
279 if ( !bbp_is_query_name( 'bbp_widget' ) )
280 $posts_query->query_vars['author_name'] = $user->user_nicename;
281
282 // Set the displayed user global to this user
283 $bbp->displayed_user = $user;
284
285 // View Page
286 } elseif ( !empty( $bbp_view ) ) {
287
288 // Check if the view exists by checking if there are query args are set
289 $view_args = bbp_get_view_query_args( $bbp_view );
290
291 // Stop if view args is false - means the view isn't registered
292 if ( false === $view_args ) {
293 $posts_query->set_404();
294 return;
295 }
296
297 // We are in a custom topic view
298 $posts_query->bbp_is_view = true;
299
300 // Topic/Reply Edit Page
301 } elseif ( !empty( $is_edit ) ) {
302
303 // We are editing a topic
304 if ( $posts_query->get( 'post_type' ) == bbp_get_topic_post_type() )
305 $posts_query->bbp_is_topic_edit = true;
306
307 // We are editing a reply
308 elseif ( $posts_query->get( 'post_type' ) == bbp_get_reply_post_type() )
309 $posts_query->bbp_is_reply_edit = true;
310
311 // We save post revisions on our own
312 remove_action( 'pre_post_update', 'wp_save_post_revision' );
313 }
314
315 return $posts_query;
316 }
317
318 /**
319 * Possibly intercept the template being loaded
320 *
321 * Listens to the 'template_include' filter and waits for a bbPress post_type
322 * to appear. If the current theme does not explicitly support bbPress, it
323 * intercepts the page template and uses one served from the bbPress compatable
324 * theme, set as the $bbp->theme_compat global. If the current theme does
325 * support bbPress, we'll explore the template hierarchy and try to locate one.
326 *
327 * @since bbPress (r3032)
328 *
329 * @global bbPress $bbp
330 * @global WP_Query $post
331 * @param string $template
332 * @return string
333 */
334 function bbp_template_include( $template = false ) {
335 global $bbp;
336
337 // Prevent debug notices
338 $templates = array();
339 $new_template = '';
340
341 // Current theme supports bbPress
342 if ( current_theme_supports( 'bbpress' ) ) {
343
344 // Viewing a profile
345 if ( bbp_is_user_profile_page() ) {
346 $templates = apply_filters( 'bbp_profile_templates', array(
347 'forums/user.php',
348 'bbpress/user.php',
349 'user.php',
350 'author.php',
351 'index.php'
352 ) );
353
354 // Editing a profile
355 } elseif ( bbp_is_user_profile_edit() ) {
356 $templates = apply_filters( 'bbp_profile_edit_templates', array(
357 'forums/user-edit.php',
358 'bbpress/user-edit.php',
359 'user-edit.php',
360 'forums/user.php',
361 'bbpress/user.php',
362 'user.php',
363 'author.php',
364 'index.php'
365 ) );
366
367 // View page
368 } elseif ( bbp_is_view() ) {
369 $templates = apply_filters( 'bbp_view_templates', array(
370 'forums/view-' . bbp_get_view_id(),
371 'bbpress/view-' . bbp_get_view_id(),
372 'forums/view.php',
373 'bbpress/view.php',
374 'view-' . bbp_get_view_id(),
375 'view.php',
376 'index.php'
377 ) );
378
379 // Editing a topic
380 } elseif ( bbp_is_topic_edit() ) {
381 $templates = array(
382 'forums/action-edit.php',
383 'bbpress/action-edit.php',
384 'forums/single-' . bbp_get_topic_post_type(),
385 'bbpress/single-' . bbp_get_topic_post_type(),
386 'action-bbp-edit.php',
387 'single-' . bbp_get_topic_post_type(),
388 'single.php',
389 'index.php'
390 );
391
392 // Add split/merge to front of array if present in _GET
393 if ( !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'merge', 'split' ) ) ) {
394 array_unshift( $templates,
395 'forums/action-split-merge.php',
396 'bbpress/action-split-merge.php',
397 'action-split-merge.php'
398 );
399 }
400
401 $templates = apply_filters( 'bbp_topic_edit_templates', $templates );
402
403 // Editing a reply
404 } elseif ( bbp_is_reply_edit() ) {
405 $templates = apply_filters( 'bbp_reply_edit_templates', array(
406 'forums/action-edit.php',
407 'bbpress/action-edit.php',
408 'forums/single-' . bbp_get_reply_post_type(),
409 'bbpress/single-' . bbp_get_reply_post_type(),
410 'action-bbp-edit.php',
411 'single-' . bbp_get_reply_post_type(),
412 'single.php',
413 'index.php'
414 ) );
415 }
416
417 // Custom template file exists
418 if ( !empty( $templates ) && ( $new_template = locate_template( $templates, false, false ) ) ) {
419 $template = $new_template;
420 }
421 }
422
423 /**
424 * In this next bit, either the current theme does not support bbPress, or
425 * the theme author has incorrectly used add_theme_support( 'bbpress' )
426 * and we are going to help them out by silently filling in the blanks.
427 */
428 if ( !current_theme_supports( 'bbpress' ) || ( !empty( $templates ) && empty( $new_template ) ) ) {
429
430 // Assume we are not in theme compat
431 $in_theme_compat = false;
432
433 /** Users *************************************************************/
434
435 if ( bbp_is_user_profile_page() || bbp_is_user_profile_edit() ) {
436
437 // In Theme Compat
438 $in_theme_compat = true;
439 bbp_theme_compat_reset_post( array(
440 'post_title' => esc_attr( bbp_get_displayed_user_field( 'display_name' ) )
441 ) );
442
443 /** Forums ************************************************************/
444
445 // Forum archive
446 } elseif ( is_post_type_archive( bbp_get_forum_post_type() ) ) {
447
448 // In Theme Compat
449 $in_theme_compat = true;
450 bbp_theme_compat_reset_post( array(
451 'ID' => 0,
452 'post_title' => __( 'Forums', 'bbpress' ),
453 'post_author' => 0,
454 'post_date' => 0,
455 'post_content' => '',
456 'post_type' => bbp_get_forum_post_type(),
457 'post_status' => 'publish'
458 ) );
459
460 /** Topics ************************************************************/
461
462 // Topic archive
463 } elseif ( is_post_type_archive( bbp_get_topic_post_type() ) ) {
464
465 // In Theme Compat
466 $in_theme_compat = true;
467 bbp_theme_compat_reset_post( array(
468 'ID' => 0,
469 'post_title' => __( 'Topics', 'bbpress' ),
470 'post_author' => 0,
471 'post_date' => 0,
472 'post_content' => '',
473 'post_type' => bbp_get_topic_post_type(),
474 'post_status' => 'publish'
475 ) );
476
477 // Single topic
478 } elseif ( bbp_is_topic_edit() || bbp_is_topic_split() || bbp_is_topic_merge() ) {
479
480 // In Theme Compat
481 $in_theme_compat = true;
482 bbp_theme_compat_reset_post( array(
483 'ID' => bbp_get_topic_id(),
484 'post_title' => bbp_get_topic_title(),
485 'post_author' => bbp_get_topic_author_id(),
486 'post_date' => 0,
487 'post_content' => get_post_field( 'post_content', bbp_get_topic_id() ),
488 'post_type' => bbp_get_topic_post_type(),
489 'post_status' => bbp_get_topic_status()
490 ) );
491
492 /** Replies ***********************************************************/
493
494 // Reply archive
495 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) {
496
497 // In Theme Compat
498 $in_theme_compat = true;
499 bbp_theme_compat_reset_post( array(
500 'ID' => 0,
501 'post_title' => __( 'Replies', 'bbpress' ),
502 'post_author' => 0,
503 'post_date' => 0,
504 'post_content' => '',
505 'post_type' => bbp_get_reply_post_type(),
506 'post_status' => 'publish'
507 ) );
508
509 // Single reply
510 } elseif ( bbp_is_reply_edit() ) {
511
512 // In Theme Compat
513 $in_theme_compat = true;
514 bbp_theme_compat_reset_post( array(
515 'ID' => bbp_get_reply_id(),
516 'post_title' => bbp_get_reply_title(),
517 'post_author' => bbp_get_reply_author_id(),
518 'post_date' => 0,
519 'post_content' => get_post_field( 'post_content', bbp_get_reply_id() ),
520 'post_type' => bbp_get_reply_post_type(),
521 'post_status' => bbp_get_reply_status()
522 ) );
523
524 /** Views *************************************************************/
525
526 } elseif ( bbp_is_view() ) {
527
528 // In Theme Compat
529 $in_theme_compat = true;
530 bbp_theme_compat_reset_post();
531
532 /** Topic Tags ********************************************************/
533
534 } elseif ( is_tax( $bbp->topic_tag_id ) ) {
535
536 // In Theme Compat
537 $in_theme_compat = true;
538
539 // Stash the current term in a new var
540 set_query_var( 'bbp_topic_tag', get_query_var( 'term' ) );
541
542 // Reset the post with our new title
543 bbp_theme_compat_reset_post( array(
544 'post_title' => sprintf( __( 'Topic Tag: %s', 'bbpress' ), '<span>' . bbp_get_topic_tag_name() . '</span>' ),
545 ) );
546
547 /** Single Forums/Topics/Replies **************************************/
548
549 } else {
550
551 // Are we looking at a forum/topic/reply?
552 switch ( get_post_type() ) {
553
554 // Single Forum
555 case bbp_get_forum_post_type() :
556 $forum_id = bbp_get_forum_id( get_the_ID() );
557
558 // Single Topic
559 case bbp_get_topic_post_type() :
560 $forum_id = bbp_get_topic_forum_id( get_the_ID() );
561
562 // Single Reply
563 case bbp_get_reply_post_type() :
564 $forum_id = bbp_get_reply_forum_id( get_the_ID() );
565
566 // Display template
567 if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) || bbp_is_forum_private( $forum_id ) ) {
568
569 // In Theme Compat
570 $in_theme_compat = true;
571
572 // Display 404 page
573 } elseif ( bbp_is_forum_hidden( $forum_id ) ) {
574 bbp_set_404();
575 }
576
577 break;
578 }
579 }
580
581 /**
582 * If we are relying on bbPress's built in theme compatibility to load
583 * the proper content, we need to intercept the_content, replace the
584 * output, and display ours instead.
585 *
586 * To do this, we first remove all filters from 'the_content' and hook
587 * our own function into it, which runs a series of checks to determine
588 * the context, and then uses the built in shortcodes to output the
589 * correct results.
590 *
591 * We default to using page.php, since it's most likely to exist and
592 * should be coded to work without superfluous elements and logic, like
593 * prev/next navigation, comments, date/time, etc... You can hook into
594 * the 'bbp_template_include' filter to override page.php.
595 */
596 if ( true === $in_theme_compat ) {
597
598 // Remove all filters from the_content
599 remove_all_filters( 'the_content' );
600
601 // Add a filter on the_content late, which we will later remove
602 add_filter( 'the_content', 'bbp_replace_the_content' );
603
604 // Default to the page template
605 $template = apply_filters( 'bbp_template_include', 'page.php' );
606 $template = locate_template( $template, false, false );
607 }
608 }
609
610 // Return $template
611 return $template;
612 }
613
614 /**
615 * Replaces the_content() if the post_type being displayed is one that would
616 * normally be handled by bbPress, but proper single page templates do not
617 * exist in the currently active theme.
618 *
619 * @since bbPress (r3034)
620 *
621 * @global bbPress $bbp
622 * @global WP_Query $post
623 * @param string $content
624 * @return type
625 */
626 function bbp_replace_the_content( $content = '' ) {
627
628 // Current theme does not support bbPress, so we need to do some heavy
629 // lifting to see if a bbPress template is needed in the current context
630 if ( !current_theme_supports( 'bbpress' ) ) {
631
632 // Use the $post global to check it's post_type
633 global $bbp;
634
635 // Prevent debug notice
636 $new_content = '';
637
638 // Remove the filter that was added in bbp_template_include()
639 remove_filter( 'the_content', 'bbp_replace_the_content' );
640
641 // Bail if shortcodes are unset somehow
642 if ( empty( $bbp->shortcodes ) )
643 return $content;
644
645 // Use shortcode API to display forums/topics/replies because they are
646 // already output buffered and ready to fit inside the_content
647
648 /** Users *************************************************************/
649
650 // Profile View
651 if ( bbp_is_user_profile_page() ) {
652 ob_start();
653
654 bbp_get_template_part( 'bbpress/single', 'user' );
655
656 $new_content = ob_get_contents();
657
658 ob_end_clean();
659
660 // Profile Edit
661 } elseif ( bbp_is_user_profile_edit() ) {
662 ob_start();
663
664 bbp_get_template_part( 'bbpress/single', 'user' );
665
666 $new_content = ob_get_contents();
667
668 ob_end_clean();
669
670
671 /** Forums ************************************************************/
672
673 // Forum archive
674 } elseif ( is_post_type_archive( bbp_get_forum_post_type() ) ) {
675 $new_content = $bbp->shortcodes->display_forum_index();
676
677 /** Topics ************************************************************/
678
679 // Topic archive
680 } elseif ( is_post_type_archive( bbp_get_topic_post_type() ) ) {
681 $new_content = $bbp->shortcodes->display_topic_index();
682
683 // Single topic
684 } elseif ( bbp_is_topic_edit() ) {
685
686 // Split
687 if ( bbp_is_topic_split() ) {
688 ob_start();
689
690 bbp_get_template_part( 'bbpress/form', 'split' );
691
692 $new_content = ob_get_contents();
693
694 ob_end_clean();
695
696 // Merge
697 } elseif ( bbp_is_topic_merge() ) {
698 ob_start();
699
700 bbp_get_template_part( 'bbpress/form', 'merge' );
701
702 $content = ob_get_contents();
703
704 ob_end_clean();
705
706 // Edit
707 } else {
708 $new_content = $bbp->shortcodes->display_topic_form();
709 }
710
711 /** Replies ***********************************************************/
712
713 // Reply archive
714 } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) {
715 //$new_content = $bbp->shortcodes->display_reply_index();
716
717 // Reply Edit
718 } elseif ( bbp_is_reply_edit() ) {
719 $new_content = $bbp->shortcodes->display_reply_form();
720
721 /** Views *************************************************************/
722
723 } elseif ( bbp_is_view() ) {
724 $new_content = $bbp->shortcodes->display_view( array( 'id' => get_query_var( 'bbp_view' ) ) );
725
726 /** Topic Tags ********************************************************/
727
728 } elseif ( get_query_var( 'bbp_topic_tag' ) ) {
729 $new_content = $bbp->shortcodes->display_topics_of_tag( array( 'id' => bbp_get_topic_tag_id() ) );
730
731 /** Forums/Topics/Replies *********************************************/
732
733 } else {
734
735 // Check the post_type
736 switch ( get_post_type() ) {
737
738 // Single Forum
739 case bbp_get_forum_post_type() :
740 $new_content = $bbp->shortcodes->display_forum( array( 'id' => get_the_ID() ) );
741 break;
742
743 // Single Topic
744 case bbp_get_topic_post_type() :
745 $new_content = $bbp->shortcodes->display_topic( array( 'id' => get_the_ID() ) );
746 break;
747
748 // Single Reply
749 case bbp_get_reply_post_type() :
750
751 break;
752 }
753 }
754
755 // Juggle the content around and try to prevent unsightly comments
756 if ( !empty( $new_content ) && ( $new_content != $content ) ) {
757
758 // Set the content to be the new content
759 $content = apply_filters( 'bbp_replace_the_content', $new_content, $content );
760
761 // Clean up after ourselves
762 unset( $new_content );
763
764 /**
765 * Supplemental hack to prevent stubborn comments_template() output.
766 *
767 * By this time we can safely assume that everything we needed from
768 * the {$post} global has been rendered into the buffer, so we're
769 * going to empty it and {$withcomments} for good measure. This has
770 * the added benefit of preventing an incorrect "Edit" link on the
771 * bottom of most popular page templates, at the cost of rendering
772 * these globals useless for the remaining page output without using
773 * wp_reset_postdata() to get that data back.
774 *
775 * @see comments_template() For why we're doing this :)
776 * @see wp_reset_postdata() If you need to get $post back
777 *
778 * Note: If a theme uses custom code to output comments, it's
779 * possible all of this dancing around is for not.
780 *
781 * Note: If you need to keep these globals around for any special
782 * reason, we've provided a failsafe hook to bypass this you
783 * can put in your plugin or theme below ---v
784 *
785 * apply_filters( 'bbp_spill_the_beans', '__return_true' );
786 */
787 if ( !apply_filters( 'bbp_spill_the_beans', false ) ) {
788
789 // Setup the chopping block
790 global $post, $withcomments;
791
792 // Empty out globals that aren't being used in this loop anymore
793 $withcomments = $post = false;
794 }
795 }
796 }
797
798 // Return possibly hi-jacked content
799 return $content;
800 }
801
802 /** Helpers *******************************************************************/
803
804 /**
805 * Remove the canonical redirect to allow pretty pagination
806 *
807 * @since bbPress (r2628)
808 *
809 * @param string $redirect_url Redirect url
810 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
811 * @uses bbp_is_topic() To check if it's a topic page
812 * @uses bbp_get_paged() To get the current page number
813 * @uses bbp_is_forum() To check if it's a forum page
814 * @return bool|string False if it's a topic/forum and their first page,
815 * otherwise the redirect url
816 */
817 function bbp_redirect_canonical( $redirect_url ) {
818 global $wp_rewrite;
819
820 if ( $wp_rewrite->using_permalinks() ) {
821 if ( bbp_is_topic() && 1 < bbp_get_paged() )
822 $redirect_url = false;
823 elseif ( bbp_is_forum() && 1 < bbp_get_paged() )
824 $redirect_url = false;
825 }
826
827 return $redirect_url;
828 }
829
830 /**
831 * Sets the 404 status.
832 *
833 * Used primarily with topics/replies inside hidden forums.
834 *
835 * @since bbPress (r3051)
836 *
837 * @global WP_Query $wp_query
838 * @uses WP_Query::set_404()
839 */
840 function bbp_set_404() {
841 global $wp_query;
842
843 if ( ! isset( $wp_query ) ) {
844 _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
845 return false;
846 }
847
848 $wp_query->set_404();
849 }
850
851
852 ?>
853