Advertisement
Guest User

Untitled

a guest
May 18th, 2012
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. function get_cat_slug($cat_id) {
  2. $cat_id = (int) $cat_id;
  3. $category = &get_category($cat_id);
  4. return $category->slug;
  5. }
  6.  
  7. function bp_blogs_record_post_activity( $post_id, $post, $user_id = 0 ) {
  8. global $bp, $wpdb;
  9.  
  10. $post_id = (int)$post_id;
  11. $blog_id = (int)$wpdb->blogid;
  12.  
  13. $post_categories = wp_get_post_categories($post_id);
  14. $new_events_slug = get_category_by_slug('new-events');
  15.  
  16. foreach($post_categories as $c){
  17. $cat = get_category( $c );
  18. if(!$cat==$new_events_slug){
  19. //get category slug from ID
  20. $category_slug = get_cat_slug($cat);
  21.  
  22. //get group slug
  23. $group_id = groups_get_id($category_slug);
  24. }
  25. }
  26.  
  27. if ( !$user_id )
  28. $user_id = (int)$post->post_author;
  29.  
  30. // Stop infinite loops with WordPress MU Sitewide Tags.
  31. // That plugin changed the way its settings were stored at some point. Thus the dual check.
  32. if ( !empty( $bp->site_options['sitewide_tags_blog'] ) ) {
  33. $st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] );
  34. $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0;
  35. } else {
  36. $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;
  37. }
  38.  
  39. if ( (int)$blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
  40. return false;
  41.  
  42. // Don't record this if it's not a post
  43. if ( !in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ) ) )
  44. return false;
  45.  
  46. $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
  47.  
  48. if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
  49. if ( $is_blog_public || !is_multisite() ) {
  50. // Record this in activity streams
  51. $post_permalink = get_permalink( $post_id );
  52.  
  53. if ( is_multisite() )
  54. $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 ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
  55. else
  56. $activity_action = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
  57.  
  58. $activity_content = $post->post_content;
  59.  
  60. bp_groups_record_activity( array(
  61. 'user_id' => (int)$post->post_author,
  62. 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ),
  63. 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ),
  64. 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
  65. 'type' => 'new_blog_post',
  66. 'item_id' => $group_id,
  67. 'secondary_item_id' => $post_id,
  68. 'recorded_time' => $post->post_modified_gmt,
  69. 'hide_sitewide' => false
  70. ));
  71. }
  72.  
  73. // Update the blogs last activity
  74. bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
  75. } else {
  76. bp_blogs_remove_post( $post_id, $blog_id, $user_id );
  77. }
  78.  
  79. add_filter( 'ass_this_activity_is_important', '__return_true' );
  80. do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
  81.  
  82. }
  83. add_action( 'save_post', 'bp_blogs_record_post_activity', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement