Skip to:
Content

BuddyPress.org

Ticket #7235: 7235.2.diff

File 7235.2.diff, 5.3 KB (added by jdgrimes, 5 years ago)

Add @since docs for new 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.
     242 *
    241243 * @param int|array $thread_ids Thread ID or array of thread IDs.
     244 * @param int       $user_id    ID of the user to delete the threads for. Defaults
     245 *                              to the current logged-in user.
    242246 * @return bool True on success, false on failure.
    243247 */
    244 function messages_delete_thread( $thread_ids ) {
     248function messages_delete_thread( $thread_ids, $user_id = 0 ) {
    245249
     250        if ( empty( $user_id ) ) {
     251                $user_id = bp_loggedin_user_id();
     252        }
     253
    246254        /**
    247255         * Fires before specified thread IDs have been deleted.
    248256         *
    249257         * @since 1.5.0
     258         * @since 2.7.0 The $user_id parameter was added.
    250259         *
    251          * @param int|array Thread ID or array of thread IDs that were deleted.
     260         * @param int|array $thread_ids Thread ID or array of thread IDs to be deleted.
     261         * @param int       $user_id    ID of the user the threads are being deleted for.
    252262         */
    253         do_action( 'messages_before_delete_thread', $thread_ids );
     263        do_action( 'messages_before_delete_thread', $thread_ids, $user_id );
    254264
    255265        if ( is_array( $thread_ids ) ) {
    256266                $error = 0;
    257267                for ( $i = 0, $count = count( $thread_ids ); $i < $count; ++$i ) {
    258                         if ( ! BP_Messages_Thread::delete( $thread_ids[$i] ) ) {
     268                        if ( ! BP_Messages_Thread::delete( $thread_ids[$i], $user_id ) ) {
    259269                                $error = 1;
    260270                        }
    261271                }
     
    268278                 * Fires after specified thread IDs have been deleted.
    269279                 *
    270280                 * @since 1.0.0
     281                 * @since 2.7.0 The $user_id parameter was added.
    271282                 *
    272283                 * @param int|array Thread ID or array of thread IDs that were deleted.
     284                 * @param int       ID of the user that the threads were deleted for.
    273285                 */
    274                 do_action( 'messages_delete_thread', $thread_ids );
     286                do_action( 'messages_delete_thread', $thread_ids, $user_id );
    275287
    276288                return true;
    277289        } else {
    278                 if ( ! BP_Messages_Thread::delete( $thread_ids ) ) {
     290                if ( ! BP_Messages_Thread::delete( $thread_ids, $user_id ) ) {
    279291                        return false;
    280292                }
    281293
    282294                /** This action is documented in bp-messages/bp-messages-functions.php */
    283                 do_action( 'messages_delete_thread', $thread_ids );
     295                do_action( 'messages_delete_thread', $thread_ids, $user_id );
    284296
    285297                return true;
    286298        }
     
    604616         */
    605617        do_action( 'bp_messages_sent_notification_email', $recipients, '', '', $args );
    606618}
    607 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
    608  No newline at end of file
     619add_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.
    329330         *
    330331         * @param int $thread_id The message thread ID.
     332         * @param int $user_id The ID of the user in the thread to mark messages as
     333         *                     deleted for. Defaults to the current logged-in user.
     334         *
    331335         * @return bool
    332336         */
    333         public static function delete( $thread_id = 0 ) {
     337        public static function delete( $thread_id = 0, $user_id = 0 ) {
    334338                global $wpdb;
    335339
    336340                $thread_id = (int) $thread_id;
     341                $user_id = (int) $user_id;
    337342
     343                if ( empty( $user_id ) ) {
     344                        $user_id = bp_loggedin_user_id();
     345                }
     346
    338347                /**
    339348                 * Fires before a message thread is marked as deleted.
    340349                 *
    341350                 * @since 2.2.0
     351                 * @since 2.7.0 The $user_id parameter was added.
    342352                 *
    343353                 * @param int $thread_id ID of the thread being deleted.
     354                 * @param int $user_id   ID of the user that the thread is being deleted for.
    344355                 */
    345                 do_action( 'bp_messages_thread_before_mark_delete', $thread_id );
     356                do_action( 'bp_messages_thread_before_mark_delete', $thread_id, $user_id );
    346357
    347358                $bp = buddypress();
    348359
    349360                // 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() ) );
     361                $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 ) );
    354362
    355363                // Get the message ids in order to pass to the action.
    356364                $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
     
    398406                 * Fires after a message thread is either marked as deleted or deleted.
    399407                 *
    400408                 * @since 2.2.0
     409                 * @since 2.7.0 The $user_id parameter was added.
    401410                 *
    402411                 * @param int   $thread_id   ID of the thread being deleted.
    403412                 * @param array $message_ids IDs of messages being deleted.
     413                 * @param int   $user_id     ID of the user the threads were deleted for.
    404414                 */
    405                 do_action( 'bp_messages_thread_after_delete', $thread_id, $message_ids );
     415                do_action( 'bp_messages_thread_after_delete', $thread_id, $message_ids, $user_id );
    406416
    407417                return true;
    408418        }