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