Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Post Type Comment Post Title in Activity

  • @bigkahunaburger

    Participant

    I’m trying to add the comment post title in the activity update:

            'bp_activity_new_comment'           => __( '%1$s commented on the <a href="%2$s">POST TITLE</a>', 'custom-textdomain' ),
            'bp_activity_new_comment_ms'        => __( '%1$s commented on the <a href="%2$s">POST TITLE</a>, on the site %3$s', 'custom-textdomain' ),

    I got it working for the post itself thanks to this topic:

    Custom Post Type Support for Activity

    And by using @imath gist as a guide:

    https://gist.github.com/imath/dce8426f686da1727f82

    However I can’t seem to figure it out for comments. Anyone have any ideas?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • @bigkahunaburger

    Participant

    Anyone have any ideas?

    @henrywright

    Moderator

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

    @bigkahunaburger

    Participant

    @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 );

    @henrywright

    Moderator

    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