Automatically send private messages in Ultimate Member

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){
  global $ultimatemember, $um_messaging;
  // Create conversation and add message
  $_POST['content']  = "Automatically generated message: " . $message;
  $conversation_id = $um_messaging->api->create_conversation( $to, $from );
  //$output['messages'] = $um_messaging->api->get_conversation($to, $from, $conversation_id );
  $_POST['content'] = "";
  do_action('um_after_new_message', $to, $from, $conversation_id );
}

Leave a Reply

Your email address will not be published. Required fields are marked *

×