BP_Messages_Thread::delete( int $thread_id, int $user_id )
Mark messages in a thread as deleted or delete all messages in a thread.
Description
Note: All messages in a thread are deleted once every recipient in a thread has marked the thread as deleted.
Parameters
- $thread_id
-
(Required) The message thread ID.
- $user_id
-
(Required) The ID of the user in the thread to mark messages as deleted for. Defaults to the current logged-in user.
Return
(bool)
Source
File: bp-messages/classes/class-bp-messages-thread.php
public static function delete( $thread_id = 0, $user_id = 0 ) {
global $wpdb;
$thread_id = (int) $thread_id;
$user_id = (int) $user_id;
if ( empty( $user_id ) ) {
$user_id = bp_loggedin_user_id();
}
/**
* Fires before a message thread is marked as deleted.
*
* @since BuddyPress 2.2.0
* @since BuddyPress 2.7.0 The $user_id parameter was added.
*
* @param int $thread_id ID of the thread being deleted.
* @param int $user_id ID of the user that the thread is being deleted for.
*/
do_action( 'bp_messages_thread_before_mark_delete', $thread_id, $user_id );
$bp = buddypress();
// Mark messages as deleted
$wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, $user_id ) );
// Get the message ids in order to pass to the action.
$message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
/**
* Fires before an entire message thread is deleted.
*
* @since BuddyPress 2.2.0
*
* @param int $thread_id ID of the thread being deleted.
* @param array $message_ids IDs of messages being deleted.
*/
do_action( 'bp_messages_thread_before_delete', $thread_id, $message_ids );
/**
* Fires after a message thread is either marked as deleted or deleted.
*
* @since BuddyPress 2.2.0
* @since BuddyPress 2.7.0 The $user_id parameter was added.
*
* @param int $thread_id ID of the thread being deleted.
* @param array $message_ids IDs of messages being deleted.
* @param int $user_id ID of the user the threads were deleted for.
*/
do_action( 'bp_messages_thread_after_delete', $thread_id, $message_ids, $user_id );
return true;
}
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.