BuddyDev

Search

Mail notifications on BuddyPress Group Activities Notifier

  • Participant
    Level: Initiated
    Posts: 7
    arisanz on #36586

    If I paste the code then a critical error appears in my web.

    Don’t know what to do..

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2499
    Ravi on #36604
    This reply has been marked as private.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2499
    Ravi on #37365

    Hello,

    Please use the following code. It will send email notification to all group members on new activity update,

    
    
    function buddydev_mail_on_new_group_activity( $user_ids, $args ) {
    
    	if ( empty( $user_ids ) ) {
    		return;
    	}
    
    	$user_emails = array_map( function ( $user_id ) {
    		$user = get_user_by( 'id', $user_id );
    
    		if ( ! $user ) {
    			return;
    		}
    
    		return $user->user_email;
    	}, $user_ids );
    
    	$user_emails = array_filter( $user_emails );
    
    	if ( ! $user_emails ) {
    		return;
    	}
    
    	$group                      = new BP_Groups_Group( $args['group_id'] );
    	$loggedin_user_display_name = bp_get_loggedin_user_fullname();
    
    	$activity = new BP_Activity_Activity( $args['activity_id'] );
    
    	$activity_content   = $activity->content;
    	$activity_permalink = bp_activity_get_permalink( $activity->id, $activity );
    
    	$subject = sprintf( '%1$s posted to %2$s', $loggedin_user_display_name, $group->name );
    
    	$message = <<<MAIN
    Hi,
    	
    {$loggedin_user_display_name} posted...
    	
    {$activity_content}
    
    Link: {$activity_permalink}
    MAIN;
    
    	wp_mail( $user_emails, $subject, $message );
    }
    add_action( 'bp_group_activities_notify_members', 'buddydev_mail_on_new_group_activity', 10, 2 );
    
    

    Please do let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 7
    arisanz on #37384

    Hi guys! Great work! It’s working perfectly. Now I have a question.. where can I translate the content of the email sent? I can translate to Spanish if you need. Thank you so much for your work!

  • Participant
    Level: Initiated
    Posts: 1
    Steven on #44788

    Hello,

    I use this plugin to generate group notification in Buddypress.
    But when user publish post with picture or document without text, the pluggin use an old activity id.
    Have you tested this problem ?

    Thanks

You must be logged in to reply to this topic.

This topic is: not resolved