Skip to:
Content

BuddyPress.org

Changeset 10553


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.

Location:
trunk/src
Files:
6 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
  • trunk/src/bp-friends/classes/class-bp-core-friends-widget.php

    r10529 r10553  
    3737     */
    3838    function widget( $args, $instance ) {
     39        global $members_template;
     40
    3941        extract( $args );
    4042
     
    7880            'populate_extras' => 1,
    7981        );
     82
     83        // Back up the global.
     84        $old_members_template = $members_template;
    8085
    8186        ?>
     
    125130        <?php endif; ?>
    126131
    127         <?php echo $after_widget; ?>
    128     <?php
     132        <?php echo $after_widget;
     133
     134        // Restore the global.
     135        $members_template = $old_members_template;
    129136    }
    130137
  • trunk/src/bp-groups/classes/class-bp-groups-widget.php

    r10520 r10553  
    4545     */
    4646    public function widget( $args, $instance ) {
     47        global $groups_template;
    4748
    4849        /**
     
    100101            'max'             => $max_groups,
    101102        );
     103
     104        // Back up the global.
     105        $old_groups_template = $groups_template;
    102106
    103107        ?>
     
    150154        <?php endif; ?>
    151155
    152         <?php echo $after_widget; ?>
    153     <?php
     156        <?php echo $after_widget;
     157
     158        // Restore the global.
     159        $groups_template = $old_groups_template;
    154160    }
    155161
  • 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
  • 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
  • trunk/src/bp-members/classes/class-bp-core-whos-online-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.