BP_Messages_Thread::mark_as_unread( int $thread_id )

Mark a thread as unread.

Description

Parameters

$thread_id

(Required) The message thread ID.

Return

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

Source

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

1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
public static function mark_as_unread( $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 = 1 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 unread.
     *
     * @since BuddyPress 2.8.0
     *
     * @param int $thread_id The message thread ID.
     */
    do_action( 'messages_thread_mark_as_unread', $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.