Skip to:
Content
Pages
Categories
Search
Top
Bottom

Comments not showing on Activity Stream


  • benjiswart
    Participant

    @benjiswart

    Hey team,

    Having a problem getting any comments from a user on a custom post type to show up on the activity stream. Currently using the mylisting theme with buddypress integration. I have site tracking enabled and have double checked that I can see comments on the listing in the admin section.

    I also found this snippet which enabled a new Activity feed action when ever anyone creates a new listing but does not pick up on any comments:

    <?php
    function job_listing_activity_args() {
    	if ( ! bp_is_active( 'activity' ) ) {
    		return;
    	}
    	add_post_type_support( 'job_listing', 'buddypress-activity' );
    	bp_activity_set_post_type_tracking_args( 'job_listing', array(
    		'component_id'             => 'activity',
    		'action_id'                => 'new_job_listing',
            	'bp_activity_admin_filter' => __( 'Published a new Report', 'text-domain' ),
            	'bp_activity_front_filter' => __( 'Reports', 'text-domain' ),
            	'contexts'                 => array( 'activity', 'member' ),
            	'activity_comment'         => true,
            	'bp_activity_new_post'     => __( '%1$s posted a new Report: <a href="%2$s">[Job]</a> aproximately', 'text-domain' ),
            	'bp_activity_new_post_ms'  => __( '%1$s posted a new Report: <a href="%2$s">[Job]</a>, on the site %3$s', 'text-domain' ),
            	'position'                 => 100,
        	) );
    }
    add_action( 'init', 'job_listing_activity_args' );
    function job_listing_include_post_type_title( $action, $activity ) {
    	if ( empty( $activity->id ) ) {
    		return $action;
    	}
    	if ( 'new_job_listing' != $activity->type ) {
    		return $action;
    	}
    	preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
    	if ( empty( $matches[1][1] ) || '[Job]' != $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', 'job_listing_include_post_type_title', 10, 2 );

    Would greatly appreciate any help, I’m brand new to buddypress and so far have been really impressed with how powerful it can be, but just running into a bit of a brick wall here.

    Thanks in advance,

    B

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

  • benjiswart
    Participant

    @benjiswart

    So after a quick schooling in buddypress and how this all works I managed to piece together the following code that does exactly what I needed to do:

    <?php
    function job_listing_activity_args() {
    	if ( ! bp_is_active( 'activity' ) ) {
    		return;
    	}
    	add_post_type_support( 'job_listing', 'buddypress-activity' );
    
    	bp_activity_set_post_type_tracking_args( 'job_listing', array(
    		'component_id'             => 'activity',
    		'action_id'                => 'new_job_listing',
            	'bp_activity_admin_filter' => __( 'Published a new Report', 'text-domain' ),
            	'bp_activity_front_filter' => __( 'Reports', 'text-domain' ),
            	'contexts'                 => array( 'activity', 'member' ),
            	'activity_comment'         => true,
            	'bp_activity_new_post'     => __( '%1$s posted a new Report: <a href="%2$s">[Job]</a> aproximately', 'text-domain' ),
            	'bp_activity_new_post_ms'  => __( '%1$s posted a new Report: <a href="%2$s">[Job]</a>, on the site %3$s', 'text-domain' ),
            	'position'                 => 100,
            	'bp_activity_new_comment'  => __( '%1$s posted a new Follow up on: <a href="%2$s">[Job]</a> aproximately', 'custom-textdomain' ),
            	'bp_activity_comments_admin_filter' => __( 'Added Follow Up', 'custom-textdomain' ),
            	'bp_activity_comments_front_filter' => __( 'Follow Ups', 'custom-textdomain' ),
            	'bp_activity_new_comment_ms'        => __( '%1$s added follow up to this <a href="%2$s">Incident</a>, on the site %3$s', 'custom-textdomain' ),
            	'comment_action_id'                 => 'new_job_listing_comment',
        	) );
    }
    add_action( 'init', 'job_listing_activity_args' );
    function job_listing_include_post_type_title( $action, $activity ) {
    	if ( empty( $activity->id ) ) {
    		return $action;
    	}
    	if ( 'new_job_listing' != $activity->type ) {
    		return $action;
    	}
    	
    	
    	preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
    	if ( empty( $matches[1][1] ) || '[Job]' != $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', 'job_listing_include_post_type_title', 10, 2 );
    

    Hope this helps anyone else trying to figure out the same thing.

    Thanks @benjiswart for posting the solution you found!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar