Skip to:
Content

BuddyPress.org

Ticket #5021: 5021.02.2.patch

File 5021.02.2.patch, 2.2 KB (added by r-a-y, 12 years ago)

Updated to include better comments

  • bp-core/bp-core-template-loader.php

    function bp_get_template_stack() { 
    202202function bp_buffer_template_part( $slug, $name = null, $echo = true ) {
    203203        ob_start();
    204204
    205         // Remove 'bp_replace_the_content' filter to prevent infinite loops
    206         remove_filter( 'the_content', 'bp_replace_the_content' );
    207 
    208205        bp_get_template_part( $slug, $name );
    209206
    210         // Remove 'bp_replace_the_content' filter to prevent infinite loops
    211         add_filter( 'the_content', 'bp_replace_the_content' );
    212 
    213207        // Get the output buffer contents
    214208        $output = ob_get_contents();
    215209
    216210        // Flush the output buffer
    217211        ob_end_clean();
    218212
     213        // Remove our filter just in case there are other post loops
     214        // after this one is rendered
     215        remove_filter( 'the_content', 'bp_replace_the_content' );
     216
    219217        // Echo or return the output buffer contents
    220218        if ( true === $echo ) {
    221219                echo $output;
  • bp-core/bp-core-theme-compatibility.php

    function bp_template_include_theme_compat( $template = '' ) { 
    521521         */
    522522        if ( bp_is_theme_compat_active() ) {
    523523
    524                 // Remove all filters from the_content
    525                 bp_remove_all_filters( 'the_content' );
    526 
    527                 // Add a filter on the_content late, which we will later remove
    528                 if ( ! has_filter( 'the_content', 'bp_replace_the_content' ) ) {
     524                // After the_post() is called, remove all filters from 'the_content'.
     525                // Next, add our filter to 'the_content' so BP can inject its contents.
     526                // This is the latest we can run this before we do our object buffering
     527                add_action( 'loop_start', create_function( '', "
     528                        bp_remove_all_filters( 'the_content' );
    529529                        add_filter( 'the_content', 'bp_replace_the_content' );
    530                 }
     530                " ), 9999 );
     531
     532                // Restore the filters after the post loop is finished
     533                add_action( 'loop_end', create_function( '', "
     534                        bp_restore_all_filters( 'the_content' );
     535                " ), 0 );
    531536
    532537                // Add BuddyPress's head action to wp_head
    533538                if ( ! has_action( 'wp_head', 'bp_head' ) ) {