Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/08/2016 04:14:59 AM (9 years ago)
Author:
boonebgorges
Message:

Restore template globals after widget loops.

BP template loop functions, like bp_has_members(), are responsible for
populating corresponding template globals. When this happens inside of a
"secondary" loop - such as a sidebar widget - the loop should clean up after
itself by resetting the relevant template global to whatever it previously was
before the secondary loop had run. (This is a rough approximation of WP's
wp_reset_postdata() for BP loops.)

Fixes #5170.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/classes/class-bp-blogs-recent-posts-widget.php

    r10517 r10553  
    3636     */
    3737    public function widget( $args, $instance ) {
     38        global $activities_template;
    3839
    3940        $title = ! empty( $instance['title'] )
     
    7576            'object'     => false,
    7677            'primary_id' => false
    77         ); ?>
     78        );
     79
     80        // Back up global.
     81        $old_activities_template = $activities_template;
     82
     83        ?>
    7884
    7985        <?php if ( bp_has_activities( $args ) ) : ?>
     
    108114        <?php endif; ?>
    109115
    110         <?php echo $after_widget; ?>
    111     <?php
     116        <?php echo $after_widget;
     117
     118        // Restore the global.
     119        $activities_template = $old_activities_template;
    112120    }
    113121
Note: See TracChangeset for help on using the changeset viewer.