Changeset 7131
- Timestamp:
- 05/30/2013 10:58:46 PM (11 years ago)
- Location:
- trunk/bp-core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-template-loader.php
r6824 r7131 212 212 213 213 // Get the output buffer contents 214 $output = ob_get_contents(); 215 216 // Flush the output buffer 217 ob_end_clean(); 214 $output = ob_get_clean(); 218 215 219 216 // Echo or return the output buffer contents … … 342 339 $new_template = apply_filters( 'bp_get_root_template', false, $template ); 343 340 344 // BuddyPress template file exists 341 // A BuddyPress template file was located, so override the WordPress 342 // template and use it to switch off BuddyPress's theme compatibility. 345 343 if ( !empty( $new_template ) ) { 346 347 // Override the WordPress template with a BuddyPress one 348 $template = $new_template; 349 350 // @see: bp_template_include_theme_compat() 351 buddypress()->theme_compat->found_template = true; 344 $template = bbp_set_template_included( $new_template ); 352 345 } 353 346 354 347 return apply_filters( 'bp_template_include_theme_supports', $template ); 348 } 349 350 /** 351 * Set the included template 352 * 353 * @since BuddyPress (1.8) 354 * @param mixed $template Default false 355 * @return mixed False if empty. Template name if template included 356 */ 357 function bp_set_template_included( $template = false ) { 358 buddypress()->theme_compat->found_template = $template; 359 360 return buddypress()->theme_compat->found_template; 361 } 362 363 /** 364 * Is a BuddyPress template being included? 365 * 366 * @since BuddyPress (1.8) 367 * @return bool True if yes, false if no 368 */ 369 function bp_is_template_included() { 370 return ! empty( buddypress()->theme_compat->found_template ); 355 371 } 356 372 -
trunk/bp-core/bp-core-theme-compatibility.php
r7128 r7131 524 524 */ 525 525 if ( bp_is_theme_compat_active() ) { 526 527 // Hook to the beginning of the main post loop to remove all filters 528 // from the_content as late as possible. 529 add_action( 'loop_start', 'bp_theme_compat_main_loop_start', 9999 ); 530 531 // Hook to the end of the main post loop to restore all filters to 532 // the_content as early as possible. 533 add_action( 'loop_end', 'bp_theme_compat_main_loop_end', -9999 ); 526 $template = bp_get_theme_compat_templates(); 527 528 add_filter( 'the_content', 'bp_replace_the_content' ); 534 529 535 530 // Add BuddyPress's head action to wp_head … … 537 532 add_action( 'wp_head', 'bp_head' ); 538 533 } 539 540 // Find the appropriate template file541 $template = bp_get_theme_compat_templates();542 534 } 543 535 … … 556 548 function bp_replace_the_content( $content = '' ) { 557 549 558 if ( ! in_the_loop() ) 550 // Bail if not the main loop where theme compat is happening 551 if ( ! bp_do_theme_compat() ) 559 552 return $content; 560 553 554 // Set theme compat to false early, to avoid recursion from nested calls to 555 // the_content() that execute before theme compat has unhooked itself. 556 bp_set_theme_compat_active( false ); 557 558 // Do we have new content to replace the old content? 561 559 $new_content = apply_filters( 'bp_replace_the_content', $content ); 562 560 563 561 // Juggle the content around and try to prevent unsightly comments 564 if ( !empty( $new_content ) && ( $new_content != $content ) ) {562 if ( !empty( $new_content ) && ( $new_content !== $content ) ) { 565 563 566 564 // Set the content to be the new content … … 579 577 580 578 /** 581 * Helper function to conditionally toggle the_content filters in the main 582 * query loop. Aids with theme compatibility. 579 * Are we replacing the_content 583 580 * 584 581 * @since BuddyPress (1.8) 585 * @internal Used only by theme compatibilty 586 * @see bp_template_include_theme_compat() 587 * @see bp_theme_compat_main_loop_end() 588 */ 589 function bp_theme_compat_main_loop_start() { 590 591 // Bail if not the main query 592 if ( ! in_the_loop() ) 593 return; 594 595 // Remove all of the filters from the_content 596 bp_remove_all_filters( 'the_content' ); 597 598 // Make sure we replace the content 599 add_filter( 'the_content', 'bp_replace_the_content' ); 600 } 601 602 /** 603 * Helper function to conditionally toggle the_content filters in the main 604 * query loop. Aids with theme compatibility. 605 * 606 * @since BuddyPress (1.8) 607 * @internal Used only by theme compatibilty 608 * @see bp_template_include_theme_compat() 609 * @see bp_theme_compat_main_loop_start() 610 */ 611 function bp_theme_compat_main_loop_end() { 612 613 // Bail if not the main query 614 if ( ! in_the_loop() ) 615 return; 616 617 // Put all the filters back 618 bp_restore_all_filters( 'the_content' ); 582 * @return bool 583 */ 584 function bp_do_theme_compat() { 585 return (bool) ( ! bp_is_template_included() && in_the_loop() && bp_is_theme_compat_active() ); 619 586 } 620 587
Note: See TracChangeset
for help on using the changeset viewer.