• Hi Michael,

    I hope you’re well,
    I’d need your help on this: I need to prevent a custom role on my website from earning badges but I also want those users to be able to visit the badges pages.

    I thought of using the filter user_has_access_to_achievement but I can’t get it to work… can you please help me on this?

    Thank you so much in advance, here is the code I tried:

    add_filter( 'user_has_access_to_achievement', 'restrict_role_from_achievements', 1, 1 );
    function restrict_role_from_achievements() {
    
    	// If role is subscriber_threshold - decline
    	if ( current_user_can ('subscriber_threshold') return false;
    
    	else return true;
    }

    have a great day,
    émilien

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

Viewing 1 replies (of 1 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    That filter should be a good one to utilizes. That leaves the logic inside.

    First thing I notice is that you don’t have any of the filter parameters being passed in at all. I’d at least take in the first 2, the first being the currently calculated boolean true/false from BOS core, the second being the user ID who is being potentially rewarded.

    Second thing would be that it’s perhaps best to use that provided user ID to fetch a user object and grab their roles from that.

    Third, and may not be a contributing factor, but who knows. Perhaps your return statements should be inside brackets instead of on the same line and without. I’m a big fan of {}’s with if statements because it helps for sure deliminate what section other parts are meant to be in.

Viewing 1 replies (of 1 total)
  • The topic ‘restrict to custom role’ is closed to new replies.