• On my site, the “user-has-not-earned” class is added to all pages and posts regardless of whether it is a badge post or not. The only posts that do not have this class are badge posts that belong to a badge the user has earned.

    Unfortunately, this causes styling unearned badges difficult as it causes for that styling to be applied to pretty much every page on my site. The theme I am using is probably getting this from the post_class filter that’s added in the content-filters.php file.

    I believe this can be fixed by adding a third value (equaling ”) to be returned if the post ID is not that of a badge so as to prevent this behaviour.

    https://wordpress.org/plugins/badgeos/

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

    (@tw2113)

    The BenchPresser

    I am only seeing 3 places that we set the class. Inside the badgeos_render_achievement() function, inside the post_class filter, and the badgeos_get_required_achievements_for_achievement_list_markup() function.

    I’m curious if the user being tested with has the current achievement ID in their user meta in these cases.

    For what it’s worth when it comes to the styling itself, you just need examples of 1 of each. If you’re looking for accuracy of the represented data, obviously it wouldn’t be.

    Thread Starter Aleksandar Arsovski

    (@alekarsovski)

    From what I understand, the post_class filter is used to add the user-has-not-earned class to the body tag (the outermost HTML element for a post (at least in our theme structure)).

    It’s been quite a while since I’ve written any plugins and done any WordPress dev work, but from what I gathered in the codex and by looking at badgeos_add_earned_class_single function in the content-filters.php file it seems to me that either the user-has-earned or the user-has-not-earned class is passed back regardless of whether or not the post or page itself is an achievement/badge or just a regular post or page. The get_post_class function then adds the user-has-not-earned class to any post or page that is not an achievement because of the ternary operation $classes[] = badgeos_get_user_achievements( array( 'user_id' => $user_ID, 'achievement_id' => get_the_ID() ) ) ? 'user-has-earned' : 'user-has-not-earned'; where it will resolve to user-has-not-earned.

    Does this make any sense or am I misunderstanding the code?

    It does get awkward when the body tags of random posts and pages have this class added as it makes the class difficult to use at all, which is a shame as otherwise it would be very useful.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Odd that the theme chose to use post_class() for that instead of something more appropriate like body_class()

    For the mentioned badgeos_add_earned_class_single() it has the following in it:

    $classes[] = badgeos_get_user_achievements( array( 'user_id' => $user_ID, 'achievement_id' => get_the_ID() ) ) ? 'user-has-earned' : 'user-has-not-earned';

    It is a bit of odd logic because it isn’t wrapped in () to help with the true/false nature of ternary. However, inside the badgeos_get_user_achievements() function itself, it is checking to make sure the get_the_ID() from above is actually an achievement. So that should be helping make sure there’s no false positives here. At the very end, it returns either an array of array values from the found achievements, or an empty array, which would eliminate issues with the post_class array values.

    I’m still left curious if there are ID values in the user’s achievement meta that are matching the single posts you’re viewing, and then there’s also the fact the theme uses post_class() on the body tag.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘user-has-not-earned class added to all pages and posts’ is closed to new replies.