The problem is that the activity stream stripes shortcodes like wp’s quicktag “more”.
Comment in bp-activity-filter.php:464 says
If the text returned by bp_create_excerpt() is different from the original text (ie it’s
been truncated), add the “Read More” link. Note that bp_create_excerpt() is stripping
shortcodes, so we have strip them from the $text before the comparison.
So if you’re used to write posts with excerpts, using the_excerpt instead of the_content would effectively bring the excerpt on the feed, but if the excert counts 1500 words, you will see them all !
If you use the_content, BP will add a read more link after 55 word by defaults, what ever the real amount of words in the post.
But with the above function active, SWA is no more in default configuration for this activity type.
So you’ll probably have better to use this function with the_content > full post and add a custom length for post activities.
Read here how to do that.
For the author name, you have to use get_userdata
.
This should work:
function 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 )
$title = isset( $post->post_title ) ? $post->post_title : '';
$content = apply_filters( 'the_content', $post->post_content ); // or post_excerpt
$author = get_userdata( $post->post_author )->user_nicename; // or display_name;
}
echo "<h2 align=center>" .$title. "</h2>";
echo '<h5 align=center>By '. $author .'</h5>';
echo $content;
}
add_filter( 'bp_get_activity_content_body', 'bp_full_posts_in_activity_feed', 10, 2 );
Thanks danbp for your help, it really point me in the right direction. I decided to use post_excerpt instead of the_content because that one proved quite problematic. The post excerpt worked wonderfully!! Here is the fixed code for anyone to use as reference (note that I also added feature image, post url and a read more button):
<?php
// Edits how blog posts appears on activity feed.
function bp_posts_in_activity_feed( $content, $activity ) {
if ( 'new_blog_post' == $activity->type ) {
$post = get_post( $activity->secondary_item_id );
if ( 'post' == $post->post_type )
$title = isset( $post->post_title ) ? $post->post_title : '';
$before_author = 'By';
$author = get_userdata( $post->post_author )->user_nicename;
$content = get_post( $post->ID )->post_excerpt;
$feature_img = wp_get_attachment_image( get_post_thumbnail_id($post->ID), $size ='medium' );
$post_url = get_permalink($post->ID);
$read_more = "<button type='button'>Read More</button>";
}
echo "<a href='$post_url'><h2 align=center>" .$title. "</h2></a>";
echo "<h5 align=center>" .$before_author . ' ' . $author. "</h5>";
echo "<a href='$post_url'><div align=center>" .$feature_img. "</div></a>";
echo "<p>" .$content. "</p>";
echo "<a href='$post_url'><h3 align=right>" .$read_more. "</h3></a>";
}
add_filter( 'bp_get_activity_content_body', 'bp_posts_in_activity_feed', 10, 2 );
I wanted to point out that on your reply above you suggested…
echo '<h5 align=center>By '. $author .'</h5>';
to show the author, but with that method the text “By” appeared above every single entry in the SWA. To fix that I just added the “By” text on a variable and then combined them on the echo. That way it only appears if there is a new blog post.