Skip to:
Content
Pages
Categories
Search
Top
Bottom

Excluding One Blog’s Activities from bp_has_activities?


  • justbishop
    Member

    @justbishop

    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?

Viewing 25 replies - 1 through 25 (of 35 total)

  • Nahum
    Participant

    @nahummadrid

    @justbishop Have you tried https://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…


    justbishop
    Member

    @justbishop

    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.


    justbishop
    Member

    @justbishop

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


    justbishop
    Member

    @justbishop

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

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


    Boone Gorges
    Keymaster

    @boonebgorges

    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: https://buddypress.org/community/groups/requests-feedback/forum/topic/couple-thoughts/?topic_page=2&num=15#post-112100


    justbishop
    Member

    @justbishop

    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


    justbishop
    Member

    @justbishop

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

    http://pastebin.com/ACH039ZW


    Boone Gorges
    Keymaster

    @boonebgorges

    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.


    justbishop
    Member

    @justbishop

    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 :/


    justbishop
    Member

    @justbishop

    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.


    Nahum
    Participant

    @nahummadrid

    @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);
    `


    Boone Gorges
    Keymaster

    @boonebgorges

    I’m a bit confused about this whole thing. BuddyPress is supposed to block SWT posts out of the box: https://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.


    justbishop
    Member

    @justbishop

    @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.


    justbishop
    Member

    @justbishop

    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


    Boone Gorges
    Keymaster

    @boonebgorges

    It’s possible that SWT was updated so that the settings key is different. Can you check your database to see if you have an item in wp_options with the name ‘tags_blog_id’?


    justbishop
    Member

    @justbishop

    On searching the db, I do not seem to have that.


    Boone Gorges
    Keymaster

    @boonebgorges

    Could you open a ticket on trac.buddypress.org pointing to the line that I linked above? I’ll have to install SWT and see how they changed it.


    justbishop
    Member

    @justbishop

    Not sure if I did it correctly, but I tried!


    justbishop
    Member

    @justbishop

    Is this something that I can help with? I have pretty meager knowledge of PHP, but am always up for learning through doing (though I generally need hand holding). If not, what is the next step in the process? Am I waiting for a patch or update to BP and/or the SWT plugin?


    Boone Gorges
    Keymaster

    @boonebgorges

    Sorry, I have a million things on my plate.

    Look through SWT and see how they are storing the tags blog id. Then change BP so that it looks for that piece of sitemeta.


    justbishop
    Member

    @justbishop

    OK, just had a look at the file, and am seriously overwhelmed. I just do not know enough about PHP to figure out what portion of the code I even need to be focusing on.

    Is there anyone else willing to help guide me a bit more? This is a serious issue for my site, and I really can’t move forward without fixing it.


    Boone Gorges
    Keymaster

    @boonebgorges

    Search the SWT for update_sitemeta or get_sitemeta. That will give you a start. I will take a look myself when I get a chance.


    Boone Gorges
    Keymaster

    @boonebgorges

    Oops – make that update_site_option and get_site_option. Might be worth pinging @wpmuguru about this as well.


    justbishop
    Member

    @justbishop

    Thanks, I really do appreciate you taking the time. I wish I could do more of this type of thing for myself, but I’m afraid that I don’t have the luxury of just sitting and straight learning PHP.

    Searched the file for both get_sitemeta and update_sitemeta and got no hits. Will your mention of @wpmuguru send them a notification? Because I don’t think BP is letting me post anything to anyone’s wall right now.


    justbishop
    Member

    @justbishop

    STOP THE PRESSES! I decided to give the block activity stream types plugin another try in my desperation, and it might actually be working WITHOUT messing with the custom post query on my index page that pulls featured posts for display! Still have more testing to do, but all I did was remove the `do_action( ‘bp_before_blog_post’ );` and `do_action( ‘bp_after_blog_post’ );` from around my featured post query, and voila, it loaded a post I marked as featured AFTER activating the block type plugin, and didn’t create a double entry about the editing of the post in my activity stream!

    I know it’s not a REAL fix, but if it gets the job done, I’ll take it…

Viewing 25 replies - 1 through 25 (of 35 total)
  • The topic ‘Excluding One Blog’s Activities from bp_has_activities?’ is closed to new replies.
Skip to toolbar