Ticket #7235: 7235.diff
| File 7235.diff, 4.8 KB (added by , 10 years ago) |
|---|
-
src/bp-messages/bp-messages-functions.php
239 239 * Delete message thread(s). 240 240 * 241 241 * @param int|array $thread_ids Thread ID or array of thread IDs. 242 * @param int $user_id ID of the user to delete the threads for. Defaults 243 * to the current logged-in user. 242 244 * @return bool True on success, false on failure. 243 245 */ 244 function messages_delete_thread( $thread_ids ) {246 function messages_delete_thread( $thread_ids, $user_id = 0 ) { 245 247 248 if ( empty( $user_id ) ) { 249 $user_id = bp_loggedin_user_id(); 250 } 251 246 252 /** 247 253 * Fires before specified thread IDs have been deleted. 248 254 * … … 249 255 * @since 1.5.0 250 256 * 251 257 * @param int|array Thread ID or array of thread IDs that were deleted. 258 * @param int ID of the user that the threads are being deleted for. 252 259 */ 253 do_action( 'messages_before_delete_thread', $thread_ids );260 do_action( 'messages_before_delete_thread', $thread_ids, $user_id ); 254 261 255 262 if ( is_array( $thread_ids ) ) { 256 263 $error = 0; 257 264 for ( $i = 0, $count = count( $thread_ids ); $i < $count; ++$i ) { 258 if ( ! BP_Messages_Thread::delete( $thread_ids[$i] ) ) {265 if ( ! BP_Messages_Thread::delete( $thread_ids[$i], $user_id ) ) { 259 266 $error = 1; 260 267 } 261 268 } … … 270 277 * @since 1.0.0 271 278 * 272 279 * @param int|array Thread ID or array of thread IDs that were deleted. 280 * @param int ID of the user that the threads were deleted for. 273 281 */ 274 do_action( 'messages_delete_thread', $thread_ids );282 do_action( 'messages_delete_thread', $thread_ids, $user_id ); 275 283 276 284 return true; 277 285 } else { 278 if ( ! BP_Messages_Thread::delete( $thread_ids ) ) {286 if ( ! BP_Messages_Thread::delete( $thread_ids, $user_id ) ) { 279 287 return false; 280 288 } 281 289 282 290 /** This action is documented in bp-messages/bp-messages-functions.php */ 283 do_action( 'messages_delete_thread', $thread_ids );291 do_action( 'messages_delete_thread', $thread_ids, $user_id ); 284 292 285 293 return true; 286 294 } … … 604 612 */ 605 613 do_action( 'bp_messages_sent_notification_email', $recipients, '', '', $args ); 606 614 } 607 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 ); 608 No newline at end of file 615 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 ); -
src/bp-messages/classes/class-bp-messages-thread.php
328 328 * @since 1.0.0 329 329 * 330 330 * @param int $thread_id The message thread ID. 331 * @param int $user_id The ID of the user in the thread to mark messages as 332 * deleted for. Defaults to the current logged-in user. 333 * 331 334 * @return bool 332 335 */ 333 public static function delete( $thread_id = 0 ) {336 public static function delete( $thread_id = 0, $user_id = 0 ) { 334 337 global $wpdb; 335 338 336 339 $thread_id = (int) $thread_id; 340 $user_id = (int) $user_id; 337 341 342 if ( empty( $user_id ) ) { 343 $user_id = bp_loggedin_user_id(); 344 } 345 338 346 /** 339 347 * Fires before a message thread is marked as deleted. 340 348 * … … 341 349 * @since 2.2.0 342 350 * 343 351 * @param int $thread_id ID of the thread being deleted. 352 * @param int $user_id ID of the user that the thread is being deleted for. 344 353 */ 345 do_action( 'bp_messages_thread_before_mark_delete', $thread_id );354 do_action( 'bp_messages_thread_before_mark_delete', $thread_id, $user_id ); 346 355 347 356 $bp = buddypress(); 348 357 349 358 // Mark messages as deleted 350 // 351 // @todo the reliance on bp_loggedin_user_id() sucks for plugins 352 // refactor this method to accept a $user_id parameter. 353 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, bp_loggedin_user_id() ) ); 359 $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 ) ); 354 360 355 361 // Get the message ids in order to pass to the action. 356 362 $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); … … 401 407 * 402 408 * @param int $thread_id ID of the thread being deleted. 403 409 * @param array $message_ids IDs of messages being deleted. 410 * @param int $user_id ID of the user the threads were deleted for. 404 411 */ 405 do_action( 'bp_messages_thread_after_delete', $thread_id, $message_ids );412 do_action( 'bp_messages_thread_after_delete', $thread_id, $message_ids, $user_id ); 406 413 407 414 return true; 408 415 }