Skip to:
Content

BuddyPress.org

Changeset 13357


Ignore:
Timestamp:
11/07/2022 08:32:51 PM (4 years ago)
Author:
imath
Message:

Eventually include inactive users in group's members count

When the Community Site Administrator decides to add an inactive user
as a member of a group from the Group's WP Admin screen, we need to
include them into the group's members count to remain consistent with the
fact:

  • an activity is created inside the group to inform this inactive user

joined the group

  • the group's members list is including this user.

Props dcavins, sjregan, espellcaste

Closes ​https://github.com/buddypress/buddypress/pull/33
Fixes #7614

Location:
trunk
Files:
2 edited

Legend:

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

    r13280 r13357  
    548548         *
    549549         * @since 10.3.0
     550         * @since 11.0.0 Include inactive users added by a community administrators to the group members count.
    550551         */
    551552        public function populate_extras() {
    … …  
    555556
    556557                // Validate active users.
    557                 $active_users    = array_filter( BP_Core_User::get_last_activity( $this->user_ids ) );
    558                 $active_user_ids = array_keys( $active_users );
    559                 $this->results   = array_intersect( $this->user_ids, $active_user_ids );
     558                if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     559                        $active_users    = array_filter( BP_Core_User::get_last_activity( $this->user_ids ) );
     560                        $active_user_ids = array_keys( $active_users );
     561                        $this->results   = array_intersect( $this->user_ids, $active_user_ids );
     562                } else {
     563                        $this->results = $this->user_ids;
     564                }
    560565
    561566                // Set the total active users.
  • trunk/tests/phpunit/testcases/groups/functions.php

    r13355 r13357  
    363363
    364364                $this->assertEquals( 1, groups_get_total_member_count( $g1 ) );
     365        }
     366
     367        /**
     368         * @group total_member_count
     369         * @ticket BP7614
     370         */
     371        public function test_total_member_count_groups_inactive_user_from_admin() {
     372                $current_user = get_current_user_id();
     373                $u1           = self::factory()->user->create(
     374                        array(
     375                                'role' => 'administrator',
     376                        )
     377                );
     378                $u2           = wp_insert_user( array(
     379                        'user_pass'  => 'barfoo',
     380                        'user_login' => 'barfoo',
     381                        'user_email' => 'barfoo@buddypress.org',
     382                ) );
     383
     384                $this->set_current_user( $u1 );
     385                $g1 = self::factory()->group->create();
     386
     387                groups_join_group( $g1, $u2 );
     388
     389                $this->assertEquals( 2, groups_get_total_member_count( $g1 ) );
     390
     391                $this->set_current_user( $current_user );
    365392        }
    366393
Note: See TracChangeset for help on using the changeset viewer.