Skip to:
Content

BuddyPress.org

Changeset 10445


Ignore:
Timestamp:
01/08/2016 09:38:46 PM (6 years ago)
Author:
boonebgorges
Message:

Use unformatted group count when deciding whether to use the 'no-count' in user nav.

A number of problems can arise when using a formatted group count for this
comparison, because formatted counts are strings.

Fixes #6813.

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r10417 r10445  
    772772    }
    773773
    774     return $count;
     774    return (int) $count;
    775775}
    776776
  • trunk/src/bp-groups/bp-groups-loader.php

    r10417 r10445  
    435435        // Only grab count if we're on a user page.
    436436        if ( bp_is_user() ) {
    437             $count    = bp_get_total_group_count_for_user();
    438             $class    = ( 0 === $count ) ? 'no-count' : 'count';
    439             $nav_name = sprintf( _x( 'Groups <span class="%s">%s</span>', 'Group screen nav with counter', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) );
     437            $class    = ( 0 === groups_total_groups_for_user( bp_displayed_user_id() ) ) ? 'no-count' : 'count';
     438            $nav_name = sprintf( _x( 'Groups <span class="%s">%s</span>', 'Group screen nav with counter', 'buddypress' ), esc_attr( $class ), bp_get_total_group_count_for_user() );
    440439        } else {
    441440            $nav_name = _x( 'Groups', 'Group screen nav without counter', 'buddypress' );
  • trunk/src/bp-groups/classes/class-bp-groups-member.php

    r10423 r10445  
    668668
    669669        if ( $user_id != bp_loggedin_user_id() && !bp_current_user_can( 'bp_moderate' ) ) {
    670             return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
     670            return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    671671        } else {
    672             return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
     672            return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    673673        }
    674674    }
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php

    r10227 r10445  
    11971197        $this->assertEqualSets( array( $u1, $u2, $u3 ), $members->user_ids );
    11981198    }
     1199
     1200    /**
     1201     * @group total_group_count
     1202     * @ticket BP6813
     1203     */
     1204    public function test_total_group_count_should_return_integer() {
     1205        $this->assertInternalType( 'int', BP_Groups_Member::total_group_count( 123 ) );
     1206    }
    11991207}
Note: See TracChangeset for help on using the changeset viewer.