BuddyDev

Search

[Resolved] BuddyPress Group Activities Notifier – Email Group Admin Only

  • Participant
    Level: Enlightened
    Posts: 64
    Graham on #12227

    Hi Brajesh,

    I installed your plugin because group admins don’t get notified when someone joins their group by default.

    It works fine.

    I see you have given an example of the code needed to email notifications. Is there a way to modify that code so emails only go to the group admin(s)?

    Thanks,
    Graham

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #12230

    Hello Graham,

    Brajesh sir is away that’s why I am posting here.

    Try the following code in your ‘bp-custom.php’ file to notify by email Group’s admin.

    
    function buddydev_mail_on_new_group_activity( $user_ids, $args ) {
    
    	if ( empty($user_ids ) ) {
    		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 = <<<'MAINCONTENT'
        Hi %1$s,
        %2$s posted...
        
        %3$s
     
        Link: %4$s
    MAINCONTENT;
    
    	foreach ( $group->admins as $admin ) {
    		$message = sprintf( $message, bp_core_get_user_displayname( $admin->user_id ), $loggedin_user_display_name, $activity_content, $activity_permalink );
    		wp_mail( $admin->user_email, $subject, $message );
    	}
    }
    add_action( 'bp_group_activities_notify_members', 'buddydev_mail_on_new_group_activity', 10, 2 );
    
    

    Please let me know if it works or not.

    Thank You
    Ravi

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #12231

    @ravisharma,
    Thank you. I am back now. I still appreciate you helping in the forums.


    @cobber
    ,
    hi Graham,
    Please check if the above code works for you.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 64
    Graham on #12232

    Hi Ravi,

    Thanks for the quick reply.

    I will let you know how it goes

    Graham

  • Participant
    Level: Enlightened
    Posts: 64
    Graham on #12233

    Hi Guys,

    Yes it worked fine, and I could customize the message okay.

    The PHP editor gave me a red “X” for the line:

    $message = <<<'MAINCONTENT'

    (Syntax error. Unexpected T_SL)

    Don’t know if that is important.

    Thanks,
    Graham

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #12234

    Hi Graham,
    Did you by any chance remove

    
    MAINCONTENT;
    

    on the last line?

    If feasible, please post the modified code on pastebin and link.

    Thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 64
    Graham on #12236

    Hi,

    No it’s still there.

    I did a copy and paste of your code to a text file, then from there to my child functions.php file.

    I don’t have a pastebin account.

    Will be offline for a while. Will get back to you.

    Graham

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #12237

    Hi Graham,
    Ravi has used Nowdoc style string which is very sensitive to the use of spaces/newlines etc. That’s why I wanted to see a copy.

    You don’t need to have an account to post on pastebin(It asks to fill a captcha)

    When you are back, Please do provide me access to it somehow if not using pastebin.

    Thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 64
    Graham on #12238

    Hi Brajesh,

    Created a pastebin account anyway. The link is https://pastebin.com/ixTC6BS7

    That is the code as I got it from here. The syntax error showed with that.

    Customizing the message had no effect on the error.

    As I said originally, it doesn’t seem to prevent it from working though,

    Cheers,
    Graham

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #12251

    Hi Graham,
    There is no error with your code. Are you getting any fatal error or notice from the site after updating this code? You may ignore the editor warning. I don’t see any warning while using PHPStorm. which editor it is?

    Regards
    Brajesh

The topic ‘ [Resolved] BuddyPress Group Activities Notifier – Email Group Admin Only’ is closed to new replies.

This topic is: resolved