<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][11883] trunk/src/bp-activity: Activity: Move some functions from `bp-activity-actions.php` to `bp-activity-functions.php`</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/11883">11883</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/11883","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>r-a-y</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-03-04 23:10:35 +0000 (Sun, 04 Mar 2018)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Activity: Move some functions from `bp-activity-actions.php` to `bp-activity-functions.php`

Some of the functions from `bp-activity-actions.php` are not related to
activity page actions, so these are being moved to the all-purpose
`bp-activity-functions.php` file (for better or worse!).

The intent is to remove and split up the `bp-activity-actions.php` and
`bp-activity-screens.php` files until these functions are actually
needed.

See <a href="http://buddypress.trac.wordpress.org/ticket/7218">#7218</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivityactionsphp">trunk/src/bp-activity/bp-activity-actions.php</a></li>
<li><a href="#trunksrcbpactivitybpactivityfunctionsphp">trunk/src/bp-activity/bp-activity-functions.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpactivitybpactivityactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-actions.php     2018-03-04 21:35:46 UTC (rev 11882)
+++ trunk/src/bp-activity/bp-activity-actions.php       2018-03-04 23:10:35 UTC (rev 11883)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -13,23 +13,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> defined( 'ABSPATH' ) || exit;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Allow core components and dependent plugins to register activity actions.
- *
- * @since 1.2.0
- *
- */
-function bp_register_activity_actions() {
-
-       /**
-        * Fires on bp_init to allow core components and dependent plugins to register activity actions.
-        *
-        * @since 1.2.0
-        */
-       do_action( 'bp_register_activity_actions' );
-}
-add_action( 'bp_init', 'bp_register_activity_actions', 8 );
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px">  * Catch and route requests for single activity item permalinks.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 1.2.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -603,252 +586,3 @@
</span><span class="cx" style="display: block; padding: 0 10px">        ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-/**
- * AJAX endpoint for Suggestions API lookups.
- *
- * @since 2.1.0
- */
-function bp_ajax_get_suggestions() {
-       if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) {
-               wp_send_json_error( 'missing_parameter' );
-               exit;
-       }
-
-       $args = array(
-               'term' => sanitize_text_field( $_GET['term'] ),
-               'type' => sanitize_text_field( $_GET['type'] ),
-       );
-
-       // Support per-Group suggestions.
-       if ( ! empty( $_GET['group-id'] ) ) {
-               $args['group_id'] = absint( $_GET['group-id'] );
-       }
-
-       $results = bp_core_get_suggestions( $args );
-
-       if ( is_wp_error( $results ) ) {
-               wp_send_json_error( $results->get_error_message() );
-               exit;
-       }
-
-       wp_send_json_success( $results );
-}
-add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' );
-
-/**
- * Detect a change in post type status, and initiate an activity update if necessary.
- *
- * @since 2.2.0
- *
- * @todo Support untrashing better.
- *
- * @param string $new_status New status for the post.
- * @param string $old_status Old status for the post.
- * @param object $post       Post data.
- */
-function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) {
-       if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) {
-               return;
-       }
-
-       // This is an edit.
-       if ( $new_status === $old_status ) {
-               // An edit of an existing post should update the existing activity item.
-               if ( $new_status == 'publish' ) {
-                       $edit = bp_activity_post_type_update( $post );
-
-                       // Post was never recorded into activity stream, so record it now!
-                       if ( null === $edit ) {
-                               bp_activity_post_type_publish( $post->ID, $post );
-                       }
-
-               // Allow plugins to eventually deal with other post statuses.
-               } else {
-                       /**
-                        * Fires when editing the post and the new status is not 'publish'.
-                        *
-                        * This is a variable filter that is dependent on the post type
-                        * being untrashed.
-                        *
-                        * @since 2.5.0
-                        *
-                        * @param WP_Post $post Post data.
-                        * @param string $new_status New status for the post.
-                        * @param string $old_status Old status for the post.
-                        */
-                       do_action( 'bp_activity_post_type_edit_' . $post->post_type, $post, $new_status, $old_status );
-               }
-
-               return;
-       }
-
-       // Publishing a previously unpublished post.
-       if ( 'publish' === $new_status ) {
-               // Untrashing the post type - nothing here yet.
-               if ( 'trash' == $old_status ) {
-
-                       /**
-                        * Fires if untrashing post in a post type.
-                        *
-                        * This is a variable filter that is dependent on the post type
-                        * being untrashed.
-                        *
-                        * @since 2.2.0
-                        *
-                        * @param WP_Post $post Post data.
-                        */
-                       do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post );
-               } else {
-                       // Record the post.
-                       bp_activity_post_type_publish( $post->ID, $post );
-               }
-
-       // Unpublishing a previously published post.
-       } elseif ( 'publish' === $old_status ) {
-               // Some form of pending status - only remove the activity entry.
-               bp_activity_post_type_unpublish( $post->ID, $post );
-
-       // For any other cases, allow plugins to eventually deal with it.
-       } else {
-               /**
-                * Fires when the old and the new post status are not 'publish'.
-                *
-                * This is a variable filter that is dependent on the post type
-                * being untrashed.
-                *
-                * @since 2.5.0
-                *
-                * @param WP_Post $post Post data.
-                * @param string $new_status New status for the post.
-                * @param string $old_status Old status for the post.
-                */
-               do_action( 'bp_activity_post_type_transition_status_' . $post->post_type, $post, $new_status, $old_status );
-       }
-}
-add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 );
-
-/**
- * When a post type comment status transition occurs, update the relevant activity's status.
- *
- * @since 2.5.0
- *
- * @param string     $new_status New comment status.
- * @param string     $old_status Previous comment status.
- * @param WP_Comment $comment Comment data.
- */
-function bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment ) {
-       $post_type = get_post_type( $comment->comment_post_ID );
-       if ( ! $post_type ) {
-               return;
-       }
-
-       // Get the post type tracking args.
-       $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );
-
-       // Bail if the activity type does not exist
-       if ( empty( $activity_post_object->comments_tracking->action_id ) ) {
-               return false;
-
-       // Set the $activity_comment_object
-       } else {
-               $activity_comment_object = $activity_post_object->comments_tracking;
-       }
-
-       // Init an empty activity ID
-       $activity_id = 0;
-
-       /**
-        * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
-        *
-        * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
-        * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
-        * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
-        * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam.
-        * Otherwise, record the comment into the activity stream.
-        */
-
-       // This clause handles delete/hold.
-       if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) {
-               return bp_activity_post_type_remove_comment( $comment->comment_ID, $activity_post_object );
-
-       // These clauses handle trash, spam, and un-spams.
-       } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) {
-               $action = 'spam_activity';
-       } elseif ( 'approved' == $new_status ) {
-               $action = 'ham_activity';
-       }
-
-       // Get the activity
-       if ( bp_disable_blogforum_comments() ) {
-               $activity_id = bp_activity_get_activity_id( array(
-                       'component'         => $activity_comment_object->component_id,
-                       'item_id'           => get_current_blog_id(),
-                       'secondary_item_id' => $comment->comment_ID,
-                       'type'              => $activity_comment_object->action_id,
-               ) );
-       } else {
-               $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
-       }
-
-       /**
-        * Leave a chance to plugins to manage activity comments differently.
-        *
-        * @since  2.5.0
-        *
-        * @param bool        $value       True to override BuddyPress management.
-        * @param string      $post_type   The post type name.
-        * @param int         $activity_id The post type activity (0 if not found).
-        * @param string      $new_status  The new status of the post type comment.
-        * @param string      $old_status  The old status of the post type comment.
-        * @param WP_Comment  $comment Comment data.
-        */
-       if ( true === apply_filters( 'bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment ) ) {
-               return false;
-       }
-
-       // Check activity item exists
-       if ( empty( $activity_id ) ) {
-               // If no activity exists, but the comment has been approved, record it into the activity table.
-               if ( 'approved' == $new_status ) {
-                       return bp_activity_post_type_comment( $comment->comment_ID, true, $activity_post_object );
-               }
-
-               return;
-       }
-
-       // Create an activity object
-       $activity = new BP_Activity_Activity( $activity_id );
-       if ( empty( $activity->component ) ) {
-               return;
-       }
-
-       // Spam/ham the activity if it's not already in that state
-       if ( 'spam_activity' === $action && ! $activity->is_spam ) {
-               bp_activity_mark_as_spam( $activity );
-       } elseif ( 'ham_activity' == $action) {
-               bp_activity_mark_as_ham( $activity );
-       }
-
-       // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
-       $post_type_comment_action = $activity_comment_object->action_id;
-       $comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) {
-               $activity_types[] = $post_type_comment_action;
-
-               return $activity_types;
-       };
-       add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
-
-       // Make sure the activity change won't edit the comment if sync is on
-       remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
-
-       // Save the updated activity
-       $activity->save();
-
-       // Restore the action
-       add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
-
-       // Remove the "new_blog_comment" activity type whitelist so we don't break anything
-       remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
-}
-add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 );
</del></span></pre></div>
<a id="trunksrcbpactivitybpactivityfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-functions.php   2018-03-04 21:35:46 UTC (rev 11882)
+++ trunk/src/bp-activity/bp-activity-functions.php     2018-03-04 23:10:35 UTC (rev 11883)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1419,6 +1419,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Allow core components and dependent plugins to register activity actions.
+ *
+ * @since 1.2.0
+ */
+function bp_register_activity_actions() {
+       /**
+        * Fires on bp_init to allow core components and dependent plugins to register activity actions.
+        *
+        * @since 1.2.0
+        */
+       do_action( 'bp_register_activity_actions' );
+}
+add_action( 'bp_init', 'bp_register_activity_actions', 8 );
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Register the activity stream actions for updates.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 1.6.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3891,3 +3906,252 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        return (bool) apply_filters( 'bp_activity_do_heartbeat', $retval );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * AJAX endpoint for Suggestions API lookups.
+ *
+ * @since 2.1.0
+ */
+function bp_ajax_get_suggestions() {
+       if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) {
+               wp_send_json_error( 'missing_parameter' );
+               exit;
+       }
+
+       $args = array(
+               'term' => sanitize_text_field( $_GET['term'] ),
+               'type' => sanitize_text_field( $_GET['type'] ),
+       );
+
+       // Support per-Group suggestions.
+       if ( ! empty( $_GET['group-id'] ) ) {
+               $args['group_id'] = absint( $_GET['group-id'] );
+       }
+
+       $results = bp_core_get_suggestions( $args );
+
+       if ( is_wp_error( $results ) ) {
+               wp_send_json_error( $results->get_error_message() );
+               exit;
+       }
+
+       wp_send_json_success( $results );
+}
+add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' );
+
+/**
+ * Detect a change in post type status, and initiate an activity update if necessary.
+ *
+ * @since 2.2.0
+ *
+ * @todo Support untrashing better.
+ *
+ * @param string $new_status New status for the post.
+ * @param string $old_status Old status for the post.
+ * @param object $post       Post data.
+ */
+function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) {
+       if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) {
+               return;
+       }
+
+       // This is an edit.
+       if ( $new_status === $old_status ) {
+               // An edit of an existing post should update the existing activity item.
+               if ( $new_status == 'publish' ) {
+                       $edit = bp_activity_post_type_update( $post );
+
+                       // Post was never recorded into activity stream, so record it now!
+                       if ( null === $edit ) {
+                               bp_activity_post_type_publish( $post->ID, $post );
+                       }
+
+               // Allow plugins to eventually deal with other post statuses.
+               } else {
+                       /**
+                        * Fires when editing the post and the new status is not 'publish'.
+                        *
+                        * This is a variable filter that is dependent on the post type
+                        * being untrashed.
+                        *
+                        * @since 2.5.0
+                        *
+                        * @param WP_Post $post Post data.
+                        * @param string $new_status New status for the post.
+                        * @param string $old_status Old status for the post.
+                        */
+                       do_action( 'bp_activity_post_type_edit_' . $post->post_type, $post, $new_status, $old_status );
+               }
+
+               return;
+       }
+
+       // Publishing a previously unpublished post.
+       if ( 'publish' === $new_status ) {
+               // Untrashing the post type - nothing here yet.
+               if ( 'trash' == $old_status ) {
+
+                       /**
+                        * Fires if untrashing post in a post type.
+                        *
+                        * This is a variable filter that is dependent on the post type
+                        * being untrashed.
+                        *
+                        * @since 2.2.0
+                        *
+                        * @param WP_Post $post Post data.
+                        */
+                       do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post );
+               } else {
+                       // Record the post.
+                       bp_activity_post_type_publish( $post->ID, $post );
+               }
+
+       // Unpublishing a previously published post.
+       } elseif ( 'publish' === $old_status ) {
+               // Some form of pending status - only remove the activity entry.
+               bp_activity_post_type_unpublish( $post->ID, $post );
+
+       // For any other cases, allow plugins to eventually deal with it.
+       } else {
+               /**
+                * Fires when the old and the new post status are not 'publish'.
+                *
+                * This is a variable filter that is dependent on the post type
+                * being untrashed.
+                *
+                * @since 2.5.0
+                *
+                * @param WP_Post $post Post data.
+                * @param string $new_status New status for the post.
+                * @param string $old_status Old status for the post.
+                */
+               do_action( 'bp_activity_post_type_transition_status_' . $post->post_type, $post, $new_status, $old_status );
+       }
+}
+add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 );
+
+/**
+ * When a post type comment status transition occurs, update the relevant activity's status.
+ *
+ * @since 2.5.0
+ *
+ * @param string     $new_status New comment status.
+ * @param string     $old_status Previous comment status.
+ * @param WP_Comment $comment Comment data.
+ */
+function bp_activity_transition_post_type_comment_status( $new_status, $old_status, $comment ) {
+       $post_type = get_post_type( $comment->comment_post_ID );
+       if ( ! $post_type ) {
+               return;
+       }
+
+       // Get the post type tracking args.
+       $activity_post_object = bp_activity_get_post_type_tracking_args( $post_type );
+
+       // Bail if the activity type does not exist
+       if ( empty( $activity_post_object->comments_tracking->action_id ) ) {
+               return false;
+
+       // Set the $activity_comment_object
+       } else {
+               $activity_comment_object = $activity_post_object->comments_tracking;
+       }
+
+       // Init an empty activity ID
+       $activity_id = 0;
+
+       /**
+        * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
+        *
+        * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
+        * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
+        * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
+        * If a blog comment transitions to unapproved (and the activity exists), mark the activity as spam.
+        * Otherwise, record the comment into the activity stream.
+        */
+
+       // This clause handles delete/hold.
+       if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) {
+               return bp_activity_post_type_remove_comment( $comment->comment_ID, $activity_post_object );
+
+       // These clauses handle trash, spam, and un-spams.
+       } elseif ( in_array( $new_status, array( 'trash', 'spam', 'unapproved' ) ) ) {
+               $action = 'spam_activity';
+       } elseif ( 'approved' == $new_status ) {
+               $action = 'ham_activity';
+       }
+
+       // Get the activity
+       if ( bp_disable_blogforum_comments() ) {
+               $activity_id = bp_activity_get_activity_id( array(
+                       'component'         => $activity_comment_object->component_id,
+                       'item_id'           => get_current_blog_id(),
+                       'secondary_item_id' => $comment->comment_ID,
+                       'type'              => $activity_comment_object->action_id,
+               ) );
+       } else {
+               $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
+       }
+
+       /**
+        * Leave a chance to plugins to manage activity comments differently.
+        *
+        * @since  2.5.0
+        *
+        * @param bool        $value       True to override BuddyPress management.
+        * @param string      $post_type   The post type name.
+        * @param int         $activity_id The post type activity (0 if not found).
+        * @param string      $new_status  The new status of the post type comment.
+        * @param string      $old_status  The old status of the post type comment.
+        * @param WP_Comment  $comment Comment data.
+        */
+       if ( true === apply_filters( 'bp_activity_pre_transition_post_type_comment_status', false, $post_type, $activity_id, $new_status, $old_status, $comment ) ) {
+               return false;
+       }
+
+       // Check activity item exists
+       if ( empty( $activity_id ) ) {
+               // If no activity exists, but the comment has been approved, record it into the activity table.
+               if ( 'approved' == $new_status ) {
+                       return bp_activity_post_type_comment( $comment->comment_ID, true, $activity_post_object );
+               }
+
+               return;
+       }
+
+       // Create an activity object
+       $activity = new BP_Activity_Activity( $activity_id );
+       if ( empty( $activity->component ) ) {
+               return;
+       }
+
+       // Spam/ham the activity if it's not already in that state
+       if ( 'spam_activity' === $action && ! $activity->is_spam ) {
+               bp_activity_mark_as_spam( $activity );
+       } elseif ( 'ham_activity' == $action) {
+               bp_activity_mark_as_ham( $activity );
+       }
+
+       // Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
+       $post_type_comment_action = $activity_comment_object->action_id;
+       $comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) {
+               $activity_types[] = $post_type_comment_action;
+
+               return $activity_types;
+       };
+       add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
+
+       // Make sure the activity change won't edit the comment if sync is on
+       remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
+
+       // Save the updated activity
+       $activity->save();
+
+       // Restore the action
+       add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
+
+       // Remove the "new_blog_comment" activity type whitelist so we don't break anything
+       remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
+}
+add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 );
</ins></span></pre>
</div>
</div>

</body>
</html>