• Resolved ItzCookie

    (@sawsainis)


    I’ve recently downloaded BadgeOS plugin for WordPress 4.0, but I’ve came into a problem. I’ve searched around your forums and random google or WP posts, but i can’t find the solution.
    The problem is, i can see earned achievements in the user profile ONLY if the user role is admin. The badges can only be earned IF THE ADMIN GIVES A USER ONE, so I made some badges and added couple of user roles and gave them some rewards – but no luck, I still can’t see any achievements as a subscriber or an editor. Maybe someone has any thoughts on this, because I’m completely lost.

    https://www.ads-software.com/plugins/badgeos/

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

    (@tw2113)

    The BenchPresser

    I believe you’re referring to the WP Admin for this. At the moment this is deliberate, but I would definitely agree we should at least display the awards to the user who owns the profile.

    https://github.com/opencredit/badgeos/issues/343

    The User List Widget or some custom querying are going to be your best option right now for displaying on the frontend. You could use the [badgeos_achievements_list] shortcode within template files with do_shortcode() as well, in order to pass in the current user ID.

    Thread Starter ItzCookie

    (@sawsainis)

    Thank you for your reply Michael, I hope you’ll look into this in the further future. For now, I’ll use this workaround, just wanted to make sure that it’s impossible to see the achievements right now in the admin panel. If it’s no trouble for you, could you post a quick custom query to access the badgeos achievement loop?

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not sure which loop you’re referring to. The one for a user’s achievements? Listing all available achievements of an achievement type?

    Thread Starter ItzCookie

    (@sawsainis)

    Yeah, the user achievement loop, to list all the badges that a user has (for example from a specific achievement type). I’ll need that to count the achievements for a specific user.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hoping this at least gets you started on something:

    $achievements = get_user_meta( get_current_user_id(), '_badgeos_achievements', true );
    foreach ( $achievements as $achievement ) {
    	$awarded_ids[] = wp_list_pluck( $achievement, 'ID' );
    	$awarded_post_types[] = wp_list_pluck( $achievement, 'post_type' );
    }
    $ids = array_unique( $awarded_ids[0] );
    $types = array_unique( $awarded_post_types[0] );
    $user_awards = new WP_Query( array( 'post_type' => $types, 'post__in' => $ids ) );

    You’ll need to best determine how to specify the user ID for the first line. The user meta holds an array of arrays that hold the achievement type, name, earned date. and points earned. For my example above, I constructed a basic WP_Query that queries for the unique achievement/post types and only the posts associated with the user.

    Hopefully with this information, you can branch out on your own as necessary.

    Thread Starter ItzCookie

    (@sawsainis)

    Sorry for the late response, but thanks for your loop, I’ve almost got the way i wanted it to work. Thanks for your help! I’ll mark this as solved. Cheers!

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    I had been gone for a couple months, so I did admittedly forget about some of our helper functions, including

    badgeos_get_user_achievements()

    It takes an array for its arguments and those are as follows:

    $defaults = array(
    	'user_id'          => 0,     // The given user's ID
    	'site_id'          => get_current_blog_id(), // The given site's ID
    	'achievement_id'   => false, // A specific achievement's post ID
    	'achievement_type' => false, // A specific achievement type
    	'since'            => 0,     // A specific timestamp to use in place of $limit_in_days
    );

    You’d want to, at least, give the user_id. site_id is more for multisite, the rest are achievement specific by single achievement, type, or earned by date.

    It would allow you to replace parts of the code above, but not all of it.

    Thread Starter ItzCookie

    (@sawsainis)

    Awesome piece of code! I’ll try that out definitely. Stay in touch.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Achievements not showing up in the Users profile (showing only as Admin)’ is closed to new replies.