Tag Archives: wordpress

Ultimate Member

Automatically send private messages in Ultimate Member

For a project where messages had to be sent automatically to the users without additional email being sent, I’ve chosen to use private messages for this purpose.

In this project when a user uploads a new file, a private message should be sent to another user. This way there is not a flood of annoying emails. Ultimate Member will send an email if the receiving user does not log in to check his private messages. This email will normally be sent once a day.

In the code where the update is received, I add this function:

rsp_send_private_message($to, $from, $message);

 /** 
  * Send a private message from a user to a user 
  * 
  * @since   
  * @param  int $to   User id the message is directed to
  * @param  int $from User id the message should come from
  * @param  string $message The text message
  * @return bool             void 
*/
function rsp_send_private_message($to, $from, $message){
  //We do not want to message ourselves
  if ($from==$to) return;
  // Create conversation and add message
  $_POST['content']  = "Automatically generated message: " . $message;
  $conversation_id = UM()->Messaging_API()->api()->create_conversation( $to, $from );;
  $_POST['content'] = "";
  do_action('um_after_new_message', $to, $from, $conversation_id );
}
1 2
×