Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/25/2014 02:45:49 PM (10 years ago)
Author:
boonebgorges
Message:

Fix global variable clashes in bp_group_has_invites()

The use of extract( $r, EXTR_SKIP ) in bp_group_has_invites() was preventing
the 'group_id' parameter passed to the function from being set in the global
and from being passed to the template class. This made the function impossible
to use outside the group context.

Fixes #5427

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-template.php

    r7978 r7983  
    31483148
    31493149function bp_group_has_invites( $args = '' ) {
    3150     global $bp, $invites_template, $group_id;
     3150    global $invites_template, $group_id;
    31513151
    31523152    $defaults = array(
     
    31563156
    31573157    $r = wp_parse_args( $args, $defaults );
    3158     extract( $r, EXTR_SKIP );
    3159 
    3160     if ( !$group_id ) {
    3161         // Backwards compatibility
    3162         if ( !empty( $bp->groups->current_group ) )
    3163             $group_id = $bp->groups->current_group->id;
    3164 
    3165         if ( !empty( $bp->groups->new_group_id ) )
    3166             $group_id = $bp->groups->new_group_id;
    3167     }
    3168 
    3169     if ( !$group_id )
     3158
     3159    if ( empty( $r['group_id'] ) ) {
     3160        if ( ! empty( buddypress()->groups->current_group ) ) {
     3161            $r['group_id'] = bp_get_current_group_id();
     3162        } else if ( ! empty( buddypress()->groups->new_group_id ) ) {
     3163            $r['group_id'] = buddypress()->groups->new_group_id;
     3164        }
     3165    }
     3166
     3167    // Set the global (for use in BP_Groups_Invite_Template::the_invite())
     3168    if ( empty( $group_id ) ) {
     3169        $group_id = $r['group_id'];
     3170    }
     3171
     3172    if ( ! $group_id ) {
    31703173        return false;
    3171 
    3172     $invites_template = new BP_Groups_Invite_Template( $user_id, $group_id );
     3174    }
     3175
     3176    $invites_template = new BP_Groups_Invite_Template( $r['user_id'], $r['group_id'] );
    31733177    return apply_filters( 'bp_group_has_invites', $invites_template->has_invites(), $invites_template );
    31743178}
Note: See TracChangeset for help on using the changeset viewer.