How can I add supplement php code/changes to my site without impacting WP core updates?

I have some code (shown below) to prohibit BuddyPress friendship activity on our site, and my theme developer recommended copying buddypress/bp-themes/bp-default/activity/activity-loop.php into my child theme, then making the changes within activity-loop.php. This I fully grasp.

What I don't understand, however, is if I copy the buddypress activity-loop.php into my child theme, does that mean that with each upgrade to the BuddyPress plugin, that I will have to copy activity-loop.php over the child theme's copy to ensure that I pick up any new code enhancements to BuddyPress core, then I must make the edit in the child theme copy as well?

Is there any way to make this code always active without tinkering with activity-loop.php?

<?php if ( 'friendship_created' != bp_get_activity_type() ) : ?>
		<?php locate_template( array( 'buddypress/activity/entry.php' ), true, false ); ?>
	<?php endif; ?>

Thank you for your help!


  • Vaughan

    Hi James,

    From looking at that snippet of code, you would need to copy the template again, but it's not often that file is actually updated, so you wouldn't need to keep doing it after every update, you only need to change it if the actual file has changed in the release.

    I've just been looking at Buddypress docs, and I can't see any other way of doing it with a custom filter.

    I did find this one, but it's 4 yrs old, so might not work anymore.

    // Remove (hide) various activities from streams.
    function my_hidden_activities($a, $activities) {
    //if admin we want to know
    //if (is_site_admin())
    //	return $activities;
    $nothanks = array(“new_blog_post”, “created_group”, “joined_group”, “new_member”, “friendship_created”, “activity_liked”);
    foreach ($activities->activities as $key => $activity) {
    if (in_array($activity->type, $nothanks, true)) {
    $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’, ‘my_hidden_activities’, 10, 2 );

    Though i'm unsure which activities you want removing from the feed, so i've just posted the code as is. As I say, this was from a post from 4yrs ago.

    Maybe your developer could look at it though? otherwise you'll need to go with editing the actual activity-loop file

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.