Remove User ID from Blog Related Site Wide Activity
I’m trying to get all activity performed by Admin User ID (1) removed from the site wide activities. If ALL activity is complicated, at least I need to remove the activity related to blogging (creating new blog, wrote a new post).
Reason is because I use a syndication tool to retrieve posts from many sources – which are assigned to admin. Secondly, the volume of this aggregation is fairly high, it would overwhelm site wide activity.
Thanks in advance
Alternatively, since I pull these feeds into a seperate blog – what would also solve my issue is if I could exclude blog related activity from blog_ID=2.
Does anyone know how?
Howdy. There’s a function in bp-blogs.php called bp_blogs_record_activity(). It’s triggered by 3 actions in bp. If you look at it, it does some setup stuff and then calls bp’s basic ‘record this stuff as an activity function’ bp_record_activity().
The three actions that trigger bp_blogs_record_activity() are listed underneath the fn.
remove_action( 'bp_blogs_new_blog_post', 'bp_blogs_record_activity' );
add_action('bp_blogs_new_blog_post', 'NOADMIN_bp_blogs_record_activity' );
Copy the function bp_blogs_record_activity() to NOADMIN_bp_blogs_record_activity(), filter yourself out inside the NOADMIN version and allow all other normal activity to occur.
I’ve got a little utility plugin that is collecting things like this for my mods. No core hacking since Andy has all sorts of hooks builtin for us to use. Like this case.
We are posting around each other. Similar fix.
Burt -awesome. Thanks for your quick response.
Now onto the next problem – while I understand and sort of follow the process, I have no idea how to code this. Any chance you can be a bit more specific (yeah, even *more* specific – I’m an absolute beginner) with a code sample so I can do this?
I was taking a look at this again to give you a sample and it turns out I was looking at some code from r805 or so. Don’t know why it’s hanging around on my dev server. Never mind what I said. That function bp_blogs_record_activity() doesn’t have any hooks we can use.
It looks like the only fn we can hook is bp_blogs_record_post() which calls the record activity fn. That is in bp-blogs.php if you want to take a look at it.
I gotta scrape my dev server clean and re-install from the latest trunk. Probably more weirdness hanging around. The basic concept of modifying bp’s behavior without modifying the core is to copy a function, change it to do what you want and hook up your new function in place of the old one.
The mod to make would occur right below or above line #377. Detecting donncha’s site wide tags plugin and not doing anything with that post on that blog. Same idea for you on blog id 2. That line # is from r832.
Let me get back to you with some suggested sample code after I clean up my dev server.
Burt – thanks again. This is sort of the last piece before I’m opening my site for beta users – so I’m curious to see if this can be done.
jvinch, ok. I’m not sure what else to tell you about this except create a new file, name it anything you want .php, drop it in /mu-plugins. The plugin should contain the function bp_blogs_record_post() as it is in bp-blogs.php.
1) rename the function something else: jvinch_bp_blogs_record_post()
2) add the filter code that skips recording blog posts for blog id 2
3) unhook the current bp_blogs_record_post() and hook up your modified function instead
4) test it out
#2 above would be somthing like:
if ($blog == 2) return;
#3 would be:
remove_action( 'publish_post', 'bp_blogs_record_post' );
add_action( 'publish_post', 'jvinch_bp_blogs_record_post' );
You are doing all this on a dev server for testing of course.
Message? To you? I got a friend request from you on testbp.org. Just accepted it. That it?
I see. Ya brain fart on my part. $blog should be $blog_id. Sorry. Also I would put that new line above the $post = get_post($post_id); call. Why make a db call if we aren’t going to do anything if it’s on blog 2?
Of course you could look at the post and see if it’s from ‘admin’ and ignore that. In that case some sort of filter after get_post() would be appropriate.
I gotta slow down and stop doing 10 things at once. The details like $blog/$blog_id sometimes get lost in the shuffle. Programming is all about details. It isn’t good enough to be ‘close’.
OK- here’s where I am. I copied the fn and added the add/replace lines at the bottom but I can’t get the part where it filters blog_ID user right. The code sample I sent you doesn’t work yet.
I’m in wayyyyy over my head!
The suggested mod filters all posts that go to blog id 2 and trigger ‘publish_post’. If the plugin that you are using doesn’t trigger the action ‘publish_post’ it might not work.
If the sitewide activity is still picking it up then you have to figure out how.
Not sure if you found an elegant answer, but you could hack the source code. I know, not the preferred method but if you track it so you add it in at the next update.
This will get the job done to remove all user_id is 1 activity from the site wide activity.
In bp-activity/bp-activity-classes.php in the function get_sitewide_activity around line 261:
$activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_sitewide'] . " ORDER BY date_recorded DESC $limit_sql" ) );
$activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_sitewide'] . " WHERE user_id != 1 ORDER BY date_recorded DESC $limit_sql" ) );
Now user 1’s activity will not show on site wide activity.
Will this same solution exclude User 1 from the Recent Blog Posts widget? Perhaps in bp-blogs-classes?
Hi, I have the same problem. I want to exclude admin posts from the recent post widget and all other activity widgets. Tried the suggested solutions and altered bp-activity-classes.php but no avail. Has anybody found a solution to this? Many thanks in advance!
This is not exactly the same problem as in topic, but I’ll post this here.
I’m using Wp 2.7, bp rc-1 and ds_private_blog plugin.
Sitewide activity records every new post and comment even from the blogs set to be fully private (admin only). How can I exclude those?
- The topic ‘Remove User ID from Blog Related Site Wide Activity’ is closed to new replies.