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,
GrahamHello 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@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
BrajeshHi Graham,
Did you by any chance removeMAINCONTENT;
on the last line?
If feasible, please post the modified code on pastebin and link.
Thank you
BrajeshHi 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
BrajeshHi 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,
GrahamHi 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.