function get_cat_slug($cat_id) {
$cat_id = (int) $cat_id;
$category = &get_category($cat_id);
return $category->slug;
}
function bp_blogs_record_post_activity( $post_id, $post, $user_id = 0 ) {
global $bp, $wpdb;
$post_id = (int)$post_id;
$blog_id = (int)$wpdb->blogid;
$post_categories = wp_get_post_categories($post_id);
$new_events_slug = get_category_by_slug('new-events');
foreach($post_categories as $c){
$cat = get_category( $c );
if(!$cat==$new_events_slug){
//get category slug from ID
$category_slug = get_cat_slug($cat);
//get group slug
$group_id = groups_get_id($category_slug);
}
}
if ( !$user_id )
$user_id = (int)$post->post_author;
// Stop infinite loops with WordPress MU Sitewide Tags.
// That plugin changed the way its settings were stored at some point. Thus the dual check.
if ( !empty( $bp->site_options['sitewide_tags_blog'] ) ) {
$st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] );
$tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0;
} else {
$tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;
}
if ( (int)$blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
return false;
// Don't record this if it's not a post
if ( !in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ) ) )
return false;
$is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
if ( $is_blog_public || !is_multisite() ) {
// Record this in activity streams
$post_permalink = get_permalink( $post_id );
if ( is_multisite() )
$activity_action = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '' . $post->post_title . '', '' . get_blog_option( $blog_id, 'blogname' ) . '' );
else
$activity_action = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '' . $post->post_title . '' );
$activity_content = $post->post_content;
bp_groups_record_activity( array(
'user_id' => (int)$post->post_author,
'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ),
'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ),
'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
'type' => 'new_blog_post',
'item_id' => $group_id,
'secondary_item_id' => $post_id,
'recorded_time' => $post->post_modified_gmt,
'hide_sitewide' => false
));
}
// Update the blogs last activity
bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
} else {
bp_blogs_remove_post( $post_id, $blog_id, $user_id );
}
add_filter( 'ass_this_activity_is_important', '__return_true' );
do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
}
add_action( 'save_post', 'bp_blogs_record_post_activity', 10, 2 );