Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: BP Avatars (and nothing else!) in bbpress… possible?


Greg
Participant

@rebootnow

Here is a quick & dirty stab at the method Burt suggests above. I have modified “bp_core_get_avatar()” (from “bp-core-avatars.php”) for use bbPress. Like the bp function it uses an uploaded avatar or a gravatar. You need to ensure that there is a “mystery-man.gif” file in the images folder of your theme. Note that I haven’t enabled the fancy automatically generated avatars.

It works for me. Here are the steps:

Create the new function “_get_avatar()”. I put it in “functions.php” in my theme folder and added “<?php require_once( ‘functions.php’ ); ?>” just before the <body> tag in “header.php” to ensure that it was loaded.

You need the following in your “post.php” to call the function:

<?php echo _get_avatar( get_post_author_id() ); ?>

Here is the code for “_get_avatar()”:

function _get_avatar( $id ) {

$avatar_file = bb_get_usermeta( get_post_author_id(), ‘bp_core_avatar_v1’ );

$url = BB_PATH . $avatar_file;

if ( strlen( $avatar_file ) ) {

return ‘<img src=”‘ . attribute_escape( $url ) . ‘” alt=”” class=”avatar photo” width=”50″ height=”50″ />’;

} else {

$default_grav = bb_get_active_theme_uri() . ‘images/mystery-man.gif’;

$user_email = bb_get_user_email( $id );

$gravatar = ‘https://secure.gravatar.com/avatar/&#8217; . md5( $user_email ) . ‘?d=’ . $default_grav . ‘&s=50’;

return ‘<img src=”‘ . attribute_escape( $gravatar ) . ‘” alt=”” class=”avatar photo” width=”50″ height=”50″ />’;

}

return;

}

One question I have for the experts… Is this a reasonable way of adding a new function? Or would it be better to create a plugin. I didn’t do the latter because I didn’t need to use any of the hooks.

Skip to toolbar