<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[BuddyPress] [1794] trunk/bp-blogs.php: Fixed all comment/post/
 blog recording and deletion functions.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>1794</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-09-04 22:42:52 +0000 (Fri, 04 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixed all comment/post/blog recording and deletion functions. Fixes #772</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpblogsphp">trunk/bp-blogs.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpblogsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-blogs.php (1793 => 1794)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-blogs.php        2009-09-04 21:09:33 UTC (rev 1793)
+++ trunk/bp-blogs.php        2009-09-04 22:42:52 UTC (rev 1794)
</span><span class="lines">@@ -263,9 +263,16 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function bp_blogs_delete_activity( $args = true ) {
</span><del>-        if ( function_exists('bp_activity_delete') ) {
</del><ins>+        if ( function_exists('bp_activity_delete_by_item_id') ) {
</ins><span class="cx">                 extract($args);
</span><del>-                bp_activity_delete_by_item_id( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
</del><ins>+                
+                bp_activity_delete_by_item_id( array( 
+                        'item_id' =&gt; $item_id, 
+                        'component_name' =&gt; $component_name,
+                        'component_action' =&gt; $component_action, 
+                        'user_id' =&gt; $user_id,
+                        'secondary_item_id' =&gt; $secondary_item_id
+                ) );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -299,7 +306,7 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function bp_blogs_record_blog( $blog_id, $user_id ) {
</del><ins>+function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
</ins><span class="cx">         global $bp;
</span><span class="cx">         
</span><span class="cx">         if ( !$user_id )
</span><span class="lines">@@ -311,42 +318,38 @@
</span><span class="cx">         $recorded_blog = new BP_Blogs_Blog;
</span><span class="cx">         $recorded_blog-&gt;user_id = $user_id;
</span><span class="cx">         $recorded_blog-&gt;blog_id = $blog_id;
</span><del>-        
</del><ins>+
</ins><span class="cx">         $recorded_blog_id = $recorded_blog-&gt;save();
</span><span class="cx">         
</span><span class="cx">         bp_blogs_update_blogmeta( $recorded_blog-&gt;blog_id, 'name', $name );
</span><span class="cx">         bp_blogs_update_blogmeta( $recorded_blog-&gt;blog_id, 'description', $description );
</span><span class="cx">         bp_blogs_update_blogmeta( $recorded_blog-&gt;blog_id, 'last_activity', time() );
</span><span class="cx">         
</span><del>-        if ( (int)$_POST['blog_public'] )
-                $is_private = 0;
-        else
-                $is_private = 1;
</del><ins>+        /* Only record this activity if the blog is public */
+        if ( (int)$_POST['blog_public'] &amp;&amp; !$no_activity ) {        
+                /* Record this in activity streams */
+                bp_blogs_record_activity( array(
+                        'user_id' =&gt; $recorded_blog-&gt;user_id,
+                        'content' =&gt; sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog-&gt;user_id ), '&lt;a href=&quot;' . get_blog_option( $recorded_blog-&gt;blog_id, 'siteurl' ) . '&quot;&gt;' . attribute_escape( $name ) . '&lt;/a&gt;' ), 
+                        'primary_link' =&gt; get_blog_option( $recorded_blog-&gt;blog_id, 'siteurl' ),
+                        'component_action' =&gt; 'new_blog',
+                        'item_id' =&gt; $recorded_blog-&gt;blog_id
+                ) );
+        }
</ins><span class="cx">         
</span><del>-        /* Record this in activity streams */
-        bp_blogs_record_activity( array(
-                'user_id' =&gt; $recorded_blog-&gt;user_id,
-                'content' =&gt; sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog-&gt;user_id ), '&lt;a href=&quot;' . get_blog_option( $recorded_blog-&gt;blog_id, 'siteurl' ) . '&quot;&gt;' . attribute_escape( $name ) . '&lt;/a&gt;' ), 
-                'primary_link' =&gt; get_blog_option( $recorded_blog-&gt;blog_id, 'siteurl' ),
-                'component_action' =&gt; 'new_blog',
-                'item_id' =&gt; $recorded_blog_id
-        ) );
-        
-        do_action( 'bp_blogs_new_blog', $recorded_blog, $is_private, $is_recorded );
</del><ins>+        do_action( 'bp_blogs_new_blog', &amp;$recorded_blog, $is_private, $is_recorded );
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
</span><span class="cx"> 
</span><del>-function bp_blogs_record_post( $post_id, $blog_id = false, $user_id = false ) {
</del><ins>+function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
</ins><span class="cx">         global $bp, $wpdb;
</span><span class="cx">         
</span><span class="cx">         $post_id = (int)$post_id;
</span><del>-        $post = get_post($post_id);
</del><ins>+        $blog_id = (int)$wpdb-&gt;blogid;
</ins><span class="cx">         
</span><span class="cx">         if ( !$user_id )
</span><span class="cx">                 $user_id = (int)$post-&gt;post_author;
</span><del>-                
-        if ( !$blog_id )
-                $blog_id = (int)$wpdb-&gt;blogid;
</del><ins>+
</ins><span class="cx">         
</span><span class="cx">         /* This is to stop infinate loops with Donncha's sitewide tags plugin */
</span><span class="cx">         if ( (int)get_site_option('tags_blog_id') == (int)$blog_id )
</span><span class="lines">@@ -363,7 +366,7 @@
</span><span class="cx">                         $recorded_post-&gt;user_id = $user_id;
</span><span class="cx">                         $recorded_post-&gt;blog_id = $blog_id;
</span><span class="cx">                         $recorded_post-&gt;post_id = $post_id;
</span><del>-                        $recorded_post-&gt;date_created = strtotime( $post-&gt;post_date_gmt );
</del><ins>+                        $recorded_post-&gt;date_created = strtotime( $post-&gt;post_date );
</ins><span class="cx">                         
</span><span class="cx">                         $recorded_post_id = $recorded_post-&gt;save();
</span><span class="cx">                         
</span><span class="lines">@@ -371,56 +374,59 @@
</span><span class="cx"> 
</span><span class="cx">                         $post_permalink = bp_post_get_permalink( $post, $blog_id );
</span><span class="cx"> 
</span><ins>+                        $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post-&gt;post_author ), '&lt;a href=&quot;' . $post_permalink . '&quot;&gt;' . $post-&gt;post_title . '&lt;/a&gt;' );
+                        $activity_content .= &quot;&lt;blockquote&gt;&quot; . bp_create_excerpt( $post-&gt;post_content ) . &quot;&lt;/blockquote&gt;&quot;;
+                        
</ins><span class="cx">                         /* Record this in activity streams */
</span><span class="cx">                         bp_blogs_record_activity( array(
</span><span class="cx">                                 'user_id' =&gt; (int)$post-&gt;post_author,
</span><del>-                                'content' =&gt; sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post-&gt;post_author ), '&lt;a href=&quot;' . $post_permalink . '&quot;&gt;' . $post-&gt;post_title . '&lt;/a&gt;' ), 
</del><ins>+                                'content' =&gt; $activity_content, 
</ins><span class="cx">                                 'primary_link' =&gt; $post_permalink,
</span><span class="cx">                                 'component_action' =&gt; 'new_blog_post',
</span><del>-                                'item_id' =&gt; $recorded_post-&gt;id,
-                                'recorded_time' =&gt; $recorded_post-&gt;date_created
</del><ins>+                                'item_id' =&gt; $recorded_post_id,
+                                'recorded_time' =&gt; strtotime( $post-&gt;post_date )
</ins><span class="cx">                         ) );
</span><span class="cx">                 }
</span><span class="cx">         } else {
</span><span class="cx">                 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
</span><span class="cx"> 
</span><del>-                /**
-                 *  Delete the recorded post if:
-                 *  - The status is no longer &quot;published&quot;
-                 *  - The post is password protected
-                 */
-                if ( 'publish' != $post-&gt;post_status || '' != $post-&gt;post_password )
-                        bp_blogs_remove_post( $post_id, $blog_id );
</del><ins>+                /* Delete and the activity stream item as we are probably going to re-add it later with new info. */
+                bp_blogs_delete_activity( array( 'item_id' =&gt; $existing_post-&gt;id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog_post' ) );
+
+                /* Delete the recorded post if the status is not published or it is password protected */
+                if ( 'publish' != $post-&gt;post_status || '' != $post-&gt;post_password ) {
+                        return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );                        
</ins><span class="cx">                 
</span><del>-                // Check to see if the post author has changed.
-                if ( (int)$existing_post-&gt;user_id != (int)$post-&gt;post_author ) {
</del><ins>+                /* If the post author has changed, delete the post and re-add it. */
+                } else if ( (int)$existing_post-&gt;user_id != (int)$post-&gt;post_author ) {
</ins><span class="cx">                         // Delete the existing recorded post
</span><del>-                        bp_blogs_remove_post( $post_id, $blog_id );
</del><ins>+                        bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
</ins><span class="cx">                         
</span><span class="cx">                         // Re-record the post with the new author.
</span><del>-                        bp_blogs_record_post( $post_id );
</del><ins>+                        bp_blogs_record_post( $post_id );                                
</ins><span class="cx">                 }
</span><span class="cx">                 
</span><ins>+                /* Now re-record the post in the activity streams */                
</ins><span class="cx">                 $post_permalink = bp_post_get_permalink( $post, $blog_id );
</span><span class="cx">                 
</span><del>-                /* Delete and re-add the activity stream item to reflect potential content changes. */
-                bp_blogs_delete_activity( array( 'item_id' =&gt; $recorded_post-&gt;id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog_post', 'user_id' =&gt; $recorded_post-&gt;user_id ) );
</del><span class="cx"> 
</span><ins>+                $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post-&gt;post_author ), '&lt;a href=&quot;' . $post_permalink . '&quot;&gt;' . $post-&gt;post_title . '&lt;/a&gt;' );
+                $activity_content .= &quot;&lt;blockquote&gt;&quot; . bp_create_excerpt( $post-&gt;post_content ) . &quot;&lt;/blockquote&gt;&quot;;
+                
</ins><span class="cx">                 /* Record this in activity streams */
</span><span class="cx">                 bp_blogs_record_activity( array(
</span><span class="cx">                         'user_id' =&gt; (int)$post-&gt;post_author,
</span><del>-                        'content' =&gt; sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post-&gt;post_author ), '&lt;a href=&quot;' . $post_permalink . '&quot;&gt;' . $post-&gt;post_title . '&lt;/a&gt;' ), 
</del><ins>+                        'content' =&gt; $activity_content, 
</ins><span class="cx">                         'primary_link' =&gt; $post_permalink,
</span><span class="cx">                         'component_action' =&gt; 'new_blog_post',
</span><span class="cx">                         'item_id' =&gt; $existing_post-&gt;id,
</span><del>-                        'recorded_time' =&gt; $existing_post-&gt;date_created
</del><ins>+                        'recorded_time' =&gt; strtotime( $post-&gt;post_date )
</ins><span class="cx">                 ) );
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded );
</span><span class="cx"> }
</span><del>-add_action( 'publish_post', 'bp_blogs_record_post' );
-add_action( 'edit_post', 'bp_blogs_record_post' );
</del><ins>+add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
</ins><span class="cx"> 
</span><span class="cx"> function bp_blogs_record_comment( $comment_id, $is_approved ) {
</span><span class="cx">         global $wpdb, $bp;
</span><span class="lines">@@ -429,6 +435,7 @@
</span><span class="cx">                 return false;
</span><span class="cx">                 
</span><span class="cx">         $comment = get_comment($comment_id);
</span><ins>+        $comment-&gt;post = get_post( $comment-&gt;comment_post_ID );
</ins><span class="cx">         
</span><span class="cx">         /* Get the user_id from the author email. */
</span><span class="cx">         $user = get_user_by_email( $comment-&gt;comment_author_email );
</span><span class="lines">@@ -442,25 +449,28 @@
</span><span class="cx">         $recorded_comment-&gt;blog_id = $wpdb-&gt;blogid;
</span><span class="cx">         $recorded_comment-&gt;comment_id = $comment_id;
</span><span class="cx">         $recorded_comment-&gt;comment_post_id = $comment-&gt;comment_post_ID;
</span><del>-        $recorded_comment-&gt;date_created = strtotime( $comment-&gt;comment_date_gmt );
</del><ins>+        $recorded_comment-&gt;date_created = strtotime( $comment-&gt;comment_date );
</ins><span class="cx"> 
</span><span class="cx">         $recorded_commment_id = $recorded_comment-&gt;save();
</span><span class="cx">         
</span><span class="cx">         bp_blogs_update_blogmeta( $recorded_comment-&gt;blog_id, 'last_activity', time() );
</span><span class="cx"> 
</span><span class="cx">         $comment_link = bp_post_get_permalink( $comment-&gt;post, $recorded_comment-&gt;blog_id );
</span><del>-        $content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '&lt;a href=&quot;' . $comment_link . '#comment-' . $comment-&gt;comment_ID . '&quot;&gt;' . $comment-&gt;post-&gt;post_title . '&lt;/a&gt;' ) . ' &lt;span class=&quot;time-since&quot;&gt;%s&lt;/span&gt;';                        
-        $content .= '&lt;blockquote&gt;' . bp_create_excerpt( $comment-&gt;comment_content ) . '&lt;/blockquote&gt;';
</del><ins>+        $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '&lt;a href=&quot;' . $comment_link . '#comment-' . $comment-&gt;comment_ID . '&quot;&gt;' . $comment-&gt;post-&gt;post_title . '&lt;/a&gt;' );                        
+        $activity_content .= '&lt;blockquote&gt;' . bp_create_excerpt( $comment-&gt;comment_content ) . '&lt;/blockquote&gt;';
</ins><span class="cx"> 
</span><span class="cx">         /* Record this in activity streams */
</span><span class="cx">         bp_blogs_record_activity( array(
</span><span class="cx">                 'user_id' =&gt; $recorded_comment-&gt;user_id,
</span><del>-                'content' =&gt; $content, 
</del><ins>+                'content' =&gt; $activity_content, 
</ins><span class="cx">                 'primary_link' =&gt; $comment_link,
</span><span class="cx">                 'component_action' =&gt; 'new_blog_comment',
</span><del>-                'item_id' =&gt; $recorded_comment-&gt;blog_id,
-                'recorded_time' =&gt;  $recorded_comment-&gt;date_created 
</del><ins>+                'item_id' =&gt; $comment_id,
+                'secondary_item_id' =&gt; $recorded_comment-&gt;blog_id,
+                'recorded_time' =&gt;  $recorded_comment-&gt;date_created
</ins><span class="cx">         ) );
</span><ins>+        
+        return $recorded_comment;
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
</span><span class="cx"> 
</span><span class="lines">@@ -469,11 +479,12 @@
</span><span class="cx"> 
</span><span class="cx">         $recorded_comment = bp_blogs_record_comment( $comment_id, true );
</span><span class="cx">         $comment = get_comment($comment_id);
</span><ins>+        $comment-&gt;post = get_post( $comment-&gt;comment_post_ID );
+        
+        bp_blogs_delete_activity( array( 'item_id' =&gt; $comment_id, 'secondary_item_id' =&gt; $recorded_comment-&gt;blog_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog_comment' ) );
</ins><span class="cx"> 
</span><del>-        bp_blogs_delete_activity( array( 'item_id' =&gt; $recorded_comment-&gt;blog_id, 'secondary_item_id' =&gt; $recorded_commment_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog_comment', 'user_id' =&gt; $recorded_comment-&gt;user_id ) );
-
</del><span class="cx">         $comment_link = bp_post_get_permalink( $comment-&gt;post, $comment-&gt;blog_id );
</span><del>-        $content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '&lt;a href=&quot;' . $comment_link . '#comment-' . $comment-&gt;comment_ID . '&quot;&gt;' . $comment-&gt;post-&gt;post_title . '&lt;/a&gt;' ) . ' &lt;span class=&quot;time-since&quot;&gt;%s&lt;/span&gt;';                        
</del><ins>+        $content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $recorded_comment-&gt;user_id ), '&lt;a href=&quot;' . $comment_link . '#comment-' . $comment-&gt;comment_ID . '&quot;&gt;' . $comment-&gt;post-&gt;post_title . '&lt;/a&gt;' );                        
</ins><span class="cx">         $content .= '&lt;blockquote&gt;' . bp_create_excerpt( $comment-&gt;comment_content ) . '&lt;/blockquote&gt;';
</span><span class="cx"> 
</span><span class="cx">         /* Record this in activity streams */
</span><span class="lines">@@ -482,7 +493,8 @@
</span><span class="cx">                 'content' =&gt; $content, 
</span><span class="cx">                 'primary_link' =&gt; $comment_link,
</span><span class="cx">                 'component_action' =&gt; 'new_blog_comment',
</span><del>-                'item_id' =&gt; $recorded_comment-&gt;blog_id,
</del><ins>+                'item_id' =&gt; $comment_id,
+                'secondary_item_id' =&gt; $recorded_comment-&gt;blog_id,
</ins><span class="cx">                 'recorded_time' =&gt;  $recorded_comment-&gt;date_created 
</span><span class="cx">         ) );
</span><span class="cx"> }
</span><span class="lines">@@ -497,7 +509,7 @@
</span><span class="cx"> 
</span><span class="cx"> function bp_blogs_add_user_to_blog( $user_id, $role, $blog_id ) {
</span><span class="cx">         if ( $role != 'subscriber' ) {
</span><del>-                bp_blogs_record_blog( $blog_id, $user_id );
</del><ins>+                bp_blogs_record_blog( $blog_id, $user_id, $no_activity = true );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
</span><span class="lines">@@ -515,7 +527,7 @@
</span><span class="cx">         BP_Blogs_Blog::delete_blog_for_all( $blog_id );
</span><span class="cx">         
</span><span class="cx">         // Delete activity stream item
</span><del>-        bp_blogs_delete_activity( array( 'item_id' =&gt; $blog_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog', 'user_id' =&gt; $bp-&gt;loggedin_user-&gt;id ) );
</del><ins>+        bp_blogs_delete_activity( array( 'item_id' =&gt; $blog_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog' ) );
</ins><span class="cx">         
</span><span class="cx">         do_action( 'bp_blogs_remove_blog', $blog_id );
</span><span class="cx"> }
</span><span class="lines">@@ -530,25 +542,28 @@
</span><span class="cx">         BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
</span><span class="cx"> 
</span><span class="cx">         // Delete activity stream item
</span><del>-        bp_blogs_delete_activity( array( 'item_id' =&gt; $blog_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog', 'user_id' =&gt; $current_user-&gt;ID ) );
</del><ins>+        bp_blogs_delete_activity( array( 'item_id' =&gt; $blog_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog' ) );
</ins><span class="cx"> 
</span><span class="cx">         do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
</span><span class="cx"> }
</span><span class="cx"> add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
</span><span class="cx"> 
</span><del>-function bp_blogs_remove_post( $post_id ) {
</del><ins>+function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
</ins><span class="cx">         global $current_blog, $bp;
</span><span class="cx"> 
</span><span class="cx">         $post_id = (int)$post_id;
</span><del>-        $blog_id = (int)$current_blog-&gt;blog_id;
</del><span class="cx">         
</span><del>-        $post = new BP_Blogs_Post( null, $blog_id, $post_id );
</del><ins>+        if ( !$blog_id )
+                $blog_id = (int)$current_blog-&gt;blog_id;
+        
+        if ( !$existing_post )
+                $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
</ins><span class="cx"> 
</span><span class="cx">         // Delete post from the bp_blogs table
</span><span class="cx">         BP_Blogs_Post::delete( $post_id, $blog_id );
</span><span class="cx">                 
</span><span class="cx">         // Delete activity stream item
</span><del>-        bp_blogs_delete_activity( array( 'item_id' =&gt; $post-&gt;id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog_post', 'user_id' =&gt; $post-&gt;user_id ) );
</del><ins>+        bp_blogs_delete_activity( array( 'item_id' =&gt; $existing_post-&gt;id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog_post' ) );
</ins><span class="cx"> 
</span><span class="cx">         do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $post-&gt;user_id );
</span><span class="cx"> }
</span><span class="lines">@@ -561,7 +576,7 @@
</span><span class="cx">         BP_Blogs_Comment::delete( $comment_id, $wpdb-&gt;blogid );        
</span><span class="cx"> 
</span><span class="cx">         // Delete activity stream item
</span><del>-        bp_blogs_delete_activity( array( 'item_id' =&gt; $recorded_comment-&gt;blog_id, 'secondary_item_id' =&gt; $recorded_comment-&gt;id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog_comment', 'user_id' =&gt; $recorded_comment-&gt;user_id ) );
</del><ins>+        bp_blogs_delete_activity( array( 'item_id' =&gt; $comment_id, 'secondary_item_id' =&gt; $recorded_comment-&gt;blog_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; 'new_blog_comment' ) );
</ins><span class="cx"> 
</span><span class="cx">         do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp-&gt;loggedin_user-&gt;id );
</span><span class="cx"> }
</span><span class="lines">@@ -576,7 +591,7 @@
</span><span class="cx">         BP_Blogs_Comment::delete_comments_for_blog( $blog_id );
</span><span class="cx"> 
</span><span class="cx">         // Delete activity stream item
</span><del>-        bp_blogs_delete_activity( array( 'item_id' =&gt; $blog_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; false, 'user_id' =&gt; $bp-&gt;loggedin_user-&gt;id ) );
</del><ins>+        bp_blogs_delete_activity( array( 'item_id' =&gt; $blog_id, 'component_name' =&gt; $bp-&gt;blogs-&gt;slug, 'component_action' =&gt; false ) );
</ins><span class="cx"> 
</span><span class="cx">         do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>