google-code-export / wordpress-custom-content-type-manager

Automatically exported from code.google.com/p/wordpress-custom-content-type-manager
2 stars 1 forks source link

Allow CCTM posts to write to the Buddy Press Activity Stream #490

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Haven't been able to find if this is already possible, so please excuse me if 
you've already been asked this.

It would be great to have a control that, when a new post is created, would 
insert the report of the fact into BuddyPress' Activity Stream.

For example, if I have a custom post type of "Documents" then, when I publish a 
new post, into the Activity Stream would be inserted "Site Admin has published 
a new Document". 

Also, it would be fab if the updating of a post could be inserted too, perhaps 
with a checkbox on the post editing screen to request such (to stop the 
Activity Stream from being flooded with loads of updates if you constantly 
click Publish and then edit it some more!)

Original issue reported on code.google.com by i...@brightongmc.org on 13 May 2013 at 4:31

GoogleCodeExporter commented 9 years ago

Original comment by ever...@fireproofsocks.com on 13 May 2013 at 4:35

GoogleCodeExporter commented 9 years ago
I think this is something that individual site-owners can do: 
http://blog.slyspyder.com/2010/08/15/integrate-simplepress-forum-into-the-buddyp
ress-activity-stream/

But the documentation looks really sloppy... and so does the code.   Do you 
have an example of adding something like a post to a stream?

I don't have Buddypress installed so I don't think this one is going to get my 
attention any time soon unfortunately.

Original comment by ever...@fireproofsocks.com on 29 Jul 2013 at 8:02

GoogleCodeExporter commented 9 years ago
I've achieved this myself. The code is relatively simple. 

The 1st filter tells BP what events to log and the 2nd one adds the wording 
that is displayed in the activity stream

// add custom post types to the activity stream
function activity_publish_custom_post_types($cpts) {
    $cpts[] = 'documents';
    return $cpts;
}
add_filter ( 'bp_blogs_record_post_post_types', 
'activity_publish_custom_post_types' );

//Change wording in Activity Stream and use post_type instead of just of 'post'
add_filter( 'bp_blogs_activity_new_post_action', 'my_activity_content',  2, 10 
);

function my_activity_content($activity_content, $post, $post_permalink){
    $myPostType = $post->post_type;
    $fullPermalink = $post->guid;
    $activity_content = sprintf( __( '%s added a new '.$myPostType.': %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $fullPermalink . '">' . $post->post_title . '</a>' );
    $activity_content .= " " . bp_create_excerpt( $post->post_content, 25 );

    return $activity_content;
}

Original comment by pe...@twobytwo.co.uk on 30 May 2014 at 4:18

GoogleCodeExporter commented 9 years ago
Thanks for sharing your solution!

Original comment by ever...@fireproofsocks.com on 30 May 2014 at 4:20