justsayno1 (@justsayno1)

Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)

  • justsayno1
    Participant

    @justsayno1

    No worries, I like putting up answers like this because people have done the same for me and it was a life saver. Also I feel like this is something that bbpress should just be able to do through the admin panel so I thought I would help out any one who wants to not expose their users real names to everybody.


    justsayno1
    Participant

    @justsayno1

    How did you get from there to “I just followed…”?

    Unfortunately there is not an easy way to explain this as I am not that familair with wordpress/bbpress core myself. BUT what I mean is that function is obviously somewhere in the bbpress core files. All I did was start going in there. They are quite well documented and have comments that explain the different functions that get used. You are mainly looking for the template tags function files. Also most plugins/php apps use an includes folder to put all the main crux of the things in. While the main file is just simply a link to all those areas an common functions. If you really can’t find it then just use a program with a “search in files” option and just try and find it that way. I think that is what I did to start with.

    For example when I wanted to find the function yo mention above:
    bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => false ) );

    I thought about what the function is saying and where in the folder directories of includes it may be. Since it was “reply” related I figured it would be in the reply section. I just used some common sense to figure out the template-tags.php probably containted template specific functions. Then I just did a search on those files until I found the bbp_reply_author_link. Which then calls bbp_get_reply_author_link which in tern as a return value of:

    return apply_filters( 'bbp_get_reply_author_link', $author_link, $r );

    Meaning that you can basically sub in your own functino for this function by using:

    add_filter( 'bbp_get_reply_author_display_name', 'replace_bbpress_replies_username_filter', 10, 2);

    Where replace_bbpress_replies_username_filter is your replacement filter. Then what I mean by following the functions is that i realised that this function was fine. It was the bpp_get_author_display_name that I was unhappy with. And this would be called in many places (presumably). So I overwrote that function. EG:

    
    function replace_bbpress_replies_username_filter($author_name,$reply_id ){
    $author_id = bbp_get_reply_author_id($reply_id);
    $author_object = get_userdata( $author_id );
    $author_name  = ucfirst($author_object->user_login);
    return $author_name;
    }
    add_filter( 'bbp_get_reply_author_display_name', 'replace_bbpress_replies_username_filter', 10, 2);
    

    Does that help? I know it seems daunting but getting into the core files and seeing what they are doing is I have found the best way when you are thinking “what the fuck!”. Also bear in mind I spend about 4 hours yesterday figuring this stuff out (but I didn’t understand filters really until now). Just to help you out futher. The three filters I added were as follows:

    
    add_filter( 'bbp_get_reply_author_display_name', 'replace_bbpress_replies_username_filter', 10, 2);
    add_filter( 'bbp_get_topic_author_display_name', 'replace_bbpress_topic_author_display_name', 10, 2);
    add_filter( 'bbp_get_user_profile_link', 'replace_bbpress_profile_link_text_filter', 10, 2 );
    

    The display name function I have shown you. The topic display name function:

    
    function replace_bbpress_topic_author_display_name( $topic_id = 0 ) {
    		$topic_id = bbp_get_topic_id( $topic_id );
    
    		// Check for anonymous user
    		if ( !bbp_is_topic_anonymous( $topic_id ) ) {
    
    			// Get the author ID
    			$author_id = bbp_get_topic_author_id( $topic_id );
    			$author_name = get_the_author_meta( 'user_login', $author_id );
    
    		// User does not have an account
    		} else {
    			$author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true);
    		}
    
    		// If nothing could be found anywhere, use Anonymous
    		if ( empty( $author_name ) )
    			$author_name = __( 'Anonymous', 'bbpress' );
    
    		// Encode possible UTF8 display names
    		if ( seems_utf8( $author_name ) === false )
    			$author_name = utf8_encode( $author_name );
    
    		return $author_name;
    }

    And for the profile link:

    
    function replace_bbpress_profile_link_text_filter($user_link, $user_id){
    		// Validate user id
    		$user_id = bbp_get_user_id( $user_id );
    		$user_object = get_userdata( $author_id );
    		$user_name  = ucfirst($author_object->user_login);
    		if ( empty( $user_id ) )
    			return false;
    
    		$user      = get_userdata( $user_id );
    		$name      = esc_attr( $user_name );
    		$user_link = '<a href="' . bbp_get_user_profile_url( $user_id ) . '" title="' . $name . '">' . $name . '</a>';
    }

    I also changed the default wordpress “get_avatar” function because it returns the gravatar users real name as the alt attr. All you really have to do it replace the function with the same function but get the users login name and replace the alt text name with that. the function is big and I don’t wanna make this post any more ridiculous.

    It’s cool to be the one giving the answers on a WordPress forum! I only really have learned this stuff in the last few months myself. I am more of a Drupal guy. Shock Horror.

    Cheers!


    justsayno1
    Participant

    @justsayno1

    Hi,

    I am in the same situation and I have found a solution. You can apply filters to almost every function in bbpress it seems. I just followed the functions until I found these three filters:

    apply_filters( 'bbp_get_user_profile_link', $user_link, $user_id );
    apply_filters( 'bbp_get_reply_author_display_name', $author_name, $reply_id )
    apply_filters( 'bbp_get_topic_author_link', $author_link, $args );
    

    Using these you can change basically everything. I found it easier to change the avatar ALT text vie the normal wordpress get_avatar filter since I wanted that to happen site wide anyway. Here is an example of the reply filter:

    
    function replace_bbpress_replies_username_filter($author_name,$reply_id ){
    $author_id = bbp_get_reply_author_id($reply_id);
    $author_object = get_userdata( $author_id );
    $author_name  = ucfirst($author_object->user_login);
    return $author_name;
    }
    add_filter( 'bbp_get_reply_author_display_name','replace_bbpress_replies_username_filter',10, 2);
    

    Hope that helps. You can do it through templating but this way you don’t have to worry about doing it in a million different templates and then also dealing the layout of the markup you use to replace the current markup. And if filters confuse you and you don’t understand go read this:

    http://dev.themeblvd.com/tutorial/filters/

    I had zero knowledge of how to do filters when I read this thread 16 hours ago and decided to not go the route the above person mentioned.

    EDIT: I thought I’d add that they really could make this a lot easier with very little effort and make it so that you could configure what to use as a display name…. If anyone reads this from bbPress I’d be happy to get involved and do it for them. Seems so dumb to default to make it peoples full names when 90% people don’t want that. That is what facebook, G+ etc is for.

Viewing 3 replies - 1 through 3 (of 3 total)