new_message
This function is to send new replies in existing conversations or create new conversations programmatically
REQUIREMENTS
To be able to implement this guide, you need to learn how to insert PHP snippets to your website.
You can find guide here: WP Beginner
Starting new conversation
<?php
// Sender user ID
$sender_id = get_current_user_id();
// Recipients User IDs
$recipients = [2, 3, 4];
// Conversation message content
$content = 'new conversation message content';
// Conversation subject
$subject = 'Subject';
$thread_id = Better_Messages()->functions->new_message([
'sender_id' => $sender_id,
'content' => $content,
'subject' => $subject,
'recipients' => $recipients,
'return' => 'thread_id',
'error_type' => 'wp_error'
]);
if ( is_wp_error( $thread_id ) ) {
$error = $thread_id->get_error_message();
// Process error
} else {
// Thread created
//var_dump( $thread_id );
}
Replying to existing conversation
<?php
// Sender user ID
$sender_id = get_current_user_id();
// Thread ID
$thread_id = 6620;
// Conversation message content
$content = 'new message content';
$message_id = Better_Messages()->functions->new_message([
'sender_id' => $sender_id,
'thread_id' => $thread_id,
'content' => $content,
'return' => 'message_id',
'error_type' => 'wp_error'
]);
if ( is_wp_error( $message_id ) ) {
$error = $message_id->get_error_message();
// Process error
} else {
// Message created
// var_dump( $message_id );
}