Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/22/2016 01:28:23 AM (8 years ago)
Author:
boonebgorges
Message:

Accept a $user_id parameter in messages_delete_thread().

Previously, this stack assumed the logged-in user, which made it very
difficult to delete threads for arbitrary users without touching the
database directly.

Props jdgrimes.
Fixes #7235.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-functions.php

    r11022 r11153  
    237237
    238238/**
    239  * Delete message thread(s).
     239 * Deletes message thread(s) for a given user.
     240 *
     241 * Note that "deleting" a thread for a user means removing it from the user's
     242 * message boxes. A thread is not deleted from the database until it's been
     243 * "deleted" by all recipients.
     244 *
     245 * @since 2.7.0 The $user_id parameter was added. Previously the current user
     246 *              was always assumed.
    240247 *
    241248 * @param int|array $thread_ids Thread ID or array of thread IDs.
     249 * @param int       $user_id    ID of the user to delete the threads for. Defaults
     250 *                              to the current logged-in user.
    242251 * @return bool True on success, false on failure.
    243252 */
    244 function messages_delete_thread( $thread_ids ) {
     253function messages_delete_thread( $thread_ids, $user_id = 0 ) {
     254
     255    if ( empty( $user_id ) ) {
     256        $user_id = bp_loggedin_user_id();
     257    }
    245258
    246259    /**
     
    248261     *
    249262     * @since 1.5.0
     263     * @since 2.7.0 The $user_id parameter was added.
    250264     *
    251      * @param int|array Thread ID or array of thread IDs that were deleted.
     265     * @param int|array $thread_ids Thread ID or array of thread IDs to be deleted.
     266     * @param int       $user_id    ID of the user the threads are being deleted for.
    252267     */
    253     do_action( 'messages_before_delete_thread', $thread_ids );
     268    do_action( 'messages_before_delete_thread', $thread_ids, $user_id );
    254269
    255270    if ( is_array( $thread_ids ) ) {
    256271        $error = 0;
    257272        for ( $i = 0, $count = count( $thread_ids ); $i < $count; ++$i ) {
    258             if ( ! BP_Messages_Thread::delete( $thread_ids[$i] ) ) {
     273            if ( ! BP_Messages_Thread::delete( $thread_ids[$i], $user_id ) ) {
    259274                $error = 1;
    260275            }
     
    269284         *
    270285         * @since 1.0.0
     286         * @since 2.7.0 The $user_id parameter was added.
    271287         *
    272288         * @param int|array Thread ID or array of thread IDs that were deleted.
     289         * @param int       ID of the user that the threads were deleted for.
    273290         */
    274         do_action( 'messages_delete_thread', $thread_ids );
     291        do_action( 'messages_delete_thread', $thread_ids, $user_id );
    275292
    276293        return true;
    277294    } else {
    278         if ( ! BP_Messages_Thread::delete( $thread_ids ) ) {
     295        if ( ! BP_Messages_Thread::delete( $thread_ids, $user_id ) ) {
    279296            return false;
    280297        }
    281298
    282299        /** This action is documented in bp-messages/bp-messages-functions.php */
    283         do_action( 'messages_delete_thread', $thread_ids );
     300        do_action( 'messages_delete_thread', $thread_ids, $user_id );
    284301
    285302        return true;
Note: See TracChangeset for help on using the changeset viewer.