Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/24/2021 01:54:39 AM (4 years ago)
Author:
imath
Message:

Make sure deleting an activity comment also deletes its children

This commit also takes care of redirecting the user to the activity single view when clicking on the comment button and there is no comment form available for the corresponding activity. This case can happen on a single member's activity stream when the main activity is an activity comment.

Props yesbutmaybeno

Fixes #8415

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/activity/ajax.php

    r12972 r13114  
    44 *
    55 * @since 3.0.0
    6  * @version 8.1.0
     6 * @version 10.0.0
    77 */
    88
     
    233233    // Deleting an activity comment.
    234234    if ( ! empty( $_POST['is_comment'] ) ) {
     235        // Get replies before they are deleted.
     236        $replies   = (array) BP_Activity_Activity::get_child_comments( $activity->id );
     237        $reply_ids = wp_list_pluck( $replies, 'id' );
     238
    235239        if ( ! bp_activity_delete_comment( $activity->item_id, $activity->id ) ) {
    236240            wp_send_json_error( $response );
     241
     242            // The comment and its replies has been deleted successfully.
     243        } else {
     244            $response = array(
     245                'deleted' => array_merge(
     246                    array( $activity->id ),
     247                    $reply_ids
     248                ),
     249            );
    237250        }
    238251
     
    241254        if ( ! bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) ) {
    242255            wp_send_json_error( $response );
     256
     257            // The activity has been deleted successfully.
     258        } else {
     259            $response = array(
     260                'deleted' => array( $activity->id ),
     261            );
    243262        }
    244263    }
     
    246265    /** This action is documented in bp-activity/bp-activity-actions.php */
    247266    do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
    248 
    249     // The activity has been deleted successfully
    250     $response = array( 'deleted' => $activity->id );
    251267
    252268    // If on a single activity redirect to user's home.
Note: See TracChangeset for help on using the changeset viewer.