This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Roger Coathup

By: a guest on Aug 29th, 2010  |  syntax: None  |  size: 3.37 KB  |  views: 518  |  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. add_action("init","my_functions");
  2.  
  3. function my_functions(){
  4.         remove_action('save_post', 'bp_blogs_record_post');
  5.         add_action( 'save_post', 'my_blogs_record_post', 10, 2 );
  6. }      
  7.  
  8. function my_blogs_record_post( $post_id, $post, $user_id = false ) {
  9.         global $bp, $wpdb;
  10.  
  11.         $post_id = (int)$post_id;
  12.         $blog_id = (int)$wpdb->blogid;
  13.  
  14.         if ( !$user_id )
  15.                 $user_id = (int)$post->post_author;
  16.  
  17.         /* This is to stop infinite loops with Donncha's sitewide tags plugin */
  18.         if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
  19.                 return false;
  20.  
  21.         /* Don't record this if it's not a post */
  22.         if ( $post->post_type != 'post' )
  23.                 return false;
  24.  
  25.         if ( 'publish' == $post->post_status && '' == $post->post_password ) {
  26.                 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
  27.                         /* Record this in activity streams */
  28.                         $post_permalink = get_permalink( $post_id );
  29.  
  30.                         $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
  31.                         $activity_content = get_the_post_thumbnail( $post_id );
  32.  
  33.                         my_blogs_record_activity( array(
  34.                                 'user_id' => (int)$post->post_author,
  35.                                 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
  36.                                 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
  37.                                 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
  38.                                 'type' => 'new_blog_post',
  39.                                 'item_id' => $blog_id,
  40.                                 'secondary_item_id' => $post_id,
  41.                                 'recorded_time' => $post->post_date_gmt
  42.                         ));
  43.                 }
  44.         } else
  45.                 bp_blogs_remove_post( $post_id, $blog_id );
  46.  
  47.         bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
  48.  
  49.         do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
  50. }
  51.  
  52. function my_blogs_record_activity( $args = '' ) {
  53.         global $bp;
  54.  
  55.         if ( !function_exists( 'bp_activity_add' ) )
  56.                 return false;
  57.  
  58.         /* Because blog, comment, and blog post code execution happens before anything else
  59.            we may need to manually instantiate the activity component globals */
  60.         if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
  61.                 bp_activity_setup_globals();
  62.  
  63.         $defaults = array(
  64.                 'user_id' => $bp->loggedin_user->id,
  65.                 'action' => '',
  66.                 'content' => '',
  67.                 'primary_link' => '',
  68.                 'component' => $bp->blogs->id,
  69.                 'type' => false,
  70.                 'item_id' => false,
  71.                 'secondary_item_id' => false,
  72.                 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
  73.                 'hide_sitewide' => false
  74.         );
  75.  
  76.         $r = wp_parse_args( $args, $defaults );
  77.         extract( $r, EXTR_SKIP );
  78.  
  79.  
  80.         if ( !empty( $action ) )
  81.                 $action = apply_filters( 'bp_blogs_record_activity_action', $action );
  82.  
  83.         /* Check for an existing entry and update if one exists. */
  84.         $id = bp_activity_get_activity_id( array(
  85.                 'user_id' => $user_id,
  86.                 'component' => $component,
  87.                 'type' => $type,
  88.                 'item_id' => $item_id,
  89.                 'secondary_item_id' => $secondary_item_id
  90.         ) );
  91.  
  92.         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 ) );
  93. }
clone this paste RAW Paste Data