diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php
index f59004e89..fa104b18d 100644
|
|
function bp_activity_delete_link() { |
2662 | 2662 | // Determine if we're on a single activity page, and customize accordingly. |
2663 | 2663 | if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { |
2664 | 2664 | $class = 'delete-activity-single'; |
| 2665 | } elseif ( 'activity_comment' === bp_get_activity_type() ) { |
| 2666 | $class = 'acomment-delete'; |
2665 | 2667 | } |
2666 | 2668 | |
2667 | 2669 | $link = '<a href="' . esc_url( $url ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>'; |
… |
… |
function bp_activity_delete_url() { |
2698 | 2700 | function bp_get_activity_delete_url() { |
2699 | 2701 | global $activities_template; |
2700 | 2702 | |
2701 | | $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id ); |
| 2703 | $activity_id = 0; |
| 2704 | if ( isset( $activities_template->activity->id ) ) { |
| 2705 | $activity_id = (int) $activities_template->activity->id; |
| 2706 | } |
| 2707 | |
| 2708 | $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activity_id ); |
2702 | 2709 | |
2703 | 2710 | // Determine if we're on a single activity page, and customize accordingly. |
2704 | 2711 | if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { |
2705 | 2712 | $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url ); |
| 2713 | } elseif ( 'activity_comment' === bp_get_activity_type() ) { |
| 2714 | $url = add_query_arg( 'cid', $activity_id, $url ); |
2706 | 2715 | } |
2707 | 2716 | |
2708 | 2717 | $url = wp_nonce_url( $url, 'bp_activity_delete_link' ); |
diff --git src/bp-templates/bp-legacy/js/buddypress.js src/bp-templates/bp-legacy/js/buddypress.js
index aea07c154..9c77a21c8 100644
|
|
jq( function() { |
557 | 557 | c_id = target.attr('href').substr( 10, target.attr('href').length ); |
558 | 558 | form = jq( '#ac-form-' + a_id ); |
559 | 559 | |
| 560 | if ( ! form.length ) { |
| 561 | var viewDiscussionLink = target.closest( 'li.activity' ).find( '.activity-meta a.view' ).prop( 'href' ); |
| 562 | |
| 563 | if ( viewDiscussionLink ) { |
| 564 | window.location.href = viewDiscussionLink; |
| 565 | } |
| 566 | |
| 567 | return false; |
| 568 | } |
| 569 | |
560 | 570 | form.css( 'display', 'none' ); |
561 | 571 | form.removeClass('root'); |
562 | 572 | jq('.ac-form').hide(); |
… |
… |
jq( function() { |
671 | 681 | /* Deleting an activity comment */ |
672 | 682 | if ( target.hasClass('acomment-delete') ) { |
673 | 683 | link_href = target.attr('href'); |
674 | | comment_li = target.parent().parent(); |
675 | | form = comment_li.parents('div.activity-comments').children('form'); |
| 684 | comment_li = target.closest( 'li' ); |
| 685 | |
| 686 | form = comment_li.find( 'form.ac-form' ); |
676 | 687 | |
677 | 688 | nonce = link_href.split('_wpnonce='); |
678 | 689 | nonce = nonce[1]; |
… |
… |
jq( function() { |
687 | 698 | jq('.activity-comments ul .error').remove(); |
688 | 699 | |
689 | 700 | /* Reset the form position */ |
690 | | comment_li.parents('.activity-comments').append(form); |
| 701 | if ( form && form.length ) { |
| 702 | comment_li.closest( '.activity-comments' ).append( form ); |
| 703 | } |
691 | 704 | |
692 | 705 | jq.post( ajaxurl, { |
693 | 706 | action: 'delete_activity_comment', |
diff --git src/bp-templates/bp-nouveau/buddypress/activity/comment.php src/bp-templates/bp-nouveau/buddypress/activity/comment.php
index 4b8b3b3fa..6990cb58c 100644
|
|
|
6 | 6 | * each activity. |
7 | 7 | * |
8 | 8 | * @since 3.0.0 |
9 | | * @version 7.0.0 |
| 9 | * @version 10.0.0 |
10 | 10 | */ |
11 | 11 | |
12 | 12 | bp_nouveau_activity_hook( 'before', 'comment' ); ?> |
13 | 13 | |
14 | | <li id="acomment-<?php bp_activity_comment_id(); ?>" class="comment-item" data-bp-activity-comment-id="<?php bp_activity_comment_id(); ?>"> |
| 14 | <li id="acomment-<?php bp_activity_comment_id(); ?>" class="comment-item" <?php bp_nouveau_activity_data_attribute_id(); ?>> |
15 | 15 | <div class="acomment-avatar item-avatar"> |
16 | 16 | <a href="<?php bp_activity_comment_user_link(); ?>"> |
17 | 17 | <?php |
diff --git src/bp-templates/bp-nouveau/buddypress/activity/entry.php src/bp-templates/bp-nouveau/buddypress/activity/entry.php
index f4d15a1a5..471944678 100644
|
|
|
6 | 6 | * each activity. |
7 | 7 | * |
8 | 8 | * @since 3.0.0 |
9 | | * @version 3.0.0 |
| 9 | * @version 10.0.0 |
10 | 10 | */ |
11 | 11 | |
12 | 12 | bp_nouveau_activity_hook( 'before', 'entry' ); ?> |
13 | 13 | |
14 | | <li class="<?php bp_activity_css_class(); ?>" id="activity-<?php bp_activity_id(); ?>" data-bp-activity-id="<?php bp_activity_id(); ?>" data-bp-timestamp="<?php bp_nouveau_activity_timestamp(); ?>"> |
| 14 | <li class="<?php bp_activity_css_class(); ?>" id="activity-<?php bp_activity_id(); ?>" <?php bp_nouveau_activity_data_attribute_id(); ?> data-bp-timestamp="<?php bp_nouveau_activity_timestamp(); ?>"> |
15 | 15 | |
16 | 16 | <div class="activity-avatar item-avatar"> |
17 | 17 | |
diff --git src/bp-templates/bp-nouveau/includes/activity/ajax.php src/bp-templates/bp-nouveau/includes/activity/ajax.php
index 2469c5bbe..0043e9d4c 100644
|
|
|
3 | 3 | * Activity Ajax functions |
4 | 4 | * |
5 | 5 | * @since 3.0.0 |
6 | | * @version 8.1.0 |
| 6 | * @version 10.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | 9 | // Exit if accessed directly. |
… |
… |
function bp_nouveau_ajax_delete_activity() { |
232 | 232 | |
233 | 233 | // Deleting an activity comment. |
234 | 234 | 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 | |
235 | 239 | if ( ! bp_activity_delete_comment( $activity->item_id, $activity->id ) ) { |
236 | 240 | 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 | ); |
237 | 250 | } |
238 | 251 | |
239 | 252 | // Deleting an activity. |
240 | 253 | } else { |
241 | 254 | if ( ! bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) ) { |
242 | 255 | wp_send_json_error( $response ); |
| 256 | |
| 257 | // The activity has been deleted successfully. |
| 258 | } else { |
| 259 | $response = array( |
| 260 | 'deleted' => array( $activity->id ), |
| 261 | ); |
243 | 262 | } |
244 | 263 | } |
245 | 264 | |
246 | 265 | /** This action is documented in bp-activity/bp-activity-actions.php */ |
247 | 266 | do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id ); |
248 | 267 | |
249 | | // The activity has been deleted successfully |
250 | | $response = array( 'deleted' => $activity->id ); |
251 | | |
252 | 268 | // If on a single activity redirect to user's home. |
253 | 269 | if ( ! empty( $_POST['is_single'] ) ) { |
254 | 270 | $response['redirect'] = bp_core_get_user_domain( $activity->user_id ); |
diff --git src/bp-templates/bp-nouveau/includes/activity/template-tags.php src/bp-templates/bp-nouveau/includes/activity/template-tags.php
index a1299feea..48662dcc1 100644
|
|
|
3 | 3 | * Activity Template tags |
4 | 4 | * |
5 | 5 | * @since 3.0.0 |
6 | | * @version 8.1.0 |
| 6 | * @version 10.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | 9 | // Exit if accessed directly. |
… |
… |
function bp_nouveau_activity_hook( $when = '', $suffix = '' ) { |
146 | 146 | bp_nouveau_hook( $hook ); |
147 | 147 | } |
148 | 148 | |
| 149 | /** |
| 150 | * Output the `data-bp-activity-id` or `data-bp-activity-comment-id` attribute |
| 151 | * according to the activity type. |
| 152 | * |
| 153 | * @since 10.0.0 |
| 154 | */ |
| 155 | function bp_nouveau_activity_data_attribute_id() { |
| 156 | $attribute = 'data-bp-%1$s-id="%2$s"'; |
| 157 | $type = 'activity'; |
| 158 | $id = (int) bp_get_activity_id(); |
| 159 | $comment_id = (int) bp_get_activity_comment_id(); |
| 160 | |
| 161 | if ( 'activity_comment' === bp_get_activity_type() || $comment_id ) { |
| 162 | $type = 'activity-comment'; |
| 163 | |
| 164 | |
| 165 | if ( $comment_id ) { |
| 166 | $id = $comment_id; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | printf( $attribute, $type, $id ); |
| 171 | } |
| 172 | |
149 | 173 | /** |
150 | 174 | * Checks if an activity of the loop has some content. |
151 | 175 | * |
diff --git src/bp-templates/bp-nouveau/js/buddypress-activity.js src/bp-templates/bp-nouveau/js/buddypress-activity.js
index 3a76427f3..f810dd9aa 100644
|
|
|
1 | 1 | /* jshint browser: true */ |
2 | 2 | /* global BP_Nouveau */ |
3 | 3 | /* @since 3.0.0 */ |
4 | | /* @version 8.0.0 */ |
| 4 | /* @version 10.0.0 */ |
5 | 5 | window.bp = window.bp || {}; |
6 | 6 | |
7 | 7 | ( function( bp, $ ) { |
… |
… |
window.bp = window.bp || {}; |
556 | 556 | li_parent = activity_comment_li; |
557 | 557 | } |
558 | 558 | |
| 559 | // Move the form if needed |
| 560 | if ( activity_comment_li.find( 'form' ).length ) { |
| 561 | activity_item.find( '.activity-comments' ).append( activity_comment_li.find( 'form' ) ); |
| 562 | } |
| 563 | |
559 | 564 | parent.ajax( ajaxData, 'activity' ).done( function( response ) { |
560 | 565 | target.removeClass( 'loading' ); |
561 | 566 | |
… |
… |
window.bp = window.bp || {}; |
570 | 575 | |
571 | 576 | if ( activity_comment_id ) { |
572 | 577 | deleted_comments_count = 1; |
| 578 | if ( response.data.deleted ) { |
| 579 | deleted_comments_count = response.data.deleted.length; |
573 | 580 | |
574 | | // Move the form if needed |
575 | | activity_item.append( activity_comment_li.find( 'form' ) ); |
576 | | |
577 | | // Count child comments if there are some |
578 | | $.each( activity_comment_li.find( 'li' ), function() { |
579 | | deleted_comments_count += 1; |
580 | | } ); |
| 581 | response.data.deleted.forEach( function( cid ) { |
| 582 | $( '[data-bp-activity-comment-id="' + cid + '"]' ).remove(); |
| 583 | } ); |
| 584 | } else { |
| 585 | // Count child comments if there are some |
| 586 | $.each( activity_comment_li.find( 'li' ), function() { |
| 587 | deleted_comments_count += 1; |
| 588 | } ); |
| 589 | } |
581 | 590 | |
582 | 591 | // Update the button count |
583 | 592 | comment_count_span = activity_item.find( '.acomment-reply span.comment-count' ); |
… |
… |
window.bp = window.bp || {}; |
660 | 669 | // Stop event propagation |
661 | 670 | event.preventDefault(); |
662 | 671 | |
| 672 | if ( ! form.length ) { |
| 673 | var viewDiscussionLink = target.closest( 'li.activity' ).find( '.activity-meta a.view' ).prop( 'href' ); |
| 674 | |
| 675 | if ( viewDiscussionLink ) { |
| 676 | window.location.href = viewDiscussionLink; |
| 677 | } |
| 678 | |
| 679 | return false; |
| 680 | } |
| 681 | |
663 | 682 | // If the comment count span inside the link is clicked |
664 | 683 | if ( target.parent().hasClass( 'acomment-reply' ) ) { |
665 | 684 | comment_link = target.parent(); |