Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 9th, 2012  |  syntax: None  |  size: 2.81 KB  |  views: 341  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function media_record_post( $post_id, $post, $user_id = 0 ) {
  2.         global $bp, $wpdb;
  3.  
  4.         $post_id = (int)$post_id;
  5.         $blog_id = (int)$wpdb->blogid;
  6.  
  7.         if ( !$user_id )
  8.                 $user_id = (int)$post->post_author;
  9.  
  10.         // Stop infinite loops with WordPress MU Sitewide Tags.
  11.         // That plugin changed the way its settings were stored at some point. Thus the dual check.
  12.         if ( !empty( $bp->site_options['sitewide_tags_blog'] ) ) {
  13.                 $st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] );
  14.                 $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0;
  15.         } else {
  16.                 $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;
  17.         }
  18.  
  19.         if ( (int)$blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
  20.                 return false;
  21.  
  22.         // Don't record this if it's not a post
  23.         if ( $post->post_type == 'post' )
  24.                 return false;
  25.  
  26.         $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
  27.  
  28.         if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
  29.                 if ( $is_blog_public || !is_multisite() ) {
  30.                         // Record this in activity streams
  31.                         $post_permalink   = get_permalink( $post_id );
  32.  
  33.                         if ( is_multisite() )
  34.                                 $activity_action  = sprintf( __( '%1$s uploaded a new object, %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>' );
  35.                         else
  36.                                 $activity_action  = sprintf( __( '%1$s uploaded a new object, %2$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
  37.  
  38.                         $activity_content = $post->post_content;
  39.  
  40.                         bp_blogs_record_activity( array(
  41.                                 'user_id'           => (int)$post->post_author,
  42.                                 'action'            => apply_filters( 'bp_blogs_activity_new_post_action',       $activity_action,  $post, $post_permalink ),
  43.                                 'content'           => apply_filters( 'bp_blogs_activity_new_post_content',      $activity_content, $post, $post_permalink ),
  44.                                 'primary_link'      => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink,   $post_id               ),
  45.                                 'type'              => 'new_blog_post',
  46.                                 'item_id'           => $blog_id,
  47.                                 'secondary_item_id' => $post_id,
  48.                                 'recorded_time'     => $post->post_modified_gmt
  49.                         ));
  50.                 }
  51.  
  52.                 // Update the blogs last activity
  53.                 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
  54.         } else {
  55.                 bp_blogs_remove_post( $post_id, $blog_id, $user_id );
  56.         }
  57.  
  58.         do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
  59. }
  60. add_action( 'save_post', 'media_record_post', 10, 2 );
clone this paste RAW Paste Data