Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

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

  • MatrixMedia
    Participant

    @matrixmedia

    to exclude some categories I have tried this:

    function exclude_category_slugs_from_activity_stream( $new_status, $old_status, $post ) {
    
    	// Only record published posts
    	if ( 'publish' !== $new_status ) {
    		return;
    	}
    
    	// Don't record edits (publish -> publish)
    	if ( 'publish' === $old_status ) {
    		return;
    	}
    
    	// add in any categories to exclue from activity stream, separated by commas, no spaces
    	$category_slugs_to_exclude = "news,new,News,service,Service";
    
    	// create the array that contains the category ids to exclude
    	$ids_to_exclude = array();
    	// create new array by splitting category slugs by comma
    	$category_slug_array = split( ",", $category_slugs_to_exclude );
    	// iterate over category_slug_array
    	foreach ( $category_slug_array as $category ) {
    		// get the category id based on the slug
    		$idObj = get_category_by_slug( $category );
    		$id = $idObj->term_id;
    		// push the category id onto the exclude array
    		array_push ( $ids_to_exclude, $id );
    	}
    
    	// get the post's categories
    	$categories = get_the_category( $post->ID );
    	$in = false;
    
    	// check if the post has any categories, do nothing if not
    	if( count($categories) > 0 ) {
    		// iterate over categories
    		foreach ( $categories as $category ) {
    			// check if any excluded category exists within post's categories
    			if( in_array( $category->cat_ID, $ids_to_exclude) )
    				$in = true;
    		}
    	}
    
    	// Don't record posts from filtered categories
    	if( $in )
    		return;
    
    	return bp_activity_post_type_publish( $post->ID, $post );
    }
    
    add_action( 'bp_init', 'bp_blogs_catch_filtered_published_post' );
    
    function bp_blogs_catch_filtered_published_post() {
    	if ( bp_is_active( 'blogs' ) ) {
    		remove_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10 );
    		add_action( 'transition_post_status', 'exclude_category_slugs_from_activity_stream', 10, 3 );
    	}
    }

    I found here: https://premium.wpmudev.org/forums/topic/exclude-auto-blog-posts-from-buddypress-activity-stream

    of course I changed the deprecated functions:
    bp_blogs_record_post -> bp_activity_post_type_publish
    bp_blogs_catch_transition_post_status -> bp_activity_catch_transition_post_type_status

    but nothing … not working … HELP!!!


    MatrixMedia
    Participant

    @matrixmedia

    sorry, I have not explained well, the second point, I Repeat:

    I also tried to customize the Post Types default ‘post’, following this guide: https://codex.buddypress.org/plugindev/post-types-activities/

    this is my function:

    add_post_type_support( 'post', 'buddypress-activity' );
    function customize_page_tracking_args() {
        // Check if the Activity component is active before using it.
        if ( ! bp_is_active( 'activity' ) ) {
            return;
        }
        bp_activity_set_post_type_tracking_args( 'post', array(
            'component_id'             => buddypress()->blogs->id,
            'action_id'                => 'new_blog_post', // or 'new_post'
            'bp_activity_admin_filter' => __( 'Published a new post', 'emt-buddypress' ),
            'bp_activity_front_filter' => __( 'Posts', 'emt-buddypress' ),
            'contexts'                 => array( 'activity', 'member' ),
            'activity_comment'         => true,
            'bp_activity_new_post'     => __( '%1$s shared a new <a href="%2$s">post</a>', 'emt-textbuddypress' ),
            'bp_activity_new_post_ms'  => __( '%1$s sahred a new <a href="%2$s">post</a>, on the site %3$s', 'emt-textbuddypress' ),
            'position'                 => 100,
        ) );
    }
    add_action( 'bp_init', 'customize_page_tracking_args' );

    but when I publish a post on activity stream, is not displayed. If I remove the function or use a new custom_post_type, in this function, it works.

Viewing 2 replies - 1 through 2 (of 2 total)
Skip to toolbar