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