Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: BBpress “post_author_link” problem?


Greg
Participant

@rebootnow

The thing is that bbPress doesn’t know that the user “nbsmrt” has BP Name “murat”.

UPDATE: Scratch that – your display names should actually be working, and in fact I see that they are for users other than “nbsmrt”. The bit I put below is necessary if you want the author link to go back to their BP profile instead of the bbPress profile page.

I wanted the name to be consistent everywhere, so I have a bit of common code that displays the user’s details in forum posts, blog comments, etc. Note that it requires deep integration because I am accessing BP variables inside bbPress.

For example, here is what I do in the forum…

First, in post.php I get the author’s details like so:

$author_id = get_post_author_id( $post_id );
$author = get_userdata( $author_id );
$author_loginname = $author->user_login;
$author_displayname = get_post_author();

Then I call a function to display the user link, avatar and other things. Part of this function does the following:

<?php
$author_url = _profile_url( $author_loginname );
?>

<div class="username">
<a href="<?php echo $author_url ?>"><?php echo $author_displayname ?></a>
</div>

And here is the code for the _profile_url() function:

function _profile_url( $login_name=0 ) {
global $bp;

/* if no login name is specified, use logged in user */
if ($login_name) {
$url = $bp->root_domain . '/members/' . $login_name . '/profile';
} else {
$url = $bp->loggedin_user->domain . 'profile';
}

return $url;
}

So the user’s BP Name is always used, and it always links to their BP profile.

My one concern about all this is that get_userdata() does a SQL query, adding one query for each author in a topic thread.

Skip to toolbar