Exclude users with certain roles form receiving points

front page Forums How-to Questions Exclude users with certain roles form receiving points

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #18742

    I would like to be able to exclude a certain role “Student” from earning points on my site. Or at least exclude them from seeing notifications that they have earned points. Can anyone help?



    You could use the code snippet I provide for excluding “Subscribers” from getting points and adjust it to work with your custom role:

    add_filter( 'mycred_exclude_user', 'mycred_pro_exclude_by_wprole', 10, 3 );
    function mycred_pro_exclude_by_wprole( $excluded, $user_id, $mycred ) {
    	// User is already set to be excluded
    	if ( $excluded === true ) return $excluded;
    	if ( $user_id == 0 || $user_id === NULL )
    		$user = wp_get_current_user();
    		$user = get_userdata( $user_id );
    	// Look for a specific role - replace with your role
    	if ( in_array( 'subscriber', $user->roles ) )
    		return true;
    	return $excluded;

    You will need to paste this into your child theme’s functions.php file and replace subscriber with the ID of the role you want to exclude.


    Thank you!


    I came here to talk about this particular topic. I pasted this code in my child theme but didn’t get the same results. I think since I’m not using the traditional WP roles, that might be the issue. I’m using buddypress member type generator, and buddypress xprofile member type field. The role I don’t want to have access to the point is “fans” How do I make this code work for me?

    Thanks in advance


    @Randlela The above code was built based on WordPress roles. If you want to exclude based on other details then the above code will need to be adjusted to suit your needs. What exactly needs to be changed, depends on what detail you want to exclude based on.

    If you look at the documentation for the mycred_exclude_user filter, you can find an example where we exclude based on a membership as an example. If you feel uncomfortable with PHP, you can always consult one of the freelance developers that list their services here on the website.


    What if i want to exclude users based on roles from receiving just specific point types and not all point types cos i have three point types

    Avatarhtml color

    Thanks for the information your article brings. I see the novelty of your writing, I will share it for everyone to read together. I look forward to reading many articles from you.


    I found a lot of interesting information here. A really good post, very thankful and hopeful that you will write many more posts like this one.
    happy room

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.