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