Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/08/2016 04:14:59 AM (10 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-members/classes/class-bp-core-recently-active-widget.php

    r10521 r10553  
    3939     */
    4040    public function widget( $args, $instance ) {
     41        global $members_template;
    4142
    4243        // Get widget settings.
     
    6869            'populate_extras' => true,
    6970            'search_terms'    => false,
    70         ); ?>
     71        );
     72
     73        // Back up global.
     74        $old_members_template = $members_template;
     75
     76        ?>
    7177
    7278        <?php if ( bp_has_members( $members_args ) ) : ?>
     
    9399
    94100        <?php echo $args['after_widget'];
     101
     102        // Restore the global.
     103        $members_template = $old_members_template;
    95104    }
    96105
Note: See TracChangeset for help on using the changeset viewer.