Really Simple Plugins

Automatically send private messages in Ultimate Member

Popular articles

Woocommerce Moneybird

Link your WooCommerce webshop to your Moneybird account, and synchronize all payments to an invoice in Moneybird automatically! With WooCommerce Moneybird all your sales will

Read More
Share on facebook
Share on twitter
Share on linkedin

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 );
}

Related articles

Subscribe