Re: wp_bp_activity_sitewide and item_id problem
Just in case anybody get into the same trouble – i didn’t managed to get to know why secondary_item_id is now unused, but i wrote my own function to overwrite this behaviour
//HOOKS FOR BP_BLOGS TO SAVE AS SECONDARY ITEM ID BLOG ID
function my_bp_blogs_record_post( $post_id, $blog_id = false, $user_id = false ) {
global $bp, $wpdb;
$post_id = (int)$post_id;
$post = get_post($post_id);
if ( !$user_id )
$user_id = (int)$post->post_author;
if ( !$blog_id )
$blog_id = (int)$wpdb->blogid;
/* This is to stop infinate loops with Donncha’s sitewide tags plugin */
if ( (int)get_site_option(‘tags_blog_id’) == (int)$blog_id )
return false;
/* Don’t record this if it’s not a post */
if ( $post->post_type != ‘post’ )
return false;
if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {
if ( ‘publish’ == $post->post_status && ” == $post->post_password ) {
$recorded_post = new BP_Blogs_Post;
$recorded_post->user_id = $user_id;
$recorded_post->blog_id = $blog_id;
$recorded_post->post_id = $post_id;
$recorded_post->date_created = strtotime( $post->post_date );
$recorded_post_id = $recorded_post->save();
bp_blogs_update_blogmeta( $recorded_post->blog_id, ‘last_activity’, time() );
bp_blogs_record_activity( array( ‘item_id’ => $recorded_post->id, ‘secondary_item_id’ => $blog_id, ‘component_name’ => ‘blogs’, ‘component_action’ => ‘new_blog_post’, ‘is_private’ => bp_blogs_is_blog_hidden( $recorded_post->blog_id ), ‘user_id’ => $recorded_post->user_id, ‘recorded_time’ => strtotime( $post->post_date ) ) );
}
} else {
$existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
/**
* Delete the recorded post if:
* – The status is no longer “published”
* – The post is password protected
*/
if ( ‘publish’ != $post->post_status || ” != $post->post_password )
bp_blogs_remove_post( $post_id, $blog_id );
// Check to see if the post author has changed.
if ( (int)$existing_post->user_id != (int)$post->post_author ) {
// Delete the existing recorded post
bp_blogs_remove_post( $post_id, $blog_id );
// Re-record the post with the new author.
bp_blogs_record_post( $post_id );
}
$recorded_post = $existing_post;
/* Delete and re-add the activity stream item to reflect potential content changes. */
bp_blogs_delete_activity( array( ‘item_id’ => $recorded_post->id, ‘secondary_item_id’ => $blog_id, ‘component_name’ => ‘blogs’, ‘component_action’ => ‘new_blog_post’, ‘user_id’ => $recorded_post->user_id ) );
bp_blogs_record_activity( array( ‘item_id’ => $recorded_post->id, ‘secondary_item_id’ => $blog_id, ‘component_name’ => ‘blogs’, ‘component_action’ => ‘new_blog_post’, ‘is_private’ => bp_blogs_is_blog_hidden( $recorded_post->blog_id ), ‘user_id’ => $recorded_post->user_id, ‘recorded_time’ => strtotime( $post->post_date ) ) );
}
do_action( ‘bp_blogs_new_blog_post’, $recorded_post, $is_private, $is_recorded );
}
remove_action( ‘publish_post’, ‘bp_blogs_record_post’ );
remove_action( ‘edit_post’, ‘bp_blogs_record_post’ );
add_action( ‘publish_post’, ‘my_bp_blogs_record_post’ );
add_action( ‘edit_post’, ‘my_bp_blogs_record_post’ );