Skip to:
Content
Pages
Categories
Search
Top
Bottom

Multiple CPT in activity stream?


  • wzshop
    Participant

    @wzshop

    Hi,
    I have this code below for one custom post type to be shown in the activity feed. All works fine, but how can i use this also for an extra CTP?

    I tried adding an extra line add_post_type_support( 'listing_2', 'buddypress-activity' );
    But that is not working. Also i rather have different tracking_args for the different custom post types.

    Anyone? Thanks!

    <?php
    //Listing activity support
    function customize_page_tracking_args_listing() {
        // Check if the Activity component is active before using it.
        if ( ! bp_is_active( 'activity' ) ) {
            return;
        }
     
        // Don't forget to add the 'buddypress-activity' support!
        add_post_type_support( 'listing', 'buddypress-activity' );
     
        /**
         * Also don't forget to allow comments from the WordPress Edit Page screen
         * see this screencap https://cldup.com/nsl4TxBV_j.png
         */
     
        bp_activity_set_post_type_tracking_args( 'listing', array(
            'action_id'                         => 'new_listing',
            'bp_activity_admin_filter'          => __( 'Vermelding toegevoegd', 'custom-textdomain' ),
            'bp_activity_front_filter'          => __( 'Vermelding', 'custom-textdomain' ),
            'bp_activity_new_post'              => __( '%1$s heeft een nieuwe vermelding genaamd <a href="%2$s">[vermelding]</a> toegevoegd', 'custom-textdomain' ),
                    'contexts'                          => array( 'activity', 'member' ),
            'comment_action_id'                 => 'new_listing_comment',
            'bp_activity_comments_admin_filter' => __( 'Reageerde op vermelding', 'custom-textdomain' ),
            'bp_activity_comments_front_filter' => __( 'Reacties op vermelding', 'custom-textdomain' ),
            'bp_activity_new_comment'           => __( '%1$s reageerde op <a href="%2$s">een vermelding</a>', 'custom-textdomain' ),
            'position'                          => 100,
        ) );
    }
    add_action( 'bp_init', 'customize_page_tracking_args_listing', 1000 );
    function new_listing_include_post_type_title( $action, $activity ) {
    	if ( empty( $activity->id ) ) {
    		return $action;
    	}
    
    	if ( 'new_listing' != $activity->type ) {
    		return $action;
    	}
    
    	preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
    
    	if ( empty( $matches[1][1] ) || '[vermelding]' != $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', 'new_listing_include_post_type_title', 10, 2 );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar