BP_Messages_Thread::get_total_threads_for_user( int $user_id, string $box = 'inbox', string $type = 'all' )

Returns the total number of message threads for a user.


Description Description


Parameters Parameters

$user_id

(Required) The user ID.

$box

(Optional) The type of mailbox to get. Either 'inbox' or 'sentbox'. Defaults to 'inbox'.

Default value: 'inbox'

$type

(Optional) The type of messages to get. Either 'all' or 'unread'. or 'read'. Defaults to 'all'.

Default value: 'all'


Top ↑

Return Return

(int) $value Total thread count for the provided user.


Top ↑

Source Source

File: bp-messages/classes/class-bp-messages-thread.php

	public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) {
		global $wpdb;

		$exclude_sender = $type_sql = '';
		if ( $box !== 'sentbox' ) {
			$exclude_sender = 'AND sender_only != 1';
		}

		if ( $type === 'unread' ) {
			$type_sql = 'AND unread_count != 0';
		} elseif ( $type === 'read' ) {
			$type_sql = 'AND unread_count = 0';
		}

		$bp = buddypress();

		return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(thread_id) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0 {$exclude_sender} {$type_sql}", $user_id ) );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.