Skip to:
Content
Pages
Categories
Search
Top
Bottom

Need help with PM function in forums

  • 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)

  • Brandon Allen
    Participant

    @cnorris23

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

    `global $bp, $topic_template;`

    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 ) ) );
    }`


    Brandon Allen
    Participant

    @cnorris23

    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.

    i changed it! see in the code above?


    Brandon Allen
    Participant

    @cnorris23

    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.

    the function still redirects to the same page. :(


    Brandon Allen
    Participant

    @cnorris23

    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.

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


    Brandon Allen
    Participant

    @cnorris23

    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 )`

    Still redirects to the same page.


    Brandon Allen
    Participant

    @cnorris23

    What is the link it’s producing?

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


    Brandon Allen
    Participant

    @cnorris23

    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

    @r-a-y

    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()`

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

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


    Brandon Allen
    Participant

    @cnorris23

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

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


    Brandon Allen
    Participant

    @cnorris23

    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 ) ) );
    }`

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


    Brandon Allen
    Participant

    @cnorris23

    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