WordPress.org

Ready to get started?Download WordPress

Forums

myCRED
[resolved] insert avatar widget (7 posts)

  1. Guillermo Kafelnikov
    Member
    Posted 5 months ago #

    Hi Gabriel !

    You can insert "an avatar" in "My Balance" widget and "Leaderboard" ?

    if so ... that codes should be inserted into the widget...?

    I apologize if someone has asked this before...

    Thank you very much...

    Bye.

    https://wordpress.org/plugins/mycred/

  2. Gabriel
    Member
    Plugin Author

    Posted 5 months ago #

    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.

  3. Guillermo Kafelnikov
    Member
    Posted 5 months ago #

    Thank you very much !!!

  4. fanalejr
    Member
    Posted 4 months ago #

    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?

  5. Gabriel
    Member
    Plugin Author

    Posted 4 months ago #

    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?

  6. fanalejr
    Member
    Posted 4 months ago #

    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.

  7. Gabriel
    Member
    Plugin Author

    Posted 4 months ago #

    Enable WP_DEBUG and see what errors you get.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.