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/classes/class-bp-messages-thread.php

    r11028 r11153  
    327327     *
    328328     * @since 1.0.0
     329     * @since 2.7.0 The $user_id parameter was added. Previously the current user
     330     *              was always assumed.
    329331     *
    330332     * @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     *
    331336     * @return bool
    332337     */
    333     public static function delete( $thread_id = 0 ) {
     338    public static function delete( $thread_id = 0, $user_id = 0 ) {
    334339        global $wpdb;
    335340
    336341        $thread_id = (int) $thread_id;
     342        $user_id = (int) $user_id;
     343
     344        if ( empty( $user_id ) ) {
     345            $user_id = bp_loggedin_user_id();
     346        }
    337347
    338348        /**
     
    340350         *
    341351         * @since 2.2.0
     352         * @since 2.7.0 The $user_id parameter was added.
    342353         *
    343354         * @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.
    344356         */
    345         do_action( 'bp_messages_thread_before_mark_delete', $thread_id );
     357        do_action( 'bp_messages_thread_before_mark_delete', $thread_id, $user_id );
    346358
    347359        $bp = buddypress();
    348360
    349361        // 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 ) );
    354363
    355364        // Get the message ids in order to pass to the action.
     
    399408         *
    400409         * @since 2.2.0
     410         * @since 2.7.0 The $user_id parameter was added.
    401411         *
    402412         * @param int   $thread_id   ID of the thread being deleted.
    403413         * @param array $message_ids IDs of messages being deleted.
     414         * @param int   $user_id     ID of the user the threads were deleted for.
    404415         */
    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 );
    406417
    407418        return true;
Note: See TracChangeset for help on using the changeset viewer.