Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/22/2011 08:02:33 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Fix bug where inbox count would return incorrect results. See #3367.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages/bp-messages-classes.php

    r4770 r4776  
    167167    }
    168168
    169     function get_inbox_count() {
    170         global $wpdb, $bp;
    171 
    172         $sql = $wpdb->prepare( "SELECT unread_count FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0 AND sender_only = 0", $bp->loggedin_user->id );
    173 
    174         if ( !$unread_counts = $wpdb->get_results($sql) )
    175             return false;
    176 
    177         $count = 0;
    178         for ( $i = 0, $count = count( $unread_counts ); $i < $count; ++$i ) {
    179             $count += $unread_counts[$i]->unread_count;
    180         }
    181 
    182         return $count;
     169    function get_inbox_count( $user_id = 0 ) {
     170        global $wpdb, $bp;
     171
     172        if ( empty( $user_id ) )
     173            $user_id = $bp->loggedin_user->id;
     174
     175        $sql = $wpdb->prepare( "SELECT SUM(unread_count) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0 AND sender_only = 0", $user_id );
     176        $unread_count = $wpdb->get_var( $sql );
     177
     178        if ( empty( $unread_count ) || is_wp_error( $unread_count ) )
     179            return 0;
     180
     181        return (int) $unread_count;
    183182    }
    184183
Note: See TracChangeset for help on using the changeset viewer.