Skip to:
Content

BuddyPress.org

Ticket #7235: 7235.diff

File 7235.diff, 4.8 KB (added by jdgrimes, 5 years ago)
  • src/bp-messages/bp-messages-functions.php

     
    239239 * Delete message thread(s).
    240240 *
    241241 * @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.
    242244 * @return bool True on success, false on failure.
    243245 */
    244 function messages_delete_thread( $thread_ids ) {
     246function messages_delete_thread( $thread_ids, $user_id = 0 ) {
    245247
     248        if ( empty( $user_id ) ) {
     249                $user_id = bp_loggedin_user_id();
     250        }
     251       
    246252        /**
    247253         * Fires before specified thread IDs have been deleted.
    248254         *
     
    249255         * @since 1.5.0
    250256         *
    251257         * @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.
    252259         */
    253         do_action( 'messages_before_delete_thread', $thread_ids );
     260        do_action( 'messages_before_delete_thread', $thread_ids, $user_id );
    254261
    255262        if ( is_array( $thread_ids ) ) {
    256263                $error = 0;
    257264                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 ) ) {
    259266                                $error = 1;
    260267                        }
    261268                }
     
    270277                 * @since 1.0.0
    271278                 *
    272279                 * @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.
    273281                 */
    274                 do_action( 'messages_delete_thread', $thread_ids );
     282                do_action( 'messages_delete_thread', $thread_ids, $user_id );
    275283
    276284                return true;
    277285        } else {
    278                 if ( ! BP_Messages_Thread::delete( $thread_ids ) ) {
     286                if ( ! BP_Messages_Thread::delete( $thread_ids, $user_id ) ) {
    279287                        return false;
    280288                }
    281289
    282290                /** 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 );
    284292
    285293                return true;
    286294        }
     
    604612         */
    605613        do_action( 'bp_messages_sent_notification_email', $recipients, '', '', $args );
    606614}
    607 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
    608  No newline at end of file
     615add_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
  • src/bp-messages/classes/class-bp-messages-thread.php

     
    328328         * @since 1.0.0
    329329         *
    330330         * @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         *
    331334         * @return bool
    332335         */
    333         public static function delete( $thread_id = 0 ) {
     336        public static function delete( $thread_id = 0, $user_id = 0 ) {
    334337                global $wpdb;
    335338
    336339                $thread_id = (int) $thread_id;
     340                $user_id = (int) $user_id;
    337341
     342                if ( empty( $user_id ) ) {
     343                        $user_id = bp_loggedin_user_id();
     344                }
     345
    338346                /**
    339347                 * Fires before a message thread is marked as deleted.
    340348                 *
     
    341349                 * @since 2.2.0
    342350                 *
    343351                 * @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.
    344353                 */
    345                 do_action( 'bp_messages_thread_before_mark_delete', $thread_id );
     354                do_action( 'bp_messages_thread_before_mark_delete', $thread_id, $user_id );
    346355
    347356                $bp = buddypress();
    348357
    349358                // 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 ) );
    354360
    355361                // Get the message ids in order to pass to the action.
    356362                $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
     
    401407                 *
    402408                 * @param int   $thread_id   ID of the thread being deleted.
    403409                 * @param array $message_ids IDs of messages being deleted.
     410                 * @param int   $user_id     ID of the user the threads were deleted for.
    404411                 */
    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 );
    406413
    407414                return true;
    408415        }