Skip to:
Content
Pages
Categories
Search
Top
Bottom

Posting an activity update to a group stream


  • gbowman
    Participant

    @gbowman

    I have a site with (amongst others) BuddyPress, BadgeOS and the BadgeOS Community Add-on.

    The BadgeOS Community Add-on allows achievements earned through BadgeOS to be added to the users activity stream. I would like these updates to also be posted to the stream of each group the user is a member of (usually only one).

    I have located the section of code in the BadgeOS Community Add-on that is adding the activity when an achievement is awarded: (badgeos-community-add-on/includes/bp-activity.php)

    function badgeos_award_achievement_bp_activity( $user_id, $achievement_id, $this_trigger, $site_id, $args ) {
    
    	if ( ! $user_id || ! $achievement_id )
    		return false;
    
    	$post = get_post( $achievement_id );
    	$type = $post->post_type;
    
    	// Don't make activity posts for step post type
    	if ( 'step' == $type ) {
    		return false;
    	}
    
    	// Check if option is on/off
    	$achievement_type = get_page_by_title( str_replace('-',' ', $type), 'OBJECT', 'achievement-type' );
    	$can_bp_activity = get_post_meta( $achievement_type->ID, '_badgeos_create_bp_activty', true );
    	if ( ! $can_bp_activity ) {
    		return false;
    	}
    
    	// Grab the singular name for our achievement type
    	$post_type_singular_name = strtolower( get_post_type_object( $type )->labels->singular_name );
    
    	// Setup our entry content
    	$content = '<div class="badgeos-achievements-list-item user-has-earned">';
    	$content .= '<div class="badgeos-item-image"><a href="'. get_permalink( $achievement_id ) . '">' . badgeos_get_achievement_post_thumbnail( $achievement_id ) . '</a></div>';
    	$content .= '<div class="badgeos-item-description">' . wpautop( $post->post_excerpt ) . '</div>';
    	$content .= '</div>';
    
    	# Bypass checking our activity items from moderation, as we know we are legit.
    	add_filter( 'bp_bypass_check_for_moderation', '__return_true' );
    
    	// Insert the activity
    	bp_activity_add( apply_filters(
    		'badgeos_award_achievement_bp_activity_details',
    		array(
    			'action'       => sprintf( __( '%1$s earned the %2$s: %3$s', 'badgeos-community' ), bp_core_get_userlink( $user_id ), $post_type_singular_name, '<a href="' . get_permalink( $achievement_id ) . '">' . $post->post_title . '</a>' ),
    			'content'      => $content,
    			'component'    => 'badgeos',
    			'type'         => 'activity_update',
    			'primary_link' => get_permalink( $achievement_id ),
    			'user_id'      => $user_id,
    			'item_id'      => $achievement_id,
    		),
    		$user_id,
    		$achievement_id,
    		$this_trigger,
    		$site_id,
    		$args
    	) );
    
    }
    add_action( 'badgeos_award_achievement', 'badgeos_award_achievement_bp_activity', 10, 5 );

    I believe the line 'type' => 'activity_update', is the part that decides how the activity is posted.

    I’ve read up on the page https://codex.buddypress.org/plugindev/bp_activity_add-2/ but I’m still a little confused as to why these activity updates are not being shown in the group stream.

    Any pointers?

  • You must be logged in to reply to this topic.
Skip to toolbar