Hi Shawn
Here we go.
The basics of activity:-
BuddyPress provides a few functions to manipulate the items in activity stream. The main functions of our interest are
bp_activity_add($arg);//to add/update an item to activity
bp_activity_new_comment( $args);//add a child activity to existing activity
bp_activity_delete($arg);//generic function for deleting activity items
There are some more generalized functions for deleting activity by item/component etc.
Now Our Item of interest here is
bp_activity_add($arg);
Where $arg can be an array or query string consisting of the following(taken from the bp-activity.php)
'id' => false, // Pass an existing activity ID to update an existing entry.
'action' => '', // The activity action - e.g. "Jon Doe posted an update"
'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
'type' => false, // The activity type e.g. activity_update, profile_updated
'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user.
'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
'recorded_time' => gmdate( "Y-m-d H:i:s" ), // The GMT time that this activity was recorded
'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
You will mostly find yourself using the "action","content","user_id","component","item_id" and "type"
here "action" is what you see i the activity stream like "xyz posted an update to alpha beta", and "type" is the actual thing you will use to separate your activity from other activity. For example, I use the type="new_media_update" for media comments.
Ok, That's enough for you(And I guess, you might already be knowing all these stuffs:) )
Now coming to the current situation, since bp does not want to record activity for publishing papges, you see the line
if ( $post->post_type != 'post' )
return false;
I hope, It will be changed in bp 1.3 since that's going to be fully featured for wp 3.0
For now, we will add our own actions to handle posting to activity stream than editing the core files.
So, let us decide what we want.
Since you want to show the custom video in the stream, let us build our code
function bp_record_custom_post( $post_id, $post, $user_id = false ) {
global $bp, $wpdb;
//do not record post/page just record sermons or other custom post types
$custom_post_types=array("sermons"=>__("Sermons"),"othertype"=>__("label for other type"),"some_other_type"=>"Label for some other type");//please edit it to all the custom post ttypes you want
$post_id = (int)$post_id;
$blog_id = (int)$wpdb->blogid;
if ( !$user_id )
$user_id = (int)$post->post_author;
/* This is to stop infinite loops with Donncha's sitewide tags plugin */
if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
return false;
/* Don't record this if it's not a post */
if ( !array_key_exists($post->post_type,$custom_post_types ))//do not record if it is not the custom post type we want to record
return false;
if ( 'publish' == $post->post_status && '' == $post->post_password ) {
//you may remove the line below
bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
/* Record this in activity streams */
$post_permalink = get_permalink( $post_id );
//what you want to say in the activity strea, like xyz posted to the sermon
$activity_action = sprintf( __( '%s wrote a new %s: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ),$custom_post_types[$post->post_type], '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
//what content you want to show, I assume you want video,so I am calling your function for video
$video = shawn_embed('width=200&height=150');//you will need to specify post id here in the function to fetch the video link from custom field
if (!empty($video)){
$activity_content ="<div class=\"video\"". $GLOBALS['single_align']."\">".$video."</div>";
}
else
$activity_content = $post->post_content;
bp_record_custom_post_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' => $blog_id,
'secondary_item_id' => $post_id,
'recorded_time' => $post->post_date_gmt
));
}
} else
bp_blogs_remove_post( $post_id, $blog_id );
bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );//remove this if you don't want blog to be updated in the blogs dir
do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );//you may want to remove this
}
add_action( 'save_post', 'bp_record_custom_post', 20, 2 );//hook to post save
/*since we do not want bp tp create excerpt of our content, let us create our own recording function*/
function bp_record_custom_post_activity( $args = '' ) {
global $bp;
if ( !function_exists( 'bp_activity_add' ) )
return false;
/* Because blog, comment, and blog post code execution happens before anything else
we may need to manually instantiate the activity component globals */
if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
bp_activity_setup_globals();
$defaults = array(
'user_id' => $bp->loggedin_user->id,
'action' => '',
'content' => '',
'primary_link' => '',
'component' => $bp->blogs->id,
'type' => false,
'item_id' => false,
'secondary_item_id' => false,
'recorded_time' => gmdate( "Y-m-d H:i:s" ),
'hide_sitewide' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
if ( !empty( $content ) )
$content = apply_filters( 'bp_blogs_record_custom_post_activity_content', $content );
/* Check for an existing entry and update if one exists. */
$id = bp_activity_get_activity_id( array(
'user_id' => $user_id,
'component' => $component,
'type' => $type,
'item_id' => $item_id,
'secondary_item_id' => $secondary_item_id
) );
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 ) );
}
This will do what you want to do, just make sure you have edited the first function "
bp_record_custom_post properly
I hope it helps a little bit, though I will be creating a post(as per your advise) and posting it back later this week :)
Let me know if you find difficulties
P.s: I may be away for couple of hours now.