Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom activity new post content NOT broken after update the post


  • ggsalas
    Participant

    @ggsalas

    Hi, I have customized my activity post content (img1) with this code, and works great:

    add_filter( 'bp_blogs_activity_new_post_content', 'record_post_activity_content', 1, 3 );
    function record_post_activity_content($activity_content, $post, $post_permalink ){
    	if( $post->post_type == 'post' ) {
    		$activity_content =  '<a href="'. get_permalink( $post->ID ).'" class="activity-content-title" >'.get_post_field('post_title', $post->ID).'</a>' . get_the_post_thumbnail( $post->ID, 'articulo-lateral',  array( 'class' => 'articulo-lateral' )) . get_post_field('post_content', $post->ID);
    	} 
    	return $activity_content;
    }

    But If I update the post, the activity shows only the post content, without my customization (img2)

    Also if I set the post as “draft” and publish again, I get my activity customization working again (img1)

    How I can resolve this? Is a bug?


    Img1: http://i.imgur.com/5s9os2q.png
    Img2: http://i.imgur.com/FlsKxz5.png

    Best regards,
    Gabriel

Viewing 5 replies - 1 through 5 (of 5 total)

  • ggsalas
    Participant

    @ggsalas

    Did anyone have this problem?


    shanebp
    Moderator

    @shanebp

    You are only filtering for new posts.

    Take a look at buddypress\bp-blogs\bp-blogs-functions.php

    Look for the filter hook you are using.
    Look for this filter hook too: bp_blogs_record_activity_content


    ggsalas
    Participant

    @ggsalas

    Hi @shanebp,
    Thanks for your help. I have tried many hours and “record_post_activity_content_update” make me crazy.

    The code I use is this:

    add_filter( 'bp_blogs_record_activity_content', 'record_post_activity_content_update');
    function record_post_activity_content_update($content){
    	return 		'<a href="' . get_permalink( $post->ID ) . '" class="activity-content-title" >' 
    				. get_the_post_thumbnail( $post->ID, 'articulo-lateral') 
    				. get_post_field('post_title', $post->ID) . '</a>' 
    				. get_post_field('post_content', $post->ID);
    }

    With this code:
    1. if I create a new post, the activity shows the image, title, but not the post content.
    2. If I update the post, the activity shows all, but old content (not updated)

    I have made a video with the problem: I hope you can help me: http://screencast-o-matic.com/watch/c26IYneixI

    Best regards,
    Gabriel


    shanebp
    Moderator

    @shanebp

    I’m not sure exactly what your issue is, but your function accepts only one parameter.
    But 3 are passed.
    Yours:
    function record_post_activity_content_update($content){

    The filter_hook:
    $activity->content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $post_content ), $post_content, (array) $activity );

    Notice that post_id is not in there.
    It might be in $activity.

    So try something like this:

    function record_post_activity_content_update( $excerpt, $post_content, $activity ) {
       $post_id = $activity->secondary_item_id;
       // or
       $post_id = $activity->item_id;
       // then build your string using $post_id rather than $post->ID
    

    ggsalas
    Participant

    @ggsalas

    Hi @shanebp,

    I can solve the problem!

    This is the code thats work perfect:

    add_filter( 'bp_blogs_record_activity_content', 'record_post_activity_content_update');
    function record_post_activity_content_update( $excerpt, $post_content, $activity ) {
    	global $post;
    	if( $post->post_type == 'post' ) {
    		$post_content= 	'<a href="' . get_permalink( $post->ID ) . '" class="activity-content-title" >' 
    						. get_the_post_thumbnail( $post->ID, 'articulo-lateral') 
    						. get_post_field('post_title', $post->ID) . '</a>' 
    						.get_post_field('post_content', $post->ID);
    	}
    	return $post_content;
    }
    

    Example:
    1- New post activity: https://i.imgur.com/75Qf5WH.png
    2- Edited post activity: https://i.imgur.com/0dWME4m.png

    The only problem that I find is not caused by this: Activity comments closed for the edited posts: https://buddypress.org/support/topic/activity-comments-closed-for-the-edited-posts/

    Thanks and best regards,
    Gabriel

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom activity new post content NOT broken after update the post’ is closed to new replies.
Skip to toolbar