This topic has 8 replies, 3 voices, and was last updated 6 years by Radu.

  • Author
  • #195687
     ThrewTheNevR
    Participant

    Is there a way to exclude either a user’s I’d or categories from showing up on the activity feed?

    These two functions don’t seem to work.

    COPY CODE
    function do_not_record_this_category( $post_id, $post ){
    
    /* this is the array that contains the category to exclude */
    
    $ids_to_exclude = array( 4,242,243,238,240,241 );
    
    if ( ‘publish’ != $post->post_status )
    
    return false;
    
    $categories = get_the_category( $post_id );
    
    $in = false;
    
     
    
    if( count($categories) > 0 ) {
    
    foreach ( $categories as $category ) {
    
    if( in_array( $category->cat_ID, $ids_to_exclude) )
    
    $in = true;
    
    }
    
    /* if the post has at least one excluded category, then we remove the BuddyPress hook that records an activity */
    
    if( $in )
    
    remove_action( ‘save_post’, ‘bp_blogs_record_post’, 10, 2 );
    
    }
    
    }
    
    add_action( ‘save_post’, ‘do_not_record_this_category’, 9, 2 );
    
    function exclude_category_slugs_from_activity_stream( $post_id, $post ){
    
    // add in any categories to exclue from activity stream, separated by commas, no spaces
    
    $category_slugs_to_exclude = "christian-news-network,christian-post,christianity-today,faith-in-the-news,google-christianity";
    
    // 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 );
    
    }
    
    // check post status to make sure it's published, exit if not
    
    if ( 'publish' != $post->post_status )
    
    return false;
    
    // 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;
    
    }
    
    }
    
     
    
    /* if the post has any excluded category, remove BuddyPress hook that records an activity */
    
    if( $in )
    
    remove_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
    
    }
    
    // add our function to save_post action hook
    
    add_action( 'save_post', 'exclude_category_slugs_from_activity_stream', 9, 2 );
    #195690
     Kieran_SQ
    Moderator

    Hi,

    You can rehash this code for hiding admin activities from the BuddyPress activity feed

    COPY CODE
    // Hide admin's activities from all activity feeds
    function bpfr_hide_admin_activity( $a, $activities ) {	
    	
    	// ... but allow admin to see his activities!
    	if ( is_super_admin() )	
    		return $activities;	
    	
    	foreach ( $activities->activities as $key => $activity ) {	
    		// ID's to exclude, separated by commas. ID 1 is always the superadmin
    		if ( $activity->user_id == 1  ) {			
    			
    			unset( $activities->activities[$key] );			
    			
    			$activities->activity_count = $activities->activity_count-1;			
    			$activities->total_activity_count = $activities->total_activity_count-1;			
    					$activities->pag_num = $activities->pag_num -1;				
    		}		
    	}		
    	// Renumber the array keys to account for missing items 	
    	$activities_new = array_values( $activities->activities );		
    	$activities->activities = $activities_new;	
    	
    	return $activities;
    	
    }
    add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );

    You can add a list of comma separated values for user ID’s on the line where you see the below

    if ( $activity->user_id == 1 ) {

    If your user ID was 42 it would be

    if ( $activity->user_id == 42 ) {

    If your user ID’s were 42 and 95 it would be

    if ( $activity->user_id == 42, 95 ) {

    The code should be added to your functions.php file via WP Admin > Appearance > Editor > KLEO Child > Functions.php

    Thanks,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #195692
     ThrewTheNevR
    Participant

    Thank you so much it works, it appears though that it wont show previous post when I select the load more. My admin account would have some test post from before showing.

    The user I blocked post from showing from the feed is from another account I use for auto posting content from rss feeds.

    However in the box that says show, I select updates and it will show my admin post, just unable to see it when it’s selected as everything.

    Seems as if the load more has broke.

    #195693
     Kieran_SQ
    Moderator

    Hi,

    I’m not sure why that would be, does it hide all previous posts that would appear in the feed before the read more link?

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #195695
     ThrewTheNevR
    Participant

    All post before the load more seems to work. I tested 3 accounts and posted on the feed.

    I kept posting updates using a different browser the selected the load more but nothing happened once I selected the load more button.

    #195696
     ThrewTheNevR
    Participant

    Once the content I posted reached the limit where u needed to select the load more.

    #195697
     Kieran_SQ
    Moderator

    Hi,

    I’ve looked into this and I cannot see why this isn’t working after the load more link. I’m going to refer this to one of our developers to see if they have another solution – or a potential fix for this code. They’ll be in touch as soon as they can, Monday to Friday, East European Time.

    Thank you for your patience,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #195698
     ThrewTheNevR
    Participant

    Thank you so much. I’m going do set this to resolved cause the initial question was answered.

    Il continue to see what’s causing it on my end and post back here if I figured it out.

    #195901
     Radu
    Moderator

    Hi,
    Ok then
    Cheers
    R

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 9 posts - 1 through 9 (of 9 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?