Link to a private message
- 
		Hi! How do I create a link, which would lead to a PM “compose” screen with predefined “send to” id, subject and message? latest wp, bp. thanks! 
- 
		
			
Hi @James, I’m also looking for a solution like this and haven’t found so far. I believe I’ll have to hard code it. If I come to a solution I’ll post here! Here is a simple solution. You will need to add following lines to your theme’s functions.php or bp-custom.php ` /** 
 *
 * @param int $to_id the user id to whom we plan to send the message
 * @param string $subject : if you want to specifuy a predefined subject
 * @param string $message: any predefined message
 * @return string: link for sending message
 */
 function bp_custom_get_send_private_message_link($to_id,$subject=false,$message=false) {//if user is not logged, do not prepare the link 
 if ( !is_user_logged_in() )
 return false;$compose_url=bp_loggedin_user_domain() . bp_get_messages_slug() . ‘/compose/?’; 
 if($to_id)
 $compose_url.=(‘r=’ . bp_core_get_username( $to_id ));
 if($subject)
 $compose_url.=(‘&subject=’.$subject);
 if($message)
 $compose_url.=(“&content=”.$message);return wp_nonce_url( $compose_url ) ; 
 }//for auto populating message content 
 add_filter(‘bp_get_messages_content_value’,’bp_custom_message_content_value’);
 function bp_custom_message_content_value($content){if(!empty ($content)) 
 return $content;
 $content=$_REQUEST[‘content’];return $content; 
 }//for auto populating message subject add_filter(‘bp_get_messages_subject_value’,’bp_custom_get_messages_subject_value’); function bp_custom_get_messages_subject_value($subject){ if(!empty($subject)) 
 return $subject;$subject=$_REQUEST[‘subject’]; return $subject; } ` and then, you can use following in your code to send the user with id:2 a message as ` 
 <a href="”>Send Message to xyz` hope that helps. Ok, forum does not allow me to post the html code. After including the above code, you can use this function bp_custom_get_send_private_message_link to get the appropriate url. thanks Brajesh, recently wanted to write about it. As I understand, we should use this function as a href, but how to write the parameters in, since for some reason I cannot get it working. thanks! Hi James, Here is an example code You are right about the url part ๐ yeah, as always, tried tens of variations, not this one ๐ works excellent, thank you again, Brajesh! @sbrajeshย Thank you for this one! ๐ But I have another question, imagine I wanna to put the messages box (compose, reply, etc) in the side bar on a profile page only. As I saw, each instance of the private message comes with a url, like Compose …/compose Reply …/reply etc. Could you point me for a possible solution? 
- The topic ‘Link to a private message’ is closed to new replies.