BP_Messages_Thread::get_inbox_count( int $user_id )
Gets the unread message count for a user.
Description
Parameters
- $user_id
-
(Required) The user ID.
Return
(int) $unread_count Total inbox unread count for user.
Source
File: bp-messages/classes/class-bp-messages-thread.php
public static function get_inbox_count( $user_id = 0 ) {
global $wpdb;
if ( empty( $user_id ) ) {
$user_id = bp_loggedin_user_id();
}
$unread_count = wp_cache_get( $user_id, 'bp_messages_unread_count' );
if ( false === $unread_count ) {
$bp = buddypress();
// $unread_count = (int) $wpdb->get_var( $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 ) );
$unread_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM(unread_count) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0", $user_id ) );
wp_cache_set( $user_id, $unread_count, 'bp_messages_unread_count' );
}
/**
* Filters a user's unread message count.
*
* @since BuddyPress 2.2.0
*
* @param int $unread_count Unread message count.
* @param int $user_id ID of the user.
*/
return apply_filters( 'messages_thread_get_inbox_count', (int) $unread_count, $user_id );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.0.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.