BP_Messages_Thread::get_recipients( int $thread_id )

Returns recipients for a message thread.

Description

Parameters

$thread_id

(Required) The thread ID.

Return

(array)

Source

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

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
public function get_recipients( $thread_id = 0 ) {
    global $wpdb;
 
    if ( empty( $thread_id ) ) {
        $thread_id = $this->thread_id;
    }
 
    $thread_id = (int) $thread_id;
 
    $recipients = wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' );
    if ( false === $recipients ) {
        $bp = buddypress();
 
        $recipients = array();
        $sql        = $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id );
        $results    = $wpdb->get_results( $sql );
 
        foreach ( (array) $results as $recipient ) {
            $recipients[ $recipient->user_id ] = $recipient;
        }
 
        wp_cache_set( 'thread_recipients_' . $thread_id, $recipients, 'bp_messages' );
    }
 
    // Cast all items from the messages DB table as integers.
    foreach ( (array) $recipients as $key => $data ) {
        $recipients[ $key ] = (object) array_map( 'intval', (array) $data );
    }
 
    /**
     * Filters the recipients of a message thread.
     *
     * @since BuddyPress 2.2.0
     *
     * @param array $recipients Array of recipient objects.
     * @param int   $thread_id  ID of the current thread.
     */
    return apply_filters( 'bp_messages_thread_get_recipients', $recipients, $thread_id );
}

Changelog

Changelog
Version Description
BuddyPress 2.3.0 Added $thread_id as a parameter. BuddyPress 2.3.0 Added $thread_id as a parameter.
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.