Reply To: manual bp_activity_add within bp_activity_before_save
@modemlooper The only problem is i am updating the content with the Post ID and thumbnail of the post for activity prior to submitting it, is there any other way of doing is ?
add_action('bp_activity_before_save', 'rewards_activity_content', 3);
add_action('publish_rewards', 'groups_rewards_activity',4,1);
/* Filter for content for post type reward before saved to database */
function rewards_activity_content($activity){
global $post;
global $bp;
if ($post->post_type == 'rewards') {
$activity_id = (int) $activity->id;
$post_id = (int) $activity->secondary_item_id;
$user_id = (int) $activity->user_id;
$post_type = get_post_type( $post_id );
$thumbnail = get_the_post_thumbnail($post_id);
$post_permalink = get_permalink($post_id);
$title = get_the_title($post_id);
$activity_content = "<div class='post-id'>The post ID : {$post_id}</div>\n";
$activity_content .= "<div class='thumbnail'>{$thumbnail}</div>\n";
$activity->content = $activity_content;
$group_id = (int) BP_Groups_Group::group_exists($field_group[0]); //working :)
$bp->groups->current_group = groups_get_group( array( 'group_id' => $group_id ) );
$groups_activity_action = sprintf( __( '%1$s posted a reward %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $user_id ),'<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ,'<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
$groups_args = array(
'action' => apply_filters( 'groups_activity_new_update_action', $groups_activity_action ),
'content' => apply_filters( 'groups_activity_new_update_content', $activity_content ),
'component' => 'groups',
'type' => 'activity_update',
'type' => 'new_forum_post',
'primary_link' => $post_permalink,
'secondary_item_id' => $post_id,
'item_id' => $group_id,
'user_id' => $user_id,
); //all of groups_args array value is being populated
//do_action( 'bp_activity_add', $groups_args ); //not working
do_action( 'groups_rewards_activity', $groups_args );
}
return $activity;
}
function groups_rewards_activity($groups_args){
$id = bp_activity_add($groups_args);
return $id;
}