Buddypress: Edit activity when new blog post [closed]

I am trying to edit the activity on Buddypress (1.7 and running latest WordPress) for when a new blog post is created. By default it displays the excerpt and shows any attached images, it also strips any code (I think).

What I’m trying to achieve is to show the full blog post, including things like galleries. Doing some searches through the internet and the docs led me to:

bp_activity_content_body() and bp_create_excerpt

Help from the online community has led me to:

bp_activity_truncate_entry in bp-activity-filters.php

But I can’t seem to figure out how to work the filters (apply / add).
I tried the following (for bp_activity_truncate_entry), but no succes so far:

apply_filters ('bp_activity_excerpt_length', 500); 

And the following for bp_create_excerpt:

remove_filter( 'bp_create_excerpt', $length, $options ); 
function pnb_excerpt(){     $lenght = 500;  
$options = array(       'ending' => __( ' […]', 'buddypress' ),
 'exact'             => false,
  'html'              => false,
  'filter_shortcodes' => $filter_shortcodes_default); } 
add_filter( 'bp_create_excerpt', 'pnb_excerpt', $length, $options );

(Also tried apply instead of add) Neither of them seem to work. But again I am not sure how to work these filters. Can anybody point me in the right direction?

1 Answer
1

First, a note on how the filter functions work. If a developer has something that they want to filter/let others filter, then they apply any filters they/others have to it by calling apply_filters(). If you have a certain function that you want to filter something with, you add your function to that filter hook with add_filter(). Of course it only does any good to add a filter to a hook if the filters hooked to that hook are going to be applied somewhere. In this case, you want to look for somewhere that BuddyPress is applying filters to the post content, and add a function to that filter hook so that you can filter it the way you want.

Because you will be displaying the full post, you need to filter the content when it is being displayed. BuddyPress applies the 'bp_get_activity_content_body' filter to the activity content before displaying it. So you want to add a function to that filter that will return the entire post body:

function my_bp_full_posts_in_activity_feed( $content, $activity ) {

     if ( 'new_blog_post' == $activity->type ) {

        $post = get_post( $activity->secondary_item_id );

        if ( 'post' == $post->post_type )
             $content = apply_filters( 'the_content', $post->post_content );
     }

     return $content;
}
add_filter( 'bp_get_activity_content_body', 'my_bp_full_posts_in_activity_feed', 10, 2 );

Leave a Comment