• Resolved kbarnett

    (@kbarnett)


    Hi, I’m trying to change the list of “People who have earned this:” to show user nicknames instead of avatars. I am using BadgeOS Version 1.4.4 and BadgeOS Community Add-On Version 1.2.0.

    I found the badgeos_get_achievement_earners_list function in badgeos/includes/achievement-functions.php and replaced the following on line 642:

    $user_content = '
    <li><a>ID ) . '">' . get_avatar( $user->ID ) . '</a></li>
    ';

    with

    $user_content = '
    <li><a>ID ) . '">' . the_author_meta( 'nickname' , $user->ID ) . '</a></li>
    ';

    However, while that does display the user nickname, it appears above “People who have earned this:”, and user avatars still show up in an unordered list.

    So I also found the function badgeos_bp_achievement_earner in badgeos-community-add-on/includes/bp-members.php and replaced the following:

    $user = new BP_Core_User( $user_id );<br />
    	return '
    <li><a>user_url . '">' . $user->avatar_mini . '</a></li>
    ';

    with

    $user = new BP_Core_User( $user_id );<br />
    	return '
    <li><a>user_url . '">' . the_author_meta( 'nickname' , $user->ID ) . '</a></li>
    ';

    Here’s a link to an example page: https://westmontlibrary.org/inventyoursummer/badge/wild-child/

    I’m close, but I could use some help nailing it down. I hope it’s okay to ask a question like this here. Thank you!

    Edit: I tried putting the code inside backticks, but I think I messed it up somewhere.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    Definitely commend you for opening up the core files to look around and see what’s available, however I highly recommend against editing the core files themselves.

    The better approach here is going to be to use the following filter found in badgeos_get_achievement_earners_list_user function, like you found with the community addon.

    I’d need a login and probably with some achievements awarded to the user to see the actual results that are occurring. However I wager it has CSS affecting it, and that’s where I’d be looking first for this case.

    Thread Starter kbarnett

    (@kbarnett)

    Thanks for your quick response.

    Looking at the page source, the returned nicknames are ending up before the UL with class “badgeos-achievement-earners-list” in the DOM, which is where I would expect they’d land. Yet I clearly am just bumbling around here, so I am not surprised I got it wrong. (I’m completely serious, not sarcastic!)

    I did try to make a custom function and use add_filter in my functions.php file, cross-referencing the BadgeOS Action and Filter Hooks Guide with the core files and the WordPress codex… but it’s just not coming together for me. I think I will probably just omit the list of earners, since I am kind of lost.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Just to be certain, you’re returning and not echo’ing, correct?

    Thread Starter kbarnett

    (@kbarnett)

    Yes, just like the quoted code above. ??

    But I think I figured it out. I added this code to my functions.php:

    function kb_display_earners( $user_content, $user_id ) {
    	$user = new BP_Core_User( $user_id );
    	return '<li><a href="' .  $user->user_url . '">' . bp_core_get_user_displayname( $user_id ) . '</a></li>';
    }
    add_filter( 'badgeos_get_achievement_earners_list_user', 'kb_display_earners', 10, 2 );

    So I’m using bp_core_get_user_displayname( $user_id ) instead of the_author_meta( ‘nickname’ , $user->ID ), which seems to work.

    Thread Starter kbarnett

    (@kbarnett)

    Though it only seems to be showing SOME users…

    Thread Starter kbarnett

    (@kbarnett)

    To be specific, it appears to only show users which I specifically added to the WordPress site from the dashboard as an administrator. It does not list any users who registered through the BuddyPress integrated signup. Oof.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Curious if the BP_Core_User() stuff isn’t always returning results like expected. I’d need to dive in and debug what conditions would cause that, as I don’t know off the top of my head.

    Are you getting empty markup for some and completed markup other times?

    Thread Starter kbarnett

    (@kbarnett)

    I’m getting completed markup for users which I’ve added manually to the WP site (it’s a sub-site of a WP multisite) but nothing for users registered from the sign up page (https://westmontlibrary.org/inventyoursummer/sign-up/) and successfully activated by email.

    Those users registered from the sign up page CAN earn achievements, and their achievements show up on both their Profile page and in the “My Achievements” widget.

    Also, users who are registered on other sites in the network CAN earn achievements, but they also do not show up in the “Users Who Have Earned This” list. I checked, and all the users have a Nickname associated with them.

    Here’s an example page:
    https://westmontlibrary.org/inventyoursummer/badge/wild-child/ The three users listed were manually added to the WP site by me from the dashboard. None of the other users who earned it show up.

    Thank you for your continued help.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Ahhhhh that’s a big clue there. The fact that it’s a network site. Achievements aren’t network-wide, they’re local to the site they were created in, because of the fact that they’re post type based. Each site in the network gets their own posts/postmeta tables.

    We don’t have the best network support because of things like this. We need to find a way to better integrate and collect necessary data for display.

    Thread Starter kbarnett

    (@kbarnett)

    So is it a lost cause then? If there’s any other information I can provide, let me know.

    In case it helps, BadgeOS, BadgeOS Community AddOn, and BuddyPress are all activated on the subblog only, not network activated. (I also set that blog as the BuddyPress site ID per this page on the BP codex. I may also try the “Put profiles in the root” option to see if that helps.)

    Thread Starter kbarnett

    (@kbarnett)

    More info, which may or may not be helpful: I can get all member names for the achievement (users added by me AND self-registered) by running a custom query like thus:

    $testquery = new WP_Query( array (
    	'post_type' => 'submission',
    	'meta_query' => array(
    		array(
    			'key'     => '_badgeos_submission_achievement_id',
    			'value'   => '158',
    			'compare' => '=',
    		),
    	),
    	'posts_per_page' => -1,
    
    ) );

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Well, the biggest issue is that the code needs to gather/query ALL of the information it needs to render everything before moving on to a different site or returning back to the start to finish the output. If there needs to be more queries based on achievements from a specific sub-site, making that query from the wrong sub-site will return empty or inaccurate results.

    We need to audit and look the network-wide settings and make sure it’s doing what we need it to, accurately, and I’m not sure we’re there as much as we may have believed in the past.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Changing "People who have earned this" display’ is closed to new replies.