Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Post Type Comment Post Title in Activity

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

  • bigkahunaburger
    Participant

    @bigkahunaburger

    Anyone have any ideas?


    Henry Wright
    Moderator

    @henrywright

    I’m pretty sure you can use the bp_blogs_format_activity_action_new_blog_comment filter to do that.


    bigkahunaburger
    Participant

    @bigkahunaburger

    @henrywright

    Thanks for your reply. Can you help me out with a few more details? This is what I’m using to get the title of the new post in the activity feed. It works fine for the new posts but doesn’t seem to work for comments:

    function dailies_comments_include_post_type_title( $action, $activity ) {
    	if ( empty( $activity->id ) ) {
    		return $action;
    	}
    
    	if ( 'new_dailies_comment' != $activity->type ) {
    		return $action;
    	}
    
    	preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
    
    	if ( empty( $matches[1][1] ) || '[Title]' != $matches[1][1] ) {
    		return $action;
    	}
    
    	$post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
    
    	if ( empty( $post_type_title ) ) {
    
    		switch_to_blog( $activity->item_id );
    
    		$post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
    
    		// We have a title save it in activity meta to avoid switching blogs too much
    		if ( ! empty( $post_type_title ) ) {
    			bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
    		}
    
    		restore_current_blog();
    	}
    
    	return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
    }
    add_filter( 'bp_activity_custom_post_type_post_action', 'dailies_comments_include_post_type_title', 10, 2 );

    Henry Wright
    Moderator

    @henrywright

    Here’s an example of how to use the filter:

    add_filter( 'bp_blogs_format_activity_action_new_blog_comment', function( $action, $activity ) {
        // Do what you wish with $activity here.
    
        $action = __( 'Your text here.', 'text-domain' );
        return $action;
    } );
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar