Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Excluding One Blog’s Activities from bp_has_activities? (36 posts)

Started 6 months, 3 weeks ago by: justbishop

  • Profile picture of justbishop justbishop said 6 months, 3 weeks ago:

    I’m running BP on a multisite WP installation along with the sitewide tags plugin to pull blog posts from child sites into the main site, essentially making a copy of all child site posts on the main site as if they’d been written there originally. Since blog owners’ posts to their child site blogs also post to their main site profiles, this is causing double posts to the activity stream. You can see an example here (one post will say “on the site ________” and the double will say “on the site RiotCart.com”):

    http://www.riotcart.com/activity

    I’d like to eliminate the doubles that say “on the site RiotCart.com”, which is my main blog, ID# 1. I’m assuming this is done on activity/activity-loop.php, somehow using bp_has_activities(), but am fuzzy on where to go from there.

    I have read the doc for the activity loop, and I’ve gotten as far as the following (which I assume is way off, but it’s a starting point, at least). Where in my activity/activity-loop.php would it go? I’m assuming that this will exclude EVERYTHING about blog #1, so how do I specify to allow everything from ID# 1 EXCEPT blog posts?

    <?php if ( bp_has_activities( '!primary_id=1') ) : ?>

  • Profile picture of Nahum Nahum said 6 months, 3 weeks ago:

    @justbishop Have you tried http://buddypress.org/community/groups/buddypress-block-activity-stream-types/home/

    ..but it seems the page where it explains how to adjust for granular level blocking is not working…

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    Yes, but that blocks it from even being recorded to the DB, which is messing with my main page “featured” post functionality. I need blog posts from the main site to be hidden from everywhere, but not completely gone, KWIM? I figure that there MUST be something that can be done on the template level to just not display them.

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    Bump. I can find a few bucks to Paypal to someone willing to help me. I’m desperate.

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    Stuff I’ve tried that either seemed to do absolutely nothing, or make the activity stream stop loading altogether:

    <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) && primary_id( 'blog_id' ) != 1 ) ) : ?>

    <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) && primary_id() != ( 'blog-id=1' ) ) ) : ?>

    <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) && !new_blog_post( 'blog-id=1' ) ) ) : ?>

    There have been more, but I can’t remember all of them :(

  • Profile picture of Boone Gorges Boone Gorges said 6 months, 2 weeks ago:

    There is something that you can do, though it’ll mess up activity pagination (which, in the case of AJAX loading, means that the number of activity items loaded when you click “load more” will not always be the same number). It involves filtering bp_has_activities, looping through $activities_template->activities, and removing those items that are new blog posts from your blog.

    Here’s an example of the technique, used to remove self-replies: http://buddypress.org/community/groups/requests-feedback/forum/topic/couple-thoughts/?topic_page=2&num=15#post-112100

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    Thank you for the suggestion, I will take a look after I put my daughter down to nap! It’s more than I had to go on thus far :D

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    Tried adding this to my bp-custom.php, but it didn’t seem to do anything:

    http://pastebin.com/ACH039ZW

  • Profile picture of Boone Gorges Boone Gorges said 6 months, 2 weeks ago:

    What do you expect it to do? The point of that specific code, as discussed in the accompanying thread, is to remove individual activity items that correspond to comments on one’s own top-level activity items.

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    Oh, sorry, I thought that if I modified the parts referring to comments to specify blog posts instead, it would compare them to the blog id of ’1′ and not display those (if ( $parent->blog_id !== 1 ) ?). I’m kind of just taking shots in the dark on this and trying desperately to learn something in the process.

    To be honest, I’m not even sure I put that code in the correct file, much less what it’s supposed to do just by looking at it :/

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    Have been digging around in core…could something be done with this:

    if ( !empty( $bp->displayed_user->id ) )
    		$user_id = $bp->displayed_user->id;

    Possibly along the lines of:

    if ( !( $bp->displayed_blog->id ) )
    		$blog_id = $bp->displayed_blog->id;

    Not sure where/how to implement something like that, but figured it wouldn’t hurt to keep trying to figure it out.

  • Profile picture of Nahum Nahum said 6 months, 2 weeks ago:

    @justbishop I don’t understand what you mean by “it will not save to the DB”? That plugin will help you block one of the duplicates, meaning one of them *will* still be recorded.

    You have all your SWT’s post going into the main site, I would think to block main id 1 in your situation. This is what I found still works with the plugin i mentioned. Add to bp-custom.

    //if php is older then change $a to &$a
    function my_block_activity_type_blog_id_before_save_1( $type, $a ) {
    	global $bp;
    
    	if ( $a->id )
    		return $type;
    
            //key on the blog types (even for comments posted to that blog)
    	if ( $a->type == 'new_blog_post' || $a->type == 'new_blog_comment' ) {
    
    		//item_id is the blog_id in this context
                    //could add more blog_ids here as well or even parlay into switch_to_blog to block categories, etc
    		if ( $a->item_id == 1) {
    			$a->type = null;
    			return null;
    		}
    	}
    
    	return $type;
    }
    add_filter('bp_activity_type_before_save', 'my_block_activity_type_blog_id_before_save_1', 9999, 2);
  • Profile picture of Boone Gorges Boone Gorges said 6 months, 2 weeks ago:

    I’m a bit confused about this whole thing. BuddyPress is supposed to block SWT posts out of the box: http://buddypress.trac.wordpress.org/browser/trunk/bp-blogs/bp-blogs-functions.php#L163 If it’s not working, then there’s a bug in BP.

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    @boonebgorges, interesting! I don’t recall ever having this issue before, but I also can’t put my finger on the moment it started happening, either. I did check my copy of bp-blogs/bp-blogs-functions.php, and I DO have that piece of code, so I’m back at square 1 not knowing what the problem is. At least now I know that I’m trying to fix something that’s broken, rather than create a new behavior.

    @nahummadrid, yes, one is still recorded, but for some reason, the fact that the other one ISN’T recorded is messing with the “featured” posts area on my index page. The posts given the “featured” designation while the block activity types plugin is activated are not displayed in the featured area as they should be. In fact, it’s as if the page tries to load with one of the posts “featured” while the plugin was turned on, but can’t get past the heading of “featured” (i.e. none of the other page content, sidebar, or footer load). The plugin DOES fix my activity stream problem, but it creates a completely new one in this regard, so I gave up on it.

  • Profile picture of justbishop justbishop said 6 months, 2 weeks ago:

    I’ve done so many mods on my bp-custom.php and functions.php that I don’t even remember how half of them work. Could it be something in there?

    bp-custom.php: http://pastebin.com/9NBk5wdw

    functions.php: http://pastebin.com/dhxXpdA0