Skip to:
Content

BuddyPress.org

Changeset 11609


Ignore:
Timestamp:
06/23/2017 01:39:31 PM (2 years ago)
Author:
dcavins
Message:

Handle missing parameter in group admin fetching functions.

In some situations, bp_group_has_moderators() is
being called without a $group parameter, causing the
downstream functions problems. This commit adds an
early return if the required parameter isn’t supplied.
It also recognizes when the cache request returns false
and skips the integer casting step.

Fixes #7524.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-member.php

    r11447 r11609  
    10891089        global $wpdb;
    10901090
     1091        if ( empty( $group_id ) ) {
     1092            return array();
     1093        }
     1094
    10911095        $group_admins = wp_cache_get( $group_id, 'bp_group_admins' );
    10921096
     
    10961100        }
    10971101
    1098         // Integer casting.
    1099         foreach ( (array) $group_admins as $key => $data ) {
    1100             $group_admins[ $key ]->user_id = (int) $group_admins[ $key ]->user_id;
     1102        if ( false === $group_admins ) {
     1103            // The wp_cache_get is still coming up empty. Return an empty array.
     1104            $group_admins = array();
     1105        } else {
     1106            // Cast the user_id property as an integer.
     1107            foreach ( (array) $group_admins as $key => $data ) {
     1108                $group_admins[ $key ]->user_id = (int) $group_admins[ $key ]->user_id;
     1109            }
    11011110        }
    11021111
     
    11591168        global $wpdb;
    11601169
     1170        if ( empty( $group_id ) ) {
     1171            return array();
     1172        }
     1173
    11611174        $group_mods = wp_cache_get( $group_id, 'bp_group_mods' );
    11621175
     
    11661179        }
    11671180
    1168         // Integer casting.
    1169         foreach ( (array) $group_mods as $key => $data ) {
    1170             $group_mods[ $key ]->user_id = (int) $group_mods[ $key ]->user_id;
     1181        if ( false === $group_mods ) {
     1182            // The wp_cache_get is still coming up empty. Return an empty array.
     1183            $group_mods = array();
     1184        } else {
     1185            // Cast the user_id property as an integer.
     1186            foreach ( (array) $group_mods as $key => $data ) {
     1187                $group_mods[ $key ]->user_id = (int) $group_mods[ $key ]->user_id;
     1188            }
    11711189        }
    11721190
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php

    r11604 r11609  
    13541354        $this->assertEquals( $user, $user_obj->id );
    13551355    }
     1356
     1357    /**
     1358     * @group get_group_moderator_ids
     1359     */
     1360    public function test_groups_get_group_mods_bad_id() {
     1361        $mods = groups_get_group_mods( null );
     1362
     1363        $this->assertTrue( is_array( $mods ) && empty( $mods ) );
     1364    }
     1365
     1366    /**
     1367     * @group get_group_moderator_ids
     1368     */
     1369    public function test_groups_get_group_admins_bad_id() {
     1370        $admins = groups_get_group_admins( null );
     1371
     1372        $this->assertTrue( is_array( $admins ) && empty( $admins ) );
     1373    }
    13561374}
Note: See TracChangeset for help on using the changeset viewer.