How Can We Help?

Creating link to new thread screen with prefilled username and message

You are here:
< All Topics
<?php
// Sending message to 1 user
$user_id = 5; #Here you need to get user_id from somewhere depending on the environment
$user = get_userdata($user_id);
$nice_name = $user->user_nicename;
$subject = urlencode('Have question about your product');
$message = urlencode('Have question about your product');
$link = BP_Better_Messages()->functions->get_link() . '?new-message&to=' . $nice_name . '&subject=' . $subject . '&message=' . $message;

echo $link;

// Sending message to multiple users
$user_ids = [5,6,7]; #Here you need to get user_ids from somewhere depending on the environment
$user_names = [];
foreach( $user_ids as $user_id ){
  $user = get_userdata($user_id);
  $user_names[] = $user->user_nicename;
}
$subject = urlencode('Have question about your product');
$message = urlencode('Have question about your product');
$link = BP_Better_Messages()->functions->get_link() . '?new-message&to=' . implode(',', $user_names) . '&subject=' . $subject . '&message=' . $message;

echo $link;

This code snippet is great example of how to create links to start new threads with other user in any place of your website.

Table of Contents