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-members-widget.php

    r10521 r10553  
    4848         */
    4949        public function widget( $args, $instance ) {
     50                global $members_template;
    5051
    5152                // Get widget settings.
     
    8889                        'populate_extras' => true,
    8990                        'search_terms'    => false,
    90                 ); ?>
     91                );
     92
     93                // Back up the global.
     94                $old_members_template = $members_template;
     95
     96                ?>
    9197
    9298                <?php if ( bp_has_members( $members_args ) ) : ?>
     
    146152
    147153                <?php echo $args['after_widget'];
     154
     155                // Restore the global.
     156                $members_template = $old_members_template;
    148157        }
    149158
Note: See TracChangeset for help on using the changeset viewer.