Documentation

Action wphd_new_message

This action is executed every time a new message is stored in the database (before any email notifications are sent), regardless of where the message is submitted from (i.e. email import, admin panel, submit ticket form, Ninja Forms form, or ticket reply).

Below is a simple usage example.

// Register action, notice fourth argument (3)
// it allows to pass 3 params to callback function
add_action("wphd_new_message", "my_wphd_new_message", 10, 3);


/**
 * @var $thread Wphd_Model_Thread Current thread
 * @var $message Wphd_Model_Message Current message
 * @var $context string One of: "admin", "email-import", "submit-ticket", "tickets"
 **/
function my_wphd_new_message($thread, $message, $context) {
   // do something with the ticket here

   // once done save message and thread
   $message->save();
   $thread->save();
}

In the code above we are using the $thread (Wphd_Model_Thread) and $message (Wphd_Model_Message) objects. These objects contain all data about the thread and message being stored.

An example use case of this action would be to assign a new ticket to a specific agent based on ticket data such as the sender’s email address or the value of a custom field.