Amazing home presentations Creating and building brands

Blog

BuddyPress Snippet: Adding CPTs in the activity stream

Do you want add Custom Post Types in the activity stream? Paste this snippet on your theme function.php

add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_custom_post_types' );
function activity_publish_custom_post_types() {
    $cp = array('dreams', 'offers'); //array with post-types slugs
    return $cp;
}

add_filter( 'bp_blogs_activity_new_post_action', 'my_activity_content',  2, 10 );
function my_activity_content($activity_content, $post, $post_permalink){
     
    $activity_content = sprintf( __( '%s submitted a new '.$cp.': %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    $activity_content .= bp_create_excerpt( $post->post_content, 25 );
    return $activity_content;
}

No Comments

Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.