BP_Messages_Thread::mark_as_read( int $thread_id )

Mark a thread as read.

Description

Parameters

$thread_id

(Required) The message thread ID.

Return

(false|int) Number of threads marked as read or false on error.

Source

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

1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
public static function mark_as_read( $thread_id = 0 ) {
    global $wpdb;
 
    $user_id =
        bp_displayed_user_id() ?
        bp_displayed_user_id() :
        bp_loggedin_user_id();
 
    $bp     = buddypress();
    $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) );
 
    wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    wp_cache_delete( $user_id, 'bp_messages_unread_count' );
 
    /**
     * Fires when messages thread was marked as read.
     *
     * @since BuddyPress 2.8.0
     *
     * @param int $thread_id The message thread ID.
     */
    do_action( 'messages_thread_mark_as_read', $thread_id );
 
    return $retval;
}

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.