bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity )

Updates the blog comment when the associated activity comment is edited.

Description

Parameters

$activity

(Required) The activity object.

Source

File: bp-blogs/bp-blogs-activity.php

1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) {
    // This is a new entry, so stop!
    // We only want edits!
    if ( empty( $activity->id ) || bp_disable_blogforum_comments() ) {
        return;
    }
 
    // fetch parent activity item
    $parent_activity = new BP_Activity_Activity( $activity->item_id );
 
    // if parent activity isn't a post type having the buddypress-activity support for comments, stop now!
    if ( ! bp_activity_type_supports( $parent_activity->type, 'post-type-comment-tracking' ) ) {
        return;
    }
 
    $post_type = bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'post_type' );
 
    // No associated post type for this activity comment, stop.
    if ( ! $post_type ) {
        return;
    }
 
    // Try to see if a corresponding blog comment exists.
    $post_comment_id = bp_activity_get_meta( $activity->id, "bp_blogs_{$post_type}_comment_id" );
 
    if ( empty( $post_comment_id ) ) {
        return;
    }
 
    // Handle multisite.
    switch_to_blog( $parent_activity->item_id );
 
    // Get the comment status
    $post_comment_status = wp_get_comment_status( $post_comment_id );
    $old_comment_status  = $post_comment_status;
 
    // No need to edit the activity, as it's the activity who's updating the comment
    remove_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10 );
    remove_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10 );
 
    if ( 1 === $activity->is_spam && 'spam' !== $post_comment_status ) {
        wp_spam_comment( $post_comment_id );
    } elseif ( ! $activity->is_spam ) {
        if ( 'spam' === $post_comment_status  ) {
            wp_unspam_comment( $post_comment_id );
        } elseif ( 'trash' === $post_comment_status ) {
            wp_untrash_comment( $post_comment_id );
        } else {
            // Update the blog post comment.
            wp_update_comment( array(
                'comment_ID'       => $post_comment_id,
                'comment_content'  => $activity->content,
            ) );
        }
    }
 
    // Restore actions
    add_action( 'transition_comment_status',     'bp_activity_transition_post_type_comment_status', 10, 3 );
    add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment',          10, 4 );
 
    restore_current_blog();
}

Changelog

Changelog
Version Description
BuddyPress 2.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.