BP_Groups_Group::set_up_admins_and_mods()

Set up admins and mods for the current group object.

Description

Called only when the ‘admins’ or ‘mods’ property is accessed.

Source

File: bp-groups/classes/class-bp-groups-group.php

567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
protected function set_up_admins_and_mods() {
    $admin_ids = BP_Groups_Member::get_group_administrator_ids( $this->id );
    $admin_ids_plucked = wp_list_pluck( $admin_ids, 'user_id' );
 
    $mod_ids = BP_Groups_Member::get_group_moderator_ids( $this->id );
    $mod_ids_plucked = wp_list_pluck( $mod_ids, 'user_id' );
 
    $admin_mod_ids = array_merge( $admin_ids_plucked, $mod_ids_plucked );
    $admin_mod_users = array();
 
    if ( ! empty( $admin_mod_ids ) ) {
        $admin_mod_users = get_users( array(
            'include' => $admin_mod_ids,
            'blog_id' => null,
        ) );
    }
 
    $admin_objects = $mod_objects = array();
    foreach ( $admin_mod_users as $admin_mod_user ) {
        $obj = new stdClass();
        $obj->user_id = $admin_mod_user->ID;
        $obj->user_login = $admin_mod_user->user_login;
        $obj->user_email = $admin_mod_user->user_email;
        $obj->user_nicename = $admin_mod_user->user_nicename;
 
        if ( in_array( $admin_mod_user->ID, $admin_ids_plucked, true ) ) {
            $obj->is_admin = 1;
            $obj->is_mod = 0;
            $admin_objects[] = $obj;
        } else {
            $obj->is_admin = 0;
            $obj->is_mod = 1;
            $mod_objects[] = $obj;
        }
    }
 
    $this->admins = $admin_objects;
    $this->mods   = $mod_objects;
}

Changelog

Changelog
Version Description
BuddyPress 2.7.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.