Skip to:
Content

BuddyPress.org

Ticket #7235: 7235.3.diff

File 7235.3.diff, 5.4 KB (added by jdgrimes, 5 years ago)

Slightly better @since explanations for new $user_id parameter

  • src/bp-messages/bp-messages-functions.php

     
    238238/**
    239239 * Delete message thread(s).
    240240 *
     241 * @since 2.7.0 The $user_id parameter was added. Previously the current user
     242 *              was always assumed.
     243 *
    241244 * @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.
    242247 * @return bool True on success, false on failure.
    243248 */
    244 function messages_delete_thread( $thread_ids ) {
     249function messages_delete_thread( $thread_ids, $user_id = 0 ) {
    245250
     251        if ( empty( $user_id ) ) {
     252                $user_id = bp_loggedin_user_id();
     253        }
     254
    246255        /**
    247256         * Fires before specified thread IDs have been deleted.
    248257         *
    249258         * @since 1.5.0
     259         * @since 2.7.0 The $user_id parameter was added.
    250260         *
    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.
    252263         */
    253         do_action( 'messages_before_delete_thread', $thread_ids );
     264        do_action( 'messages_before_delete_thread', $thread_ids, $user_id );
    254265
    255266        if ( is_array( $thread_ids ) ) {
    256267                $error = 0;
    257268                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 ) ) {
    259270                                $error = 1;
    260271                        }
    261272                }
     
    268279                 * Fires after specified thread IDs have been deleted.
    269280                 *
    270281                 * @since 1.0.0
     282                 * @since 2.7.0 The $user_id parameter was added.
    271283                 *
    272284                 * @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.
    273286                 */
    274                 do_action( 'messages_delete_thread', $thread_ids );
     287                do_action( 'messages_delete_thread', $thread_ids, $user_id );
    275288
    276289                return true;
    277290        } else {
    278                 if ( ! BP_Messages_Thread::delete( $thread_ids ) ) {
     291                if ( ! BP_Messages_Thread::delete( $thread_ids, $user_id ) ) {
    279292                        return false;
    280293                }
    281294
    282295                /** 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 );
    284297
    285298                return true;
    286299        }
     
    604617         */
    605618        do_action( 'bp_messages_sent_notification_email', $recipients, '', '', $args );
    606619}
    607 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
    608  No newline at end of file
     620add_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
  • src/bp-messages/classes/class-bp-messages-thread.php

     
    326326         * has marked the thread as deleted.
    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;
    337343
     344                if ( empty( $user_id ) ) {
     345                        $user_id = bp_loggedin_user_id();
     346                }
     347
    338348                /**
    339349                 * Fires before a message thread is marked as deleted.
    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.
    356365                $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
     
    398407                 * Fires after a message thread is either marked as deleted or deleted.
    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;
    408419        }