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

    (@tw2113)

    The BenchPresser

    Could you link me to either one? I’m not sure where to find it personally. Those may be custom implementations for DMA as well.

    Thread Starter elmindo

    (@elmindo)

    You can see it, if you look at the top right corner of the screen in the first frame of the video on the BadgeOS in Action page:
    https://badgeos.org/about/sample-sites/
    And you can see it again about 55 sec into the film.

    To see it on the DMA page, you’d have to sign up and log into your profile.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Ah gotcha.

    The video should do well enough. Without being able to dive deep into any code for it, I’d wager it’s just plucking out the last achievement that a user has earned, from their user meta and displaying information about it using its achievement ID, which is just a post ID.

    Try out the following custom function. It may need some tweaking since it can return individual steps, but this will get you on your way:

    function my_badgeos_get_latest_achievement( $user_id = 0 ) {
    
    	if ( empty( $user_id ) ) {
    		$user_id = get_current_user_id();
    	}
    
    	$achievements = badgeos_get_user_achievements( $user_id );
    
    	if ( !empty( $achievements ) ) {
    		return end( $achievements );
    	}
    
    	return array();
    }

    Usage:

    $latest = my_badgeos_get_latest_achievement();
    
    echo get_the_post_thumbnail( $latest->ID, 'large' );

    All you really need to do is use the function and assign the return value to a variable, and then you’d have a variable that has the following:

    $latest->ID
    $latest->post_type
    $latest->poinsts
    $latest->date_earned

    The ID is the most important part because it’d allow you query for pretty much anything related to the achievement. The post_type is the achievement type its’ related to.

    The function declaration simply checks for a user ID to use, and if none is provided, it’ll just use the current user’s. Then it’ll grab the user’s earned achievements and return either an empty array if there are none, or the latest one earned which will be at the end of the saved value.

    Thread Starter elmindo

    (@elmindo)

    So I’ve tried a bit myself, but unfortunately my skill level is not high enough to achieve this on my own by just this. Could you help me a bit more on the way with a bit more detailed explanation?

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    What do you have so far? so that I can build off from there instead of trying something from scratch.

    Thread Starter elmindo

    (@elmindo)

    I tried adding the code to a function-plugin, as the function.php is updated regularly with the theme.

    Did not work though. Just broke everything, and that’s about as far as I got. ??

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Well, if you still have the file available, lets get it shared and we can move from there, if not, I’ll just start a quick plugin that can be shared and has an example or two for output.

    Thread Starter elmindo

    (@elmindo)

    I think the easiest thing would be to start a new plugin if you wouldn’t mind?

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    What type of quick layout do you want for this? Just the large version of the achievement image and perhaps the achievement name below it?

    Does it need to be for the current user? or the displayed user when browsing user profiles say in BuddyPress?

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Any changes or updates to this one elmindo?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘My Latest Badge’ is closed to new replies.