Only Show Posts and Forum Topics in Activity Feed

Hi there,

I was wondering if someone could help me putting together the right code snippet for a child’s theme functions.php, to make sure the Site-wide activity feed only shows these updates:

New Posts (Multisite)

New Forum Topics (BBPress)

New Group Creation (BuddyPress)

I saw the Ash putting something together on this topic:

https://premium.wpmudev.org/forums/topic/customizing-the-buddypress-activity-loop

Just need a snippet like that. Any help would be very much appreciated.

Thanks in advance!

Cheers,

Ronald

  • Ash
    • WordPress Hacker

    Hi there

    Please try the following code to create activity when a new post is created:

    add_action( 'save_post', function( $post_id, $post, $update ) {
    if( $post->post_status == 'publish' && $post->post_type == 'post' )
    {
    $author = new WP_User( $post->post_author );
    $args = array(
    'action' => bp_core_get_userlink( $author->ID ) . '</a> have created a post - <a href="' . get_permalink( $post_id ) . '">' . $post->post_title . '</a>',
    'component' => 'activity',
    'type' => 'New Blog Post',
    'user_id' => $author->ID
    );

    $activity_id = bp_activity_add( $args );
    }
    }, 10, 3 );

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name ‘mu-plugins’. If there is no folder in that name, then create a folder, name it ‘mu-plugins’, create a file inside that, give any name you like and paste the code in there. You don’t need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    For group creation and new topic creation, it’s automatically creates sitewide activity. No need to add any extra code for that.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers

    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.