Skip to:
Content

BuddyPress.org

Changeset 9185


Ignore:
Timestamp:
11/26/2014 06:08:54 AM (9 years ago)
Author:
r-a-y
Message:

Introduce 'bp_messages_thread_before_mark_delete' action.

This commit renames the 'bp_messages_thread_before_delete' action added in
r9165 to 'bp_messages_thread_before_mark_delete' and moves the
'bp_messages_thread_before_delete' hook where the message thread is
actually deleted.

The phpDoc for BP_Messages_Thread::delete() is also updated to accurately
outline what is happening in the class method.

See #5193.

File:
1 edited

Legend:

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

    r9184 r9185  
    233233
    234234    /**
    235      * Delete a message thread.
     235     * Mark messages in a thread as deleted or delete all messages in a thread.
     236     *
     237     * Note: All messages in a thread are deleted once every recipient in a thread
     238     * has marked the thread as deleted.
    236239     *
    237240     * @since BuddyPress (1.0.0)
     
    244247
    245248        /**
    246          * Fires before a message thread is deleted.
     249         * Fires before a message thread is marked as deleted.
    247250         *
    248251         * @since BuddyPress (2.2.0)
     
    250253         * @param int $thread_id ID of the thread being deleted.
    251254         */
    252         do_action( 'bp_messages_thread_before_delete', $thread_id );
     255        do_action( 'bp_messages_thread_before_mark_delete', $thread_id );
    253256
    254257        // Mark messages as deleted
     258        //
     259        // @todo the reliance on bp_loggedin_user_id() sucks for plugins
     260        //       refactor this method to accept a $user_id parameter
    255261        $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() ) );
    256262
     
    259265
    260266        // Check to see if any more recipients remain for this message
    261         // if not, then delete the message from the database.
    262267        $recipients = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0", $thread_id ) );
    263268
     269        // No more recipients so delete all messages associated with the thread
    264270        if ( empty( $recipients ) ) {
     271            /**
     272             * Fires before an entire message thread is deleted.
     273             *
     274             * @since BuddyPress (2.2.0)
     275             *
     276             * @param int   $thread_id   ID of the thread being deleted.
     277             * @param array $message_ids IDs of messages being deleted.
     278             */
     279            do_action( 'bp_messages_thread_before_delete', $thread_id, $message_ids );
     280
    265281            // Delete all the messages
    266282            $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
Note: See TracChangeset for help on using the changeset viewer.