Skip to:
Content
Pages
Categories
Search
Top
Bottom

Problem with checking if a user is in a group (SOLVED (maybe?))

  • Hi, since updating to the latest buddypress i’ve had issues with detecting if a member is in a specific group.

    I have the following function

    public function user_is_mod() {
    global $bp;
    if(function_exists(‘groups_get_group’) && function_exists(‘bp_group_is_member’)) {
    $modgroup = groups_get_group( array(“group_id” => 1) );
    if($_SERVER == “84.13.3.11”) {
    var_dump($modgroup);
    var_dump(bp_group_is_member($modgroup));
    }
    if ($modgroup->is_member === 1) {
    return true;
    } else return false;
    } else return false;
    //return false;
    }

    Which is returning true for all members

    I added some debug code and that is returning

    object(BP_Groups_Group)#452 (14) {
    [“id”]=>
    string(1) “1”
    [“creator_id”]=>
    string(1) “2”
    [“name”]=>
    string(10) “Moderators”
    [“slug”]=>
    string(10) “moderators”
    [“description”]=>
    string(19) “The site moderators”
    [“status”]=>
    string(7) “private”
    [“enable_forum”]=>
    string(1) “0”
    [“date_created”]=>
    string(19) “2012-04-03 11:34:20”
    [“total_member_count”]=>
    string(2) “14”
    [“is_member”]=>
    int(1)
    [“last_activity”]=>
    string(19) “2012-07-28 15:24:08”
    [“user_has_access”]=>
    bool(true)
    }
    bool(true)

    in particular the important bits are:
    [“is_member”]=>
    int(1)
    [“last_activity”]=>
    string(19) “2012-07-28 15:24:08”
    [“user_has_access”]=>
    bool(true)
    }
    bool(true)

    this is for a user that is not in the group, does anyone have any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’ve also tried $modgroup = groups_get_group(‘group_id=1’); instead of using an array, and it fixed it for my test user, but randomly some other users can approve images, even though they aren’t members =/

    and some (not all) other users that ARE members can’t approve images.

    ok, using $modgroup = new BP_Groups_Group(1); instead *seems* to be working, so the only thing I can think of is I read groups_get_group leverages WP cache, so I’m assuming a mod logs in, goes to the backend, it does a check if they are in the group, sets [“is_member”] => 1 and caches it, then the next person logs in, goes to the backend, and it retrieves [“is_member”] === 1 from the cache.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with checking if a user is in a group (SOLVED (maybe?))’ is closed to new replies.
Skip to toolbar