Skip to:
Content
Pages
Categories
Search
Top
Bottom

Direct link to PM to a specific user?


  • Charles
    Participant

    @charlesrodmell

    Is it possible to easily make a link (that I can place in a button) that replicates the “Private Message” button that appears at the top of people’s profiles? Hovering on that link includes a nonce, the target nickname and my own user nickname.

    What I’d like is a button that I can place somewhere on the site which lets any user go directly to the compose screen with (specifically) my nickname already inserted in the “Send @username” field.

    So something like https://domain.com/messages/compose/?r=meeeeeee (but working).

Viewing 5 replies - 1 through 5 (of 5 total)

  • emaralive
    Participant

    @emaralive

    If one were to literally read, your example link; the link would probably work better if there were a “members/user name” between “domain name” & “messages”, i.e., domain_name/members/user_name/messages/blah_blah_blah.

    This should go without saying, but the “user_name” would be that of the user who intends to send the PM.


    Charles
    Participant

    @charlesrodmell

    Cheers, I get you. But the button I want has to work for any member. In your example, I’d have to dynamically generate the link in the button and suddenly I’m coding instead of just putting in a static link 😀 I just want a button that any user can click to send me a message. Currently I have a button pointing to my profile and then they have to click another one to start the message. I just want one button.


    thinlizzie
    Participant

    @thinlizzie

    This is untested but you might try ….

    domain/members/me/messages/compose/?r=yourusername


    Charles
    Participant

    @charlesrodmell

    @thinlizzie That’s excellent. Thank you so much. I didn’t know about the “me” thing. It works exactly as I wanted.


    jgasba
    Participant

    @jgasba

    I’ve done what you want to do like this:

    
    $user_compose_url = get_site_url() . '/members/' . get_user_by('id', get_current_user_id())->user_nicename . '/messages/compose';
    
    /* or when Buddypress 12.0 will be released */
    $user_compose_url = bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_messages_slug(), 'compose' ) ) );
    
    $url = wp_nonce_url(
                    add_query_arg(
                        'r',
                        get_user_by('id', $user_id)->user_nicename,
                        $user_compose_url
                    )
                );
    

    This way you’ll have the nonce.
    You’ll need to adapt the code to where you want to display the button though.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar