Skip to:
Content
Pages
Categories
Search
Top
Bottom

Link to a private message

  • @janismo

    Participant

    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!

Viewing 7 replies - 1 through 7 (of 7 total)
  • @espellcaste

    Moderator

    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!

    @sbrajesh

    Participant

    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.

    @sbrajesh

    Participant

    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.

    @janismo

    Participant

    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!

    @sbrajesh

    Participant

    Hi James, Here is an example code

    http://pastebin.com/WA2rBjvH

    You are right about the url part ๐Ÿ™‚

    @janismo

    Participant

    yeah, as always, tried tens of variations, not this one ๐Ÿ™‚

    works excellent, thank you again, Brajesh!

    @espellcaste

    Moderator

    @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?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Link to a private message’ is closed to new replies.
Skip to toolbar