Skip to:

How to attach custom activities to groups?

  • I have a custom post type, my_cpt.
    I can make creations of posts of type my_cpt visible in activity feeds with this (in bp-custom.php):

    add_post_type_support( 'my_cpt', 'buddypress-activity' );

    This does not make this type of activity available when creating a new activity. How can I make this happen, in the same way that I can select a group when creating a new activity?
    Is it then possible to require more fields when adding this activity?

    If I have to write my own front-end submission form for an activity of the type my_cpt, how do I attach this user’s activity to a particular group?

Viewing 3 replies - 1 through 3 (of 3 total)
  • A first step could be to add a custom tab on the groups pages. This works for that:

        function setup_group_nav(){
        	global $bp;	
        	/* Add some group subnav items */
        	$user_access = false;
        	$group_link = '';
        	if( bp_is_active('groups') && !empty($bp->groups->current_group) ){
        		$group_link = $bp->root_domain . '/' . bp_get_groups_root_slug() . '/' . $bp->groups->current_group->slug . '/';
        		$user_access = $bp->groups->current_group->user_has_access;
        		bp_core_new_subnav_item( array( 
        			'name' => __( 'Custom', 'custom'),
        			'slug' => 'custom', 
        			'parent_url' => $group_link, 
        			'parent_slug' => $bp->groups->current_group->slug,
        			'screen_function' => 'bp_group_custom', 
        			'position' => 50, 
        			'user_has_access' => $user_access, 
        			'item_css_id' => 'custom' 
        add_action( 'bp_init', 'setup_group_nav' );
        function bp_group_custom() {
        	add_action('bp_template_title', 'my_new_group_show_screen_title');
        	add_action('bp_template_content', 'my_new_group_show_screen_content');
        	$templates = array('groups/single/plugins.php', 'plugin-template.php');
        	if (strstr(locate_template($templates), 'groups/single/plugins.php')) {
        		bp_core_load_template(apply_filters('bp_core_template_plugin', 'groups/single/plugins'));
        	} else {
        		bp_core_load_template(apply_filters('bp_core_template_plugin', 'plugin-template'));
        function my_new_group_show_screen_title() {
        	echo 'New Tab Title';
        function my_new_group_show_screen_content() {
        	echo 'New tab page content';

    I can call a custom template for my custom page like so:

    function my_new_group_show_screen_content() {
    	echo bp_buffer_template_part( 'groups/group-custom', null, false );

    Then, just for testing, on that template, I record a visit to that page as an activity, like so:

    	$defaults = array(
    		'user_id' => '1',
    		'action' => 'A user just visited the custom page.',
    		'content' => 'It was considered a good time.',
    		'primary_link' => '',
    		'component' => 'groups',
    		'type' => 'naming',
    		'item_id' => $bp->groups->current_group->id,
    		'secondary_item_id' => get_current_user_id(),
    		'recorded_time' => gmdate( "Y-m-d H:i:s" ),
    		'hide_sitewide' => '0'
    	extract( $defaults );
    	$r = bp_activity_add( array( 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );

    So, I could now allow for the creation of instances of my_cpt on this custom page. When adding this instance to the WP database, I also store the group for which it was created. Then, on this custom page, I could show a list of all instances created for this group.
    And, when this instance has been created, I can save an activity connected to this group.



    Thank you for this idea.

    Actually my issue is slightly different.

    How can I attach an existing SWA activity post to a group. The SWA activity post was not initially attached to a group. Once attached, when users go to the group, they should be able to see the post as part of the group activity posts. Any idea how to do this ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar