Skip to:
Content
Pages
Categories
Search
Top
Bottom

Filtering bp_get_activity_content_body, bp_get_activity_secondary_item_id


  • robsward
    Participant

    @robsward

    I’m trying to filter the activity content body, but bp_get_activity_secondary_item_id keeps returning 0. What I want is, when users comment on a post with a featured image, for that image to appear appended to the activity body. Here’s what I’m using:

    add_filter( 'bp_get_activity_content_body', 'cshp_add_thumbs_to_activity', 0, 1 );
    	function cshp_add_thumbs_to_activity( $bp_activity_filter_kses, $number ){
    
    		$post_id = bp_get_activity_secondary_item_id();
    
    		if( has_post_thumbnail( get_post( $post_id ) ) )
    			$attachment = wp_get_attachment_image( $post_id );
    
    		$new_content = $attachment ? $bp_activity_filter_kses . "<br />\n" . $attachment : $bp_activity_filter_kses;
    
    		return $new_content;
    	}

    Thanks

Viewing 1 replies (of 1 total)

  • shanebp
    Moderator

    @shanebp

    The filter call is:
    apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) );

    Your function expects 2 parameters. Your add_filter call states there is only one.

    And there is only one – an array.
    Read about that kind of filter https://codex.wordpress.org/Function_Reference/apply_filters_ref_array

    Try something like this:

    function cshp_add_thumbs_to_activity( $array ) { 
         $post_id = $array[1]->secondary_item_id;
        //etc
    
        $array[0] = // new content
    
        return $array; 
    
    }
    add_filter( 'bp_get_activity_content_body', 'cshp_add_thumbs_to_activity', 15, 1 );
Viewing 1 replies (of 1 total)
  • The topic ‘Filtering bp_get_activity_content_body, bp_get_activity_secondary_item_id’ is closed to new replies.
Skip to toolbar