Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author myCred

    (@designbymerovingi)

    Hey!

    You can use the following code to add avatars to the leaderbaord. Each results row is passed though the mycred_ranking_row filter which allows you to add / adjust things that can not be done via the template.

    add_filter( 'mycred_ranking_row', 'my_custom_ranking_rows', 10, 4 );
    function my_custom_ranking_rows( $layout, $template, $row, $position )
    {
    	return str_replace( '%avatar%', get_avatar( $row['user_id'], 32 ), $layout );
    }

    This code goes in your themes functions.php file and introduces a new template tag called %avatar% which will be replaced by the users avatar.

    But that code only works for the leaderboard so to add support for balances, we would be better off registering this new template tag as a user related tag which means that everywhere where User related template tags can be used, this new tag will also be available. To do this, we will need to use the mycred_parse_tags_user filter.

    Example:

    add_filter( 'mycred_parse_tags_user', 'custom_general_template_tag', 10, 3 );
    function custom_general_template_tag( $content, $user, $data ) {
    	// Bail if user no longer exists
    	if ( ! isset( $user->ID ) ) return $content;
    
    	return str_replace( '%avatar%', get_avatar( $user->ID, 32 ), $content );
    }

    Let me know if you require further assistance.

    Thread Starter Guillermo

    (@guillermo-kafelnikov)

    Thank you very much !!!

    Hi,
    I love this plugin – this script however doesn’t seem to work for me after updating to 1.4 – using this on the buddyboss theme and just want to add the users avatar in the leaderboard widget. It was working without a problem prior to updating. Now it just breaks the widget/site – Anyone else experience this?

    Plugin Author myCred

    (@designbymerovingi)

    Hi fanalejr

    Can you be a bit more specific as to how it “breaks” the widget? Have you had a look what CSS styles are applied to the avatar? Does it not render the template tag or the image is not inserted correctly?

    Gabriel, thanks for the response – it actually doesn’t render anything. It renders the title of the leaderboard widget and then stops the output all together. It seems to be an error with the filter –

    add_filter( 'mycred_ranking_row', 'my_custom_ranking_rows', 10, 4 );
    function my_custom_ranking_rows( $layout, $template, $row, $position )
    {
    	return str_replace( '%avatar%', get_avatar( $row['user_id'], 32 ), $layout );
    }

    When I remove that from the functions file it renders fine.

    Plugin Author myCred

    (@designbymerovingi)

    Enable WP_DEBUG and see what errors you get.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘insert avatar widget’ is closed to new replies.