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

1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
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

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.