Skip to:
Content
Pages
Categories
Search
Top
Bottom

Need help with PM function in forums

  • @vegasparty607

    Participant

    I am trying to put a Private Message Function in the forums so people can choose to PM eachother in the forums, but I am getting stuck on the function!!! I know I am close, but I am having trouble with some of it… here is what I have so far

    `function bp_forum_send_private_message_link() {
    echo bp_forum_get_send_private_message_link();
    }
    function bp_forum_get_send_private_message_link() {
    global $topic_template;

    if ( !bp_the_topic_is_mine() || !is_user_logged_in() )
    return false;

    return apply_filters( ‘bp_forum_get_send_private_message_link’, wp_nonce_url( $bp->loggedin_user->domain . $bp->messages->slug . ‘/compose/?r=’ . bp_core_get_username( $topic_template->post->poster_id, $topic_template->displayed_user->userdata->user_nicename, $topic_template->displayed_user->userdata->user_login ) ) );
    }`

    What am I doing wrong? The Link just redirects itself to the page I was on…

Viewing 20 replies - 1 through 20 (of 20 total)
  • @cnorris23

    Participant

    I would start with adding $bp to your global statement.

    `global $bp, $topic_template;`

    @vegasparty607

    Participant

    Thought for sure this would work but it didn’t

    `function bp_forum_send_private_message_link() {
    echo bp_forum_get_send_private_message_link();
    }
    function bp_forum_get_send_private_message_link() {
    global $bp, $topic_template;

    if ( !bp_the_topic_is_mine() || !is_user_logged_in() )
    return false;

    return apply_filters( ‘bp_forum_get_send_private_message_link’, wp_nonce_url( $bp->loggedin_user->domain . $bp->messages->slug . ‘/compose/?r=’ . bp_core_get_username( $bp->topic_template->post->poster_id, $bp->topic_template->displayed_user->userdata->user_nicename, $bp->topic_template->displayed_user->userdata->user_login ) ) );
    }`

    @cnorris23

    Participant

    That’s be cause you changed too much. You only need to change the line I told you to change. Which was:

    `global $topic_template;`

    to

    `global $bp, $topic_template;`

    Nothing else should change.

    @vegasparty607

    Participant

    i changed it! see in the code above?

    @cnorris23

    Participant

    Yes, but you changed more than that. You changed the code in bp_core_get_username() from:

    `bp_core_get_username( $topic_template->post->poster_id, $topic_template->displayed_user->userdata->user_nicename, $topic_template->displayed_user->userdata->user_login )`

    ,which was correct, to:

    `bp_core_get_username( $bp->topic_template->post->poster_id, $bp->topic_template->displayed_user->userdata->user_nicename, $bp->topic_template->displayed_user->userdata->user_login )`

    which is incorrect.

    @vegasparty607

    Participant

    the function still redirects to the same page. :(

    @cnorris23

    Participant

    Are you sure the globals are correct within `bp_core_get_username`? I’m going under the assumption that you did your homework and found the right globals. The code inside bp_core_get_username() is the only place things could go wrong.

    @vegasparty607

    Participant

    Yes, I copied right from the template-tags for the send_private_message_link function.

    @cnorris23

    Participant

    Yeah, that’s why. Try this:

    `bp_core_get_username( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login )`

    @vegasparty607

    Participant

    Still redirects to the same page.

    @cnorris23

    Participant

    What is the link it’s producing?

    @vegasparty607

    Participant

    Just the same page that I was on. It just reloads.

    @cnorris23

    Participant

    Instead of clicking the link, right-click and choose “copy shortcut” or “copy url” or “copy link”… whatever the text may be. I would change your web domain to example.com before posting the link if you don’t want people poking around your site.

    @r-a-y

    Keymaster

    You’d probably want to echo the result.

    Use the following in topic.php:
    `bp_forum_send_private_message_link()`

    And not:
    `bp_forum_get_send_private_message_link()`

    @vegasparty607

    Participant

    -brandon I copied link and pasted it, and it’s just the same URL

    -ray, thats how it is in my topic.php

    @cnorris23

    Participant

    Question… Are you trying to put the link on every post as long as it’s not your own post?

    @vegasparty607

    Participant

    Yeah. Thats why I have the ` if ( !bp_the_topic_is_mine() ||`

    @cnorris23

    Participant

    Well that’s why I asked. Right now the logic tranlates to this:

    “If this topic is not mine, or the user is not logged in, don’t show a link.”

    You want it to say:

    “If this post is mine, or the user is not logged in, don’t show a link.”

    Here’s your new code:

    `function bp_forum_send_private_message_link() {
    echo bp_forum_get_send_private_message_link();
    }
    function bp_forum_get_send_private_message_link() {
    global $bp, $topic_template;

    if ( bp_get_the_topic_post_is_mine() || !is_user_logged_in() )
    return false;

    return apply_filters( ‘bp_forum_get_send_private_message_link’, wp_nonce_url( $bp->loggedin_user->domain . $bp->messages->slug . ‘/compose/?r=’ . bp_core_get_username( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) ) );
    }`

    @vegasparty607

    Participant

    Nice! It works now. Thanks for your help! :)

    @cnorris23

    Participant

    No problem. Glad it works now

Viewing 20 replies - 1 through 20 (of 20 total)
  • The topic ‘Need help with PM function in forums’ is closed to new replies.
Skip to toolbar