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 ) ) );
}`
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?
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.
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.
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.
What is the link it’s producing?
Just the same page that I was on. It just reloads.
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.
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
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() ||`
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!
No problem. Glad it works now