Guest User

Untitled

a guest
May 19th, 2013
1,066
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // begin record products to BP activity stream
  2. function product_record_activity( $post_id, $post, $user_id = false ) {
  3.  
  4. global $bp, $wpdb;
  5.  
  6. //check for multisite install
  7. if(!is_multisite()) return false;
  8.  
  9. $post_id = (int)$post_id;
  10. $blog_id = (int)$wpdb->blogid;
  11.  
  12. if ( !$user_id )
  13. $user_id = (int)$post->post_author;
  14.  
  15. /* This is to stop infinite loops with Donncha's sitewide tags plugin */
  16. if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id ) return false;
  17.  
  18. /* Don't record this if it's a regular post */
  19. if ( $post->post_type != 'product' ) return false;
  20.  
  21. if ( ( 'publish' == $post->post_status ) && ( '' == $post->post_password ) ) {
  22.  
  23. if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
  24.  
  25. /* Record this in activity streams */
  26. $post_permalink = get_permalink( $post_id );
  27.  
  28. $activity_action = sprintf( __( '%1$s added or updated the product %2$s, in the store: %3$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', get_blog_option($blog_id, 'blogname') );
  29. $activity_content = $post->post_content;
  30.  
  31. bp_blogs_record_activity( array(
  32. 'user_id' => (int)$post->post_author,
  33. 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
  34. 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
  35. 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
  36. 'type' => 'new_blog_post',
  37. 'item_id' => $blog_id,
  38. 'secondary_item_id' => $post_id,
  39. 'recorded_time' => $post->post_modified_gmt
  40. ));
  41. }
  42. } else
  43. bp_blogs_remove_post( $post_id, $blog_id );
  44.  
  45. bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
  46.  
  47. do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
  48.  
  49. /* check for existing entry and update if one exists */
  50. $id = bp_activity_get_activity_id( array(
  51. 'user_id' => $user_id,
  52. 'component' => $component,
  53. 'type' => $type,
  54. 'item_id' => $item_id,
  55. 'secondary_item_id' => $secondary_item_id
  56. ) );
  57.  
  58. return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
  59.  
  60. }
  61.  
  62. add_action( 'save_post', 'product_record_activity', 10, 2 );
  63. //end record products to the BP activity stream
RAW Paste Data