Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save champsupertramp/12a5e29081085d0d3f8b62217bfa2883 to your computer and use it in GitHub Desktop.
Save champsupertramp/12a5e29081085d0d3f8b62217bfa2883 to your computer and use it in GitHub Desktop.
Ultimate Member Private Messaging - Email recipients everytime there's a new message in chat
/**
* Author: Champ
* Website: www.champ.ninja
*/
function um_custom_messaging_user_got_message($to, $from, $conversation_id ){
if ( ! UM()->Messaging_API()->api()->enabled_email( $to, '_enable_reminder_pm' ) ) {
return;
}
remove_action( 'um_after_existing_conversation', 'um_messaging_user_got_message', 20, 3 ); // Remove the original email notification with timestamp
// send a mail notification
um_fetch_user( $to );
$recipient_e = um_user('user_email');
$recipient = um_user('display_name');
$message_history = add_query_arg('profiletab', 'messages', um_user_profile_url() );
// who sends the message
um_fetch_user( $from );
$sender = um_user('display_name');
UM()->mail()->send( $recipient_e, 'new_message', array(
'plain_text' => 1,
'path' => um_messaging_path . 'templates/email/',
'tags' => array(
'{recipient}',
'{message_history}',
'{sender}'
),
'tags_replace' => array(
$recipient,
$message_history,
$sender
)
) );
}
add_action( 'um_after_existing_conversation', 'um_custom_messaging_user_got_message', 19, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment